summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-12-13 15:35:57 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-12-13 16:37:02 +0100
commit2dde931854b779562777b8946aa619c86fc821db (patch)
tree6060307277a7e4e0dc58f87f6b97c1b19f3bea0e
parent5bef82801ced8f754552110959ad6fcfcf94c7ac (diff)
openpgp: Likewise for MDC.
-rw-r--r--openpgp/src/packet/mdc.rs31
-rw-r--r--openpgp/src/parse/parse.rs12
-rw-r--r--openpgp/src/serialize/mod.rs2
-rw-r--r--openpgp/src/serialize/stream.rs2
-rw-r--r--tool/src/commands/dump.rs8
5 files changed, 27 insertions, 28 deletions
diff --git a/openpgp/src/packet/mdc.rs b/openpgp/src/packet/mdc.rs
index d6628479..9b64190c 100644
--- a/openpgp/src/packet/mdc.rs
+++ b/openpgp/src/packet/mdc.rs
@@ -13,39 +13,39 @@ pub struct MDC {
/// CTB packet header fields.
pub(crate) common: packet::Common,
/// Our SHA-1 hash.
- computed_hash: [u8; 20],
+ computed_digest: [u8; 20],
/// A 20-octet SHA-1 hash of the preceding plaintext data.
- hash: [u8; 20],
+ digest: [u8; 20],
}
impl MDC {
/// Creates an MDC packet.
- pub fn new(hash: [u8; 20], computed_hash: [u8; 20]) -> Self {
+ pub fn new(digest: [u8; 20], computed_digest: [u8; 20]) -> Self {
MDC {
common: Default::default(),
- computed_hash: computed_hash,
- hash: hash,
+ computed_digest,
+ digest,
}
}
/// Gets the packet's hash value.
- pub fn hash(&self) -> &[u8] {
- &self.hash[..]
+ pub fn digest(&self) -> &[u8] {
+ &self.digest[..]
}
/// Gets the computed hash value.
- pub fn computed_hash(&self) -> &[u8] {
- &self.computed_hash[..]
+ pub fn computed_digest(&self) -> &[u8] {
+ &self.computed_digest[..]
}
/// Returns whether the data protected by the MDC is valid.
pub fn valid(&self) -> bool {
- if self.hash == [ 0; 20 ] {
- // If the computed_hash and hash are uninitialized, then
+ if self.digest == [ 0; 20 ] {
+ // If the computed_digest and digest are uninitialized, then
// return false.
false
} else {
- self.computed_hash == self.hash
+ self.computed_digest == self.digest
}
}
}
@@ -57,12 +57,12 @@ impl From<MDC> for Packet {
}
impl From<[u8; 20]> for MDC {
- fn from(hash: [u8; 20]) -> Self {
+ fn from(digest: [u8; 20]) -> Self {
MDC {
common: Default::default(),
// All 0s.
- computed_hash: Default::default(),
- hash: hash,
+ computed_digest: Default::default(),
+ digest,
}
}
}
@@ -74,4 +74,3 @@ impl From<crypto::hash::Context> for MDC {
value.into()
}
}
-
diff --git a/openpgp/src/parse/parse.rs b/openpgp/src/parse/parse.rs
index 202041ba..4319df42 100644
--- a/openpgp/src/parse/parse.rs
+++ b/openpgp/src/parse/parse.rs
@@ -2029,7 +2029,7 @@ impl MDC {
// Nevertheless, we take some basic precautions to check
// whether it is really the matching HashedReader.
- let mut computed_hash : [u8; 20] = Default::default();
+ let mut computed_digest : [u8; 20] = Default::default();
{
let mut r : Option<&mut dyn BufferedReader<Cookie>>
= Some(&mut php.reader);
@@ -2046,7 +2046,7 @@ impl MDC {
} else {
None
}).unwrap();
- h.digest(&mut computed_hash);
+ h.digest(&mut computed_digest);
}
// If the outer most HashedReader is not the
@@ -2060,10 +2060,10 @@ impl MDC {
}
}
- let mut hash : [u8; 20] = Default::default();
- hash.copy_from_slice(&php_try!(php.parse_bytes("hash", 20)));
+ let mut digest: [u8; 20] = Default::default();
+ digest.copy_from_slice(&php_try!(php.parse_bytes("digest", 20)));
- php.ok(Packet::MDC(MDC::new(hash, computed_hash)))
+ php.ok(Packet::MDC(MDC::new(digest, computed_digest)))
}
}
@@ -3943,7 +3943,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_digest(), mdc.digest(),
"MDC doesn't match");
}
diff --git a/openpgp/src/serialize/mod.rs b/openpgp/src/serialize/mod.rs
index 15e95ada..dba3c443 100644
--- a/openpgp/src/serialize/mod.rs
+++ b/openpgp/src/serialize/mod.rs
@@ -1938,7 +1938,7 @@ impl SerializeInto for SEIP {
impl Serialize for MDC {
fn serialize(&self, o: &mut dyn std::io::Write) -> Result<()> {
- o.write_all(self.hash())?;
+ o.write_all(self.digest())?;
Ok(())
}
}
diff --git a/openpgp/src/serialize/stream.rs b/openpgp/src/serialize/stream.rs
index 35b08b1a..389b6d90 100644
--- a/openpgp/src/serialize/stream.rs
+++ b/openpgp/src/serialize/stream.rs
@@ -1599,7 +1599,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.digest(), mdc.computed_digest());
State::Done
} else {
panic!("Unexpected packet: {:?}", pp.packet)
diff --git a/tool/src/commands/dump.rs b/tool/src/commands/dump.rs
index 2b117585..324a34a9 100644
--- a/tool/src/commands/dump.rs
+++ b/tool/src/commands/dump.rs
@@ -648,10 +648,10 @@ impl PacketDumper {
},
MDC(ref m) => {
- writeln!(output, "{} Hash: {}",
- i, hex::encode(m.hash()))?;
- writeln!(output, "{} Computed hash: {}",
- i, hex::encode(m.computed_hash()))?;
+ writeln!(output, "{} Digest: {}",
+ i, hex::encode(m.digest()))?;
+ writeln!(output, "{} Computed digest: {}",
+ i, hex::encode(m.computed_digest()))?;
},
AED(ref a) => {