Skip to content

Commit 62c839c

Browse files
committed
Implement conversion traits
Converting signature to serialized signature and back is natural, so the conversion traits should be implemented.
1 parent dc3eab7 commit 62c839c

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

src/ecdsa/serialized_signature.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
//! serialized signatures and since it's a bit more complicated it has its own module.
99
1010
use core::borrow::Borrow;
11+
use core::convert::TryFrom;
1112
use core::{fmt, ops};
1213

1314
pub use into_iter::IntoIter;
@@ -91,6 +92,28 @@ impl<'a> IntoIterator for &'a SerializedSignature {
9192
fn into_iter(self) -> Self::IntoIter { self.iter() }
9293
}
9394

95+
impl From<Signature> for SerializedSignature {
96+
fn from(value: Signature) -> Self { Self::from_signature(&value) }
97+
}
98+
99+
impl<'a> From<&'a Signature> for SerializedSignature {
100+
fn from(value: &'a Signature) -> Self { Self::from_signature(value) }
101+
}
102+
103+
impl TryFrom<SerializedSignature> for Signature {
104+
type Error = Error;
105+
106+
fn try_from(value: SerializedSignature) -> Result<Self, Self::Error> { value.to_signature() }
107+
}
108+
109+
impl<'a> TryFrom<&'a SerializedSignature> for Signature {
110+
type Error = Error;
111+
112+
fn try_from(value: &'a SerializedSignature) -> Result<Self, Self::Error> {
113+
value.to_signature()
114+
}
115+
}
116+
94117
impl SerializedSignature {
95118
/// Creates `SerializedSignature` from data and length.
96119
///

0 commit comments

Comments
 (0)