radicle-crypto: add Serialize and Deserialize for Signature
Add Serialize and Deserialize for Signature using the the `into` and `try_from` serde attributes. To achieve this `From` and `TryFrom` implementations were added between `Signature` and `String`. Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
parent
dc79130988
commit
3af5a7084d
|
|
@ -63,7 +63,8 @@ where
|
|||
}
|
||||
|
||||
/// Cryptographic signature.
|
||||
#[derive(PartialEq, Eq, Copy, Clone)]
|
||||
#[derive(PartialEq, Eq, Copy, Clone, Serialize, Deserialize)]
|
||||
#[serde(into = "String", try_from = "String")]
|
||||
pub struct Signature(pub ed25519::Signature);
|
||||
|
||||
impl fmt::Display for Signature {
|
||||
|
|
@ -126,6 +127,20 @@ impl TryFrom<&[u8]> for Signature {
|
|||
}
|
||||
}
|
||||
|
||||
impl From<Signature> for String {
|
||||
fn from(s: Signature) -> Self {
|
||||
s.to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<String> for Signature {
|
||||
type Error = SignatureError;
|
||||
|
||||
fn try_from(s: String) -> Result<Self, Self::Error> {
|
||||
Self::from_str(&s)
|
||||
}
|
||||
}
|
||||
|
||||
/// The public/verification key.
|
||||
#[derive(Serialize, Deserialize, Eq, Copy, Clone)]
|
||||
#[serde(into = "String", try_from = "String")]
|
||||
|
|
|
|||
Loading…
Reference in New Issue