Merge rust-bitcoin/rust-secp256k1#361: Add basic derives for Parity

1671dfc2ed Release 0.21.2 (sanket1729)
837be22e09 Basic derives for Parity (sanket1729)
7059192de9 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 https://github.com/rust-bitcoin/rust-bitcoin/pull/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 1671dfc2ed

Tree-SHA512: 263ad027da3da764bd76f719200382c47ba21a976caefc23ebef45d1c4be35ddfc80ce619b57326310aaab22bbf75ca7f1db80b45e95ec076584805efb791f3f
This commit is contained in:
Andrew Poelstra 2022-01-06 22:52:28 +00:00
commit 691173410a
No known key found for this signature in database
GPG Key ID: C588D63CE41B97C1
3 changed files with 36 additions and 2 deletions

View File

@ -1,6 +1,6 @@
[package] [package]
name = "secp256k1" name = "secp256k1"
version = "0.21.1" version = "0.21.2"
authors = [ "Dawid Ciężarkiewicz <dpc@ucore.info>", authors = [ "Dawid Ciężarkiewicz <dpc@ucore.info>",
"Andrew Poelstra <apoelstra@wpsoftware.net>" ] "Andrew Poelstra <apoelstra@wpsoftware.net>" ]
license = "CC0-1.0" license = "CC0-1.0"

View File

@ -910,6 +910,7 @@ impl XOnlyPublicKey {
} }
/// Opaque type used to hold the parity passed between FFI function calls. /// Opaque type used to hold the parity passed between FFI function calls.
#[derive(Copy, Clone, PartialEq, Eq, Debug, PartialOrd, Ord, Hash)]
pub struct Parity(i32); pub struct Parity(i32);
impl From<i32> for Parity { impl From<i32> for Parity {
@ -924,6 +925,39 @@ impl From<Parity> for i32 {
} }
} }
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl ::serde::Serialize for Parity {
fn serialize<S: ::serde::Serializer>(&self, s: S) -> Result<S::Ok, S::Error> {
s.serialize_i32(self.0)
}
}
#[cfg(feature = "serde")]
#[cfg_attr(docsrs, doc(cfg(feature = "serde")))]
impl<'de> ::serde::Deserialize<'de> for Parity {
fn deserialize<D: ::serde::Deserializer<'de>>(d: D) -> Result<Self, D::Error> {
struct I32Visitor;
impl<'de> ::serde::de::Visitor<'de> for I32Visitor
{
type Value = Parity;
fn expecting(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
formatter.write_str("Expecting a 4 byte int i32")
}
fn visit_i32<E>(self, v: i32) -> Result<Self::Value, E>
where E: ::serde::de::Error
{
Ok(Parity::from(v))
}
}
d.deserialize_i32(I32Visitor)
}
}
impl CPtr for XOnlyPublicKey { impl CPtr for XOnlyPublicKey {
type Target = ffi::XOnlyPublicKey; type Target = ffi::XOnlyPublicKey;
fn as_c_ptr(&self) -> *const Self::Target { fn as_c_ptr(&self) -> *const Self::Target {

View File

@ -181,7 +181,7 @@ pub mod schnorr;
#[cfg(feature = "serde")] #[cfg(feature = "serde")]
mod serde_util; mod serde_util;
pub use key::{SecretKey, PublicKey, ONE_KEY, KeyPair, XOnlyPublicKey, Parity}; pub use key::*;
pub use context::*; pub use context::*;
use core::marker::PhantomData; use core::marker::PhantomData;
use core::{mem, fmt, str}; use core::{mem, fmt, str};