Implement conversion traits

Converting signature to serialized signature and back is natural, so the
conversion traits should be implemented.
This commit is contained in:
Martin Habovstiak 2023-10-31 14:32:09 +01:00
parent dc3eab7aaa
commit 62c839c9e0
1 changed files with 23 additions and 0 deletions

View File

@ -8,6 +8,7 @@
//! serialized signatures and since it's a bit more complicated it has its own module. //! serialized signatures and since it's a bit more complicated it has its own module.
use core::borrow::Borrow; use core::borrow::Borrow;
use core::convert::TryFrom;
use core::{fmt, ops}; use core::{fmt, ops};
pub use into_iter::IntoIter; pub use into_iter::IntoIter;
@ -91,6 +92,28 @@ impl<'a> IntoIterator for &'a SerializedSignature {
fn into_iter(self) -> Self::IntoIter { self.iter() } fn into_iter(self) -> Self::IntoIter { self.iter() }
} }
impl From<Signature> 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<SerializedSignature> for Signature {
type Error = Error;
fn try_from(value: SerializedSignature) -> Result<Self, Self::Error> { value.to_signature() }
}
impl<'a> TryFrom<&'a SerializedSignature> for Signature {
type Error = Error;
fn try_from(value: &'a SerializedSignature) -> Result<Self, Self::Error> {
value.to_signature()
}
}
impl SerializedSignature { impl SerializedSignature {
/// Creates `SerializedSignature` from data and length. /// Creates `SerializedSignature` from data and length.
/// ///