minisign/
signature_bones.rs1use crate::constants::*;
2use crate::errors::*;
3use crate::signature::*;
4use crate::signature_box::*;
5
6#[derive(Clone)]
9pub struct SignatureBones {
10 pub(crate) signature: Signature,
11 pub(crate) is_prehashed: bool,
12}
13
14impl SignatureBones {
15 pub const BYTES: usize = Signature::BYTES;
17
18 pub fn is_prehashed(&self) -> bool {
20 self.is_prehashed
21 }
22
23 pub fn from_bytes(bytes: &[u8]) -> Result<SignatureBones> {
25 let signature = Signature::from_bytes(bytes)?;
26 let is_prehashed = match signature.sig_alg {
27 SIGALG => false,
28 SIGALG_PREHASHED => true,
29 _ => {
30 return Err(PError::new(
31 ErrorKind::Verify,
32 "Unsupported signature algorithm".to_string(),
33 ))
34 }
35 };
36 Ok(SignatureBones {
37 signature,
38 is_prehashed,
39 })
40 }
41
42 pub fn to_bytes(&self) -> Vec<u8> {
44 self.signature.to_bytes()
45 }
46}
47
48impl From<SignatureBones> for SignatureBox {
49 fn from(signature: SignatureBones) -> SignatureBox {
50 let is_prehashed = signature.is_prehashed();
51 SignatureBox {
52 untrusted_comment: String::new(),
53 signature: signature.signature,
54 sig_and_trusted_comment: None,
55 global_sig: None,
56 is_prehashed,
57 }
58 }
59}
60
61impl From<SignatureBox> for SignatureBones {
62 fn from(signature: SignatureBox) -> SignatureBones {
63 let is_prehashed = signature.is_prehashed();
64 SignatureBones {
65 signature: signature.signature,
66 is_prehashed,
67 }
68 }
69}