Skip to content

Commit

Permalink
Implement conversion traits
Browse files Browse the repository at this point in the history
Converting signature to serialized signature and back is natural, so the
conversion traits should be implemented.
  • Loading branch information
Kixunil committed Oct 31, 2023
1 parent dc3eab7 commit 62c839c
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions src/ecdsa/serialized_signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//! 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;
Expand Down Expand Up @@ -91,6 +92,28 @@ impl<'a> IntoIterator for &'a SerializedSignature {
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 {
/// Creates `SerializedSignature` from data and length.
///
Expand Down

0 comments on commit 62c839c

Please sign in to comment.