diff --git a/src/ecdsa/serialized_signature.rs b/src/ecdsa/serialized_signature.rs index 1b2a65a..bfd035f 100644 --- a/src/ecdsa/serialized_signature.rs +++ b/src/ecdsa/serialized_signature.rs @@ -7,6 +7,8 @@ //! unable to run on platforms without allocator. We implement a special type to encapsulate //! serialized signatures and since it's a bit more complicated it has its own module. +use core::borrow::Borrow; +use core::convert::TryFrom; use core::{fmt, ops}; pub use into_iter::IntoIter; @@ -41,11 +43,30 @@ impl PartialEq for SerializedSignature { fn eq(&self, other: &SerializedSignature) -> bool { **self == **other } } +impl PartialEq<[u8]> for SerializedSignature { + #[inline] + fn eq(&self, other: &[u8]) -> bool { **self == *other } +} + +impl PartialEq for [u8] { + #[inline] + fn eq(&self, other: &SerializedSignature) -> bool { *self == **other } +} + +impl core::hash::Hash for SerializedSignature { + fn hash(&self, state: &mut H) { (**self).hash(state) } +} + impl AsRef<[u8]> for SerializedSignature { #[inline] fn as_ref(&self) -> &[u8] { self } } +impl Borrow<[u8]> for SerializedSignature { + #[inline] + fn borrow(&self) -> &[u8] { self } +} + impl ops::Deref for SerializedSignature { type Target = [u8]; @@ -71,6 +92,28 @@ impl<'a> IntoIterator for &'a SerializedSignature { fn into_iter(self) -> Self::IntoIter { self.iter() } } +impl From for SerializedSignature { + fn from(value: Signature) -> Self { Self::from_signature(&value) } +} + +impl<'a> From<&'a Signature> for SerializedSignature { + fn from(value: &'a Signature) -> Self { Self::from_signature(value) } +} + +impl TryFrom for Signature { + type Error = Error; + + fn try_from(value: SerializedSignature) -> Result { value.to_signature() } +} + +impl<'a> TryFrom<&'a SerializedSignature> for Signature { + type Error = Error; + + fn try_from(value: &'a SerializedSignature) -> Result { + value.to_signature() + } +} + impl SerializedSignature { /// Creates `SerializedSignature` from data and length. /// @@ -84,6 +127,7 @@ impl SerializedSignature { } /// Get the capacity of the underlying data buffer. + #[deprecated = "This always returns 72"] #[inline] pub fn capacity(&self) -> usize { self.data.len() } @@ -106,6 +150,7 @@ impl SerializedSignature { pub fn from_signature(sig: &Signature) -> SerializedSignature { sig.serialize_der() } /// Check if the space is zero. + #[deprecated = "This always returns false"] #[inline] pub fn is_empty(&self) -> bool { self.len() == 0 } }