Skip to content

Commit 6911734

Browse files
committed
Merge #361: Add basic derives for Parity
1671dfc Release 0.21.2 (sanket1729) 837be22 Basic derives for Parity (sanket1729) 7059192 Wildcard export from key module (sanket1729) Pull request description: Sorry for getting another point release. This time I have tested against this branch for rust-bitcoin rust-bitcoin/rust-bitcoin#755. Hopefully, this is the last release. Next release, we should have a Release Candidate for a couple of days before publishing a release. ACKs for top commit: apoelstra: ACK 1671dfc Tree-SHA512: 263ad027da3da764bd76f719200382c47ba21a976caefc23ebef45d1c4be35ddfc80ce619b57326310aaab22bbf75ca7f1db80b45e95ec076584805efb791f3f
2 parents 74e8fc7 + 1671dfc commit 6911734

File tree

3 files changed

+36
-2
lines changed

3 files changed

+36
-2
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "secp256k1"
3-
version = "0.21.1"
3+
version = "0.21.2"
44
authors = [ "Dawid Ciężarkiewicz <[email protected]>",
55
"Andrew Poelstra <[email protected]>" ]
66
license = "CC0-1.0"

src/key.rs

+34
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,7 @@ impl XOnlyPublicKey {
910910
}
911911

912912
/// Opaque type used to hold the parity passed between FFI function calls.
913+
#[derive(Copy, Clone, PartialEq, Eq, Debug, PartialOrd, Ord, Hash)]
913914
pub struct Parity(i32);
914915

915916
impl From<i32> for Parity {
@@ -924,6 +925,39 @@ impl From<Parity> for i32 {
924925
}
925926
}
926927

928+
#[cfg(feature = "serde")]
929+
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
930+
impl ::serde::Serialize for Parity {
931+
fn serialize<S: ::serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
932+
s.serialize_i32(self.0)
933+
}
934+
}
935+
936+
#[cfg(feature = "serde")]
937+
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
938+
impl<'de> ::serde::Deserialize<'de> for Parity {
939+
fn deserialize<D: ::serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
940+
struct I32Visitor;
941+
942+
impl<'de> ::serde::de::Visitor<'de> for I32Visitor
943+
{
944+
type Value = Parity;
945+
946+
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
947+
formatter.write_str("Expecting a 4 byte int i32")
948+
}
949+
950+
fn visit_i32<E>(self, v: i32) -> Result<Self::Value, E>
951+
where E: ::serde::de::Error
952+
{
953+
Ok(Parity::from(v))
954+
}
955+
}
956+
957+
d.deserialize_i32(I32Visitor)
958+
}
959+
}
960+
927961
impl CPtr for XOnlyPublicKey {
928962
type Target = ffi::XOnlyPublicKey;
929963
fn as_c_ptr(&self) -> *const Self::Target {

src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ pub mod schnorr;
181181
#[cfg(feature = "serde")]
182182
mod serde_util;
183183

184-
pub use key::{SecretKey, PublicKey, ONE_KEY, KeyPair, XOnlyPublicKey, Parity};
184+
pub use key::*;
185185
pub use context::*;
186186
use core::marker::PhantomData;
187187
use core::{mem, fmt, str};

0 commit comments

Comments
 (0)