diff options
author | Justus Winter <justus@sequoia-pgp.org> | 2018-12-13 13:04:22 +0100 |
---|---|---|
committer | Justus Winter <justus@sequoia-pgp.org> | 2018-12-13 13:21:58 +0100 |
commit | 75d96baaffeb4c563c7bd234a8a94a83b0940a74 (patch) | |
tree | bee2c0555d2fa3d074eecf87a20ca87eb8a5a007 /openpgp | |
parent | 5fff08455fdbdcab1dac39456304cc7183059c8d (diff) |
openpgp: Make fields of MDC private.
Diffstat (limited to 'openpgp')
-rw-r--r-- | openpgp/src/packet/mdc.rs | 13 | ||||
-rw-r--r-- | openpgp/src/parse/parse.rs | 8 | ||||
-rw-r--r-- | openpgp/src/serialize/mod.rs | 2 | ||||
-rw-r--r-- | openpgp/src/serialize/stream.rs | 2 |
4 files changed, 15 insertions, 10 deletions
diff --git a/openpgp/src/packet/mdc.rs b/openpgp/src/packet/mdc.rs index 426e9cbf..0a217639 100644 --- a/openpgp/src/packet/mdc.rs +++ b/openpgp/src/packet/mdc.rs @@ -13,12 +13,21 @@ pub struct MDC { /// CTB packet header fields. pub(crate) common: packet::Common, /// Our SHA-1 hash. - pub(crate) computed_hash: [u8; 20], + computed_hash: [u8; 20], /// A 20-octet SHA-1 hash of the preceding plaintext data. - pub(crate) hash: [u8; 20], + hash: [u8; 20], } impl MDC { + /// Creates an MDC packet. + pub(crate) fn new_(hash: [u8; 20], computed_hash: [u8; 20]) -> Self { + MDC { + common: Default::default(), + computed_hash: computed_hash, + hash: hash, + } + } + /// Creates a new MDC packet for the data hashed into `hash` Hash context. pub fn new(hash: &mut nettle::Hash) -> Self { let mut value : [u8; 20] = Default::default(); diff --git a/openpgp/src/parse/parse.rs b/openpgp/src/parse/parse.rs index 369bab0e..0a2d7c3a 100644 --- a/openpgp/src/parse/parse.rs +++ b/openpgp/src/parse/parse.rs @@ -1861,11 +1861,7 @@ impl MDC { let mut hash : [u8; 20] = Default::default(); hash.copy_from_slice(&php_try!(php.parse_bytes("hash", 20))); - php.ok(Packet::MDC(MDC { - common: Default::default(), - computed_hash: computed_hash, - hash: hash, - })) + php.ok(Packet::MDC(MDC::new_(hash, computed_hash))) } } @@ -3626,7 +3622,7 @@ mod test { if let PacketParserResult::Some( PacketParser { packet: Packet::MDC(ref mdc), .. }) = ppr { - assert_eq!(mdc.computed_hash, mdc.hash, + assert_eq!(mdc.computed_hash(), mdc.hash(), "MDC doesn't match"); } diff --git a/openpgp/src/serialize/mod.rs b/openpgp/src/serialize/mod.rs index 3f13461d..c0fc665e 100644 --- a/openpgp/src/serialize/mod.rs +++ b/openpgp/src/serialize/mod.rs @@ -1158,7 +1158,7 @@ impl Serialize for MDC { fn serialize<W: io::Write>(&self, o: &mut W) -> Result<()> { CTB::new(Tag::MDC).serialize(o)?; BodyLength::Full(20).serialize(o)?; - o.write_all(&self.hash[..])?; + o.write_all(self.hash())?; Ok(()) } } diff --git a/openpgp/src/serialize/stream.rs b/openpgp/src/serialize/stream.rs index 58def727..3acb34fd 100644 --- a/openpgp/src/serialize/stream.rs +++ b/openpgp/src/serialize/stream.rs @@ -1450,7 +1450,7 @@ mod test { // Look for the MDC packet. State::MDC => if let Packet::MDC(ref mdc) = pp.packet { - assert_eq!(mdc.hash, mdc.computed_hash); + assert_eq!(mdc.hash(), mdc.computed_hash()); State::Done } else { panic!("Unexpected packet: {:?}", pp.packet) |