Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle-crypto: add Serialize and Deserialize for Signature
Fintan Halpenny committed 3 years ago
commit 3af5a7084da77cf5b6559b0594b14680460500fc
parent dc791309887629e9e3fee74ecbd7b99375002889
1 file changed +16 -1
modified radicle-crypto/src/lib.rs
@@ -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")]