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<ExtendedSignature> for (PublicKey, Signature)` Signed-off-by: Fintan Halpenny <fintan.halpenny@gmail.com> X-Clacks-Overhead: GNU Terry Pratchett
This commit is contained in:
parent
3af5a7084d
commit
58c26e1c9d
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in New Issue