Radish alpha
h
Radicle Heartwood Protocol & Stack
Radicle
Git (anonymous pull)
Log in to clone via SSH
radicle-crypto: ExtendedSignature constructor and destructor
Fintan Halpenny committed 3 years ago
commit 58c26e1c9d2f69bb0176e3a008829c88ed52cf87
parent 3af5a7084da77cf5b6559b0594b14680460500fc
1 file changed +17 -0
modified radicle-crypto/src/ssh.rs
@@ -227,6 +227,12 @@ pub struct ExtendedSignature {
    signature: crypto::Signature,
}

+
impl From<ExtendedSignature> for (crypto::PublicKey, crypto::Signature) {
+
    fn from(ex: ExtendedSignature) -> Self {
+
        (ex.public_key, ex.signature)
+
    }
+
}
+

impl Encodable for ExtendedSignature {
    type Error = ExtendedSignatureError;

@@ -263,6 +269,17 @@ impl ExtendedSignature {
    const ARMORED_WIDTH: usize = 70;
    const MAGIC_PREAMBLE: &[u8] = b"SSHSIG";

+
    pub fn new(public_key: crypto::PublicKey, signature: crypto::Signature) -> Self {
+
        Self {
+
            version: 1,
+
            public_key,
+
            namespace: b"radicle".to_vec(),
+
            reserved: b"".to_vec(),
+
            hash_algorithm: b"sha256".to_vec(),
+
            signature,
+
        }
+
    }
+

    pub fn from_armored(s: &[u8]) -> Result<Self, ExtendedSignatureError> {
        let s = s
            .strip_prefix(Self::ARMORED_HEADER)