diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2018-09-06 15:29:51 +0200 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2018-09-06 15:35:23 +0200 |
commit | 5c7298150ca3d3c51c3cec030d24d5cc69d8342f (patch) | |
tree | 4114628b5c86d8af98aa96d0d28fb2a72cc90e9d | |
parent | c87464a6f560028791b75d80034067daabc3e961 (diff) |
openpgp: Make Signature's MPIs mandatory.
- Capitalize on the fact that all Signatures now have MPIs.
-rw-r--r-- | openpgp/src/parse/parse.rs | 4 | ||||
-rw-r--r-- | openpgp/src/serialize/mod.rs | 6 | ||||
-rw-r--r-- | openpgp/src/signature.rs | 24 |
3 files changed, 16 insertions, 18 deletions
diff --git a/openpgp/src/parse/parse.rs b/openpgp/src/parse/parse.rs index d3127847..e3166a01 100644 --- a/openpgp/src/parse/parse.rs +++ b/openpgp/src/parse/parse.rs @@ -883,7 +883,7 @@ impl Signature { unhashed_area: SubpacketArea::new(unhashed_area), }, hash_prefix: [hash_prefix1, hash_prefix2], - mpis: Some(mpis), + mpis: mpis, computed_hash: None, }))?; @@ -1011,7 +1011,7 @@ fn signature_parser_test () { assert_eq!(p.hashed_area().data.len(), 29); assert_eq!(p.unhashed_area().data.len(), 10); assert_eq!(p.hash_prefix(), &[0x65u8, 0x74]); - assert_eq!(p.mpis().unwrap().serialized_len(), 258); + assert_eq!(p.mpis().serialized_len(), 258); } else { panic!("Wrong packet!"); } diff --git a/openpgp/src/serialize/mod.rs b/openpgp/src/serialize/mod.rs index e62c2115..ca434749 100644 --- a/openpgp/src/serialize/mod.rs +++ b/openpgp/src/serialize/mod.rs @@ -600,7 +600,7 @@ impl Serialize for Signature { + 2 // unhashed area size + self.unhashed_area().data.len() + 2 // hash prefix - + self.mpis.as_ref().map(|sig| sig.serialized_len()).unwrap_or(0); + + self.mpis().serialized_len(); CTB::new(Tag::Signature).serialize(o)?; BodyLength::Full(len as u32).serialize(o)?; @@ -652,9 +652,7 @@ impl Signature { write_byte(o, self.hash_prefix()[0])?; write_byte(o, self.hash_prefix()[1])?; - if let Some(sig) = self.mpis() { - sig.serialize(o)?; - } + self.mpis.serialize(o)?; Ok(()) } diff --git a/openpgp/src/signature.rs b/openpgp/src/signature.rs index 4eda5206..a68eacfe 100644 --- a/openpgp/src/signature.rs +++ b/openpgp/src/signature.rs @@ -199,7 +199,7 @@ impl SignatureBuilder { common: Default::default(), fields: self, hash_prefix: [digest[0], digest[1]], - mpis: Some(mpis), + mpis: mpis, computed_hash: None, }) } @@ -230,8 +230,8 @@ pub struct Signature { /// Lower 16 bits of the signed hash value. pub(crate) hash_prefix: [u8; 2], - /// Signature MPIs. Must be a *Signature variant. - pub(crate) mpis: Option<mpis::Signature>, + /// Signature MPIs. + pub(crate) mpis: mpis::Signature, /// When used in conjunction with a one-pass signature, this is the /// hash computed over the enclosed message. @@ -335,13 +335,13 @@ impl Signature { } /// Gets the signature packet's MPIs. - pub fn mpis(&self) -> Option<&mpis::Signature> { - self.mpis.as_ref() + pub fn mpis(&self) -> &mpis::Signature { + &self.mpis } /// Sets the signature packet's MPIs. pub fn set_mpis(&mut self, mpis: mpis::Signature) { - self.mpis = Some(mpis); + self.mpis = mpis; } /// Gets the computed hash value. @@ -377,13 +377,13 @@ impl Signature { use mpis::PublicKey; #[allow(deprecated)] - match (self.pk_algo(), key.mpis(), self.mpis.as_ref()) { + match (self.pk_algo(), key.mpis(), self.mpis()) { (RSASign, &PublicKey::RSA{ ref e, ref n }, - Some(&mpis::Signature::RSA { ref s })) | + &mpis::Signature::RSA { ref s }) | (RSAEncryptSign, &PublicKey::RSA{ ref e, ref n }, - Some(&mpis::Signature::RSA { ref s })) => { + &mpis::Signature::RSA { ref s }) => { let key = rsa::PublicKey::new(&n.value, &e.value)?; // As described in [Section 5.2.2 and 5.2.3 of RFC 4880], @@ -397,7 +397,7 @@ impl Signature { (DSA, &PublicKey::DSA{ ref y, ref p, ref q, ref g }, - Some(&mpis::Signature::DSA { ref s, ref r })) => { + &mpis::Signature::DSA { ref s, ref r }) => { let key = dsa::PublicKey::new(&y.value); let params = dsa::Params::new(&p.value, &q.value, &g.value); let signature = dsa::Signature::new(&r.value, &s.value); @@ -407,7 +407,7 @@ impl Signature { (EdDSA, &PublicKey::EdDSA{ ref curve, ref q }, - Some(&mpis::Signature::EdDSA { ref r, ref s })) => match curve { + &mpis::Signature::EdDSA { ref r, ref s }) => match curve { Curve::Ed25519 => { if q.value[0] != 0x40 { return Err(Error::MalformedPacket( @@ -449,7 +449,7 @@ impl Signature { (ECDSA, &PublicKey::ECDSA{ ref curve, ref q }, - Some(&mpis::Signature::ECDSA { ref s, ref r })) => { + &mpis::Signature::ECDSA { ref s, ref r }) => { let (x, y) = q.decode_point(curve)?; let key = match curve { Curve::NistP256 => |