From 58c26e1c9d2f69bb0176e3a008829c88ed52cf87 Mon Sep 17 00:00:00 2001 From: Fintan Halpenny Date: Wed, 2 Nov 2022 14:29:37 +0000 Subject: [PATCH] radicle-crypto: ExtendedSignature constructor and destructor Add `ExtendedSignature::new` to construct an `ExtendedSignature` provided a public key and signature. The `namespace` chosen was "radicle" and `reserved` is set to be empty -- these choices were slightly arbitrary. Also add a desctructor in the form of: `From for (PublicKey, Signature)` Signed-off-by: Fintan Halpenny X-Clacks-Overhead: GNU Terry Pratchett --- radicle-crypto/src/ssh.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/radicle-crypto/src/ssh.rs b/radicle-crypto/src/ssh.rs index d0d8c778..b051bf3b 100644 --- a/radicle-crypto/src/ssh.rs +++ b/radicle-crypto/src/ssh.rs @@ -227,6 +227,12 @@ pub struct ExtendedSignature { signature: crypto::Signature, } +impl From 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 { let s = s .strip_prefix(Self::ARMORED_HEADER)