summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-12-13 16:09:26 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-12-13 16:37:02 +0100
commit4f9b5460dbc66716823d4a0e9f94ad1e23ccf20a (patch)
treed3abe8ccc9762bba0e4644ad8da885976faf4a32
parent2dde931854b779562777b8946aa619c86fc821db (diff)
openpgp: Rename the hash prefix to digest prefix.
-rw-r--r--openpgp/src/cert/mod.rs36
-rw-r--r--openpgp/src/crypto/hash.rs14
-rw-r--r--openpgp/src/packet/signature/mod.rs20
-rw-r--r--openpgp/src/parse/parse.rs26
-rw-r--r--openpgp/src/serialize/mod.rs4
-rw-r--r--tool/src/commands/dump.rs4
6 files changed, 52 insertions, 52 deletions
diff --git a/openpgp/src/cert/mod.rs b/openpgp/src/cert/mod.rs
index c2893e54..d4c458ab 100644
--- a/openpgp/src/cert/mod.rs
+++ b/openpgp/src/cert/mod.rs
@@ -1312,7 +1312,7 @@ impl Cert {
$binding.$sigs.push(sig);
} else {
t!("Sig {:02X}{:02X}, type = {} doesn't belong to {}",
- sig.hash_prefix()[0], sig.hash_prefix()[1],
+ sig.digest_prefix()[0], sig.digest_prefix()[1],
sig.typ(), $desc);
self.bad.push(sig);
@@ -1347,7 +1347,7 @@ impl Cert {
// Use hash prefix as heuristic.
if let Ok(hash) = Signature::$hash_method(
&sig, self.primary.key(), $($verify_args),*) {
- if &sig.hash_prefix()[..] == &hash[..2] {
+ if &sig.digest_prefix()[..] == &hash[..2] {
// See if we can get the key for a
// positive verification.
if let Some(key) = $lookup_fn(&sig) {
@@ -1358,8 +1358,8 @@ impl Cert {
} else {
t!("Sig {:02X}{:02X}, type = {} \
doesn't belong to {}",
- sig.hash_prefix()[0],
- sig.hash_prefix()[1],
+ sig.digest_prefix()[0],
+ sig.digest_prefix()[1],
sig.typ(), $desc);
self.bad.push(sig);
@@ -1371,7 +1371,7 @@ impl Cert {
} else {
t!("Sig {:02X}{:02X}, type = {} \
doesn't belong to {}",
- sig.hash_prefix()[0], sig.hash_prefix()[1],
+ sig.digest_prefix()[0], sig.digest_prefix()[1],
sig.typ(), $desc);
self.bad.push(sig);
@@ -1381,7 +1381,7 @@ impl Cert {
// the hash algorithm.
t!("Sig {:02X}{:02X}, type = {}: \
Hashing failed",
- sig.hash_prefix()[0], sig.hash_prefix()[1],
+ sig.digest_prefix()[0], sig.digest_prefix()[1],
sig.typ());
self.bad.push(sig);
@@ -1490,8 +1490,8 @@ impl Cert {
{
t!("Sig {:02X}{:02X}, {:?} \
was out of place. Belongs to {}.",
- $sig.hash_prefix()[0],
- $sig.hash_prefix()[1],
+ $sig.digest_prefix()[0],
+ $sig.digest_prefix()[1],
$sig.typ(), $desc);
$sigs.push($sig);
@@ -1527,8 +1527,8 @@ impl Cert {
{
t!("Sig {:02X}{:02X}, {:?} \
was out of place. Belongs to {}.",
- $sig.hash_prefix()[0],
- $sig.hash_prefix()[1],
+ $sig.digest_prefix()[0],
+ $sig.digest_prefix()[1],
$sig.typ(), $desc);
$sigs.push($sig);
@@ -1538,11 +1538,11 @@ impl Cert {
// Use hash prefix as heuristic.
if let Ok(hash) = Signature::$hash_method(
&sig, self.primary.key(), $($verify_args),*) {
- if &sig.hash_prefix()[..] == &hash[..2] {
+ if &sig.digest_prefix()[..] == &hash[..2] {
t!("Sig {:02X}{:02X}, {:?} \
was out of place. Likely belongs to {}.",
- $sig.hash_prefix()[0],
- $sig.hash_prefix()[1],
+ $sig.digest_prefix()[0],
+ $sig.digest_prefix()[1],
$sig.typ(), $desc);
$sigs.push($sig);
@@ -1638,7 +1638,7 @@ impl Cert {
// Keep them for later.
t!("Self-sig {:02X}{:02X}, {:?} doesn't belong \
to any known component or is bad.",
- sig.hash_prefix()[0], sig.hash_prefix()[1],
+ sig.digest_prefix()[0], sig.digest_prefix()[1],
sig.typ());
self.bad.push(sig);
}
@@ -1898,7 +1898,7 @@ mod test {
assert_eq!(cert.userids[0].userid().value(),
&b"Testy McTestface <testy@example.org>"[..]);
assert_eq!(cert.userids[0].self_signatures.len(), 1);
- assert_eq!(cert.userids[0].self_signatures[0].hash_prefix(),
+ assert_eq!(cert.userids[0].self_signatures[0].digest_prefix(),
&[ 0xc6, 0x8f ]);
assert_eq!(cert.user_attributes.len(), 0);
assert_eq!(cert.subkeys.len(), 0);
@@ -1920,7 +1920,7 @@ mod test {
assert_eq!(cert.userids[0].userid().value(),
&b"Testy McTestface <testy@example.org>"[..]);
assert_eq!(cert.userids[0].self_signatures.len(), 1);
- assert_eq!(cert.userids[0].self_signatures[0].hash_prefix(),
+ assert_eq!(cert.userids[0].self_signatures[0].digest_prefix(),
&[ 0xc6, 0x8f ]);
assert_eq!(cert.user_attributes.len(), 0);
@@ -1928,7 +1928,7 @@ mod test {
assert_eq!(cert.subkeys.len(), 1, "number of subkeys");
assert_eq!(cert.subkeys[0].key().creation_time(),
Timestamp::from(1511355130).into());
- assert_eq!(cert.subkeys[0].self_signatures[0].hash_prefix(),
+ assert_eq!(cert.subkeys[0].self_signatures[0].digest_prefix(),
&[ 0xb7, 0xb9 ]);
let cert = parse_cert(crate::tests::key("testy-no-subkey.pgp"),
@@ -1944,7 +1944,7 @@ mod test {
assert_eq!(cert.userids[0].userid().value(),
&b"Testy McTestface <testy@example.org>"[..]);
assert_eq!(cert.userids[0].self_signatures.len(), 1);
- assert_eq!(cert.userids[0].self_signatures[0].hash_prefix(),
+ assert_eq!(cert.userids[0].self_signatures[0].digest_prefix(),
&[ 0xc6, 0x8f ]);
assert_eq!(cert.subkeys.len(), 0, "number of subkeys");
diff --git a/openpgp/src/crypto/hash.rs b/openpgp/src/crypto/hash.rs
index 05911bae..d1a12236 100644
--- a/openpgp/src/crypto/hash.rs
+++ b/openpgp/src/crypto/hash.rs
@@ -471,12 +471,12 @@ mod test {
selfsig,
cert.primary(),
binding.userid()).unwrap();
- if &h[..2] != selfsig.hash_prefix() {
+ if &h[..2] != selfsig.digest_prefix() {
eprintln!("{:?}: {:?} / {:?}",
i, binding.userid(), selfsig);
eprintln!(" Hash: {:?}", h);
}
- assert_eq!(&h[..2], selfsig.hash_prefix());
+ assert_eq!(&h[..2], selfsig.digest_prefix());
userid_sigs += 1;
}
}
@@ -487,12 +487,12 @@ mod test {
selfsig,
cert.primary(),
binding.user_attribute()).unwrap();
- if &h[..2] != selfsig.hash_prefix() {
+ if &h[..2] != selfsig.digest_prefix() {
eprintln!("{:?}: {:?} / {:?}",
i, binding.user_attribute(), selfsig);
eprintln!(" Hash: {:?}", h);
}
- assert_eq!(&h[..2], selfsig.hash_prefix());
+ assert_eq!(&h[..2], selfsig.digest_prefix());
ua_sigs += 1;
}
}
@@ -503,12 +503,12 @@ mod test {
selfsig,
cert.primary(),
binding.key()).unwrap();
- if &h[..2] != selfsig.hash_prefix() {
+ if &h[..2] != selfsig.digest_prefix() {
eprintln!("{:?}: {:?}", i, binding);
eprintln!(" Hash: {:?}", h);
}
- assert_eq!(h[0], selfsig.hash_prefix()[0]);
- assert_eq!(h[1], selfsig.hash_prefix()[1]);
+ assert_eq!(h[0], selfsig.digest_prefix()[0]);
+ assert_eq!(h[1], selfsig.digest_prefix()[1]);
subkey_sigs += 1;
}
}
diff --git a/openpgp/src/packet/signature/mod.rs b/openpgp/src/packet/signature/mod.rs
index 546ab349..184caf53 100644
--- a/openpgp/src/packet/signature/mod.rs
+++ b/openpgp/src/packet/signature/mod.rs
@@ -273,7 +273,7 @@ impl Builder {
Ok(Signature4 {
common: Default::default(),
fields: self,
- hash_prefix: [digest[0], digest[1]],
+ digest_prefix: [digest[0], digest[1]],
mpis: mpis,
computed_digest: Some(digest),
level: 0,
@@ -328,7 +328,7 @@ pub struct Signature4 {
pub(crate) fields: Builder,
/// Lower 16 bits of the signed hash value.
- hash_prefix: [u8; 2],
+ digest_prefix: [u8; 2],
/// Signature MPIs.
mpis: mpis::Signature,
@@ -364,8 +364,8 @@ impl fmt::Debug for Signature4 {
.field("hash_algo", &self.hash_algo())
.field("hashed_area", self.hashed_area())
.field("unhashed_area", self.unhashed_area())
- .field("hash_prefix",
- &crate::fmt::to_hex(&self.hash_prefix, false))
+ .field("digest_prefix",
+ &crate::fmt::to_hex(&self.digest_prefix, false))
.field("computed_digest",
&if let Some(ref hash) = self.computed_digest {
Some(crate::fmt::to_hex(&hash[..], false))
@@ -422,7 +422,7 @@ impl Signature4 {
pub fn new(typ: SignatureType, pk_algo: PublicKeyAlgorithm,
hash_algo: HashAlgorithm, hashed_area: SubpacketArea,
unhashed_area: SubpacketArea,
- hash_prefix: [u8; 2],
+ digest_prefix: [u8; 2],
mpis: mpis::Signature) -> Self {
Signature4 {
common: Default::default(),
@@ -433,7 +433,7 @@ impl Signature4 {
hash_algo: hash_algo,
subpackets: SubpacketAreas::new(hashed_area, unhashed_area),
},
- hash_prefix: hash_prefix,
+ digest_prefix: digest_prefix,
mpis: mpis,
computed_digest: None,
level: 0,
@@ -441,13 +441,13 @@ impl Signature4 {
}
/// Gets the hash prefix.
- pub fn hash_prefix(&self) -> &[u8; 2] {
- &self.hash_prefix
+ pub fn digest_prefix(&self) -> &[u8; 2] {
+ &self.digest_prefix
}
/// Sets the hash prefix.
- pub fn set_hash_prefix(&mut self, prefix: [u8; 2]) -> [u8; 2] {
- ::std::mem::replace(&mut self.hash_prefix, prefix)
+ pub fn set_digest_prefix(&mut self, prefix: [u8; 2]) -> [u8; 2] {
+ ::std::mem::replace(&mut self.digest_prefix, prefix)
}
/// Gets the signature packet's MPIs.
diff --git a/openpgp/src/parse/parse.rs b/openpgp/src/parse/parse.rs
index 4319df42..4ad58c9c 100644
--- a/openpgp/src/parse/parse.rs
+++ b/openpgp/src/parse/parse.rs
@@ -1008,8 +1008,8 @@ impl Signature4 {
let unhashed_area
= php_try!(php.parse_bytes("unhashed_area",
unhashed_area_len as usize));
- let hash_prefix1 = php_try!(php.parse_u8("hash_prefix1"));
- let hash_prefix2 = php_try!(php.parse_u8("hash_prefix2"));
+ let digest_prefix1 = php_try!(php.parse_u8("digest_prefix1"));
+ let digest_prefix2 = php_try!(php.parse_u8("digest_prefix2"));
if ! pk_algo.for_signing() {
return php.fail("not a signature algorithm");
}
@@ -1021,7 +1021,7 @@ impl Signature4 {
typ.into(), pk_algo.into(), hash_algo,
SubpacketArea::new(hashed_area),
SubpacketArea::new(unhashed_area),
- [hash_prefix1, hash_prefix2],
+ [digest_prefix1, digest_prefix2],
mpis).into()))?;
// Locate the corresponding HashedReader and extract the
@@ -1150,7 +1150,7 @@ fn signature_parser_test () {
assert_eq!(p.hash_algo(), HashAlgorithm::SHA512);
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.digest_prefix(), &[0x65u8, 0x74]);
assert_eq!(p.mpis().serialized_len(), 258);
} else {
panic!("Wrong packet!");
@@ -1351,21 +1351,21 @@ impl<'a> Parse<'a, OnePassSig3> for OnePassSig3 {
fn one_pass_sig_test () {
struct Test<'a> {
filename: &'a str,
- hash_prefix: Vec<[u8; 2]>,
+ digest_prefix: Vec<[u8; 2]>,
};
let tests = [
Test {
filename: "signed-1.gpg",
- hash_prefix: vec![ [ 0x83, 0xF5 ] ],
+ digest_prefix: vec![ [ 0x83, 0xF5 ] ],
},
Test {
filename: "signed-2-partial-body.gpg",
- hash_prefix: vec![ [ 0x2F, 0xBE ] ],
+ digest_prefix: vec![ [ 0x2F, 0xBE ] ],
},
Test {
filename: "signed-3-partial-body-multiple-sigs.gpg",
- hash_prefix: vec![ [ 0x29, 0x64 ], [ 0xff, 0x7d ] ],
+ digest_prefix: vec![ [ 0x29, 0x64 ], [ 0xff, 0x7d ] ],
},
];
@@ -1385,19 +1385,19 @@ fn one_pass_sig_test () {
} else if let Packet::Signature(ref sig) = pp.packet {
eprintln!(" {}:\n prefix: expected: {}, in sig: {}",
test.filename,
- crate::fmt::to_hex(&test.hash_prefix[sigs][..], false),
- crate::fmt::to_hex(sig.hash_prefix(), false));
+ crate::fmt::to_hex(&test.digest_prefix[sigs][..], false),
+ crate::fmt::to_hex(sig.digest_prefix(), false));
eprintln!(" computed hash: {}",
crate::fmt::to_hex(&sig.computed_digest().unwrap(),
false));
- assert_eq!(&test.hash_prefix[sigs], sig.hash_prefix());
- assert_eq!(&test.hash_prefix[sigs][..],
+ assert_eq!(&test.digest_prefix[sigs], sig.digest_prefix());
+ assert_eq!(&test.digest_prefix[sigs][..],
&sig.computed_digest().unwrap()[..2]);
sigs += 1;
} else if one_pass_sigs > 0 {
- assert_eq!(one_pass_sigs, test.hash_prefix.len(),
+ assert_eq!(one_pass_sigs, test.digest_prefix.len(),
"Number of OnePassSig packets does not match \
number of expected OnePassSig packets.");
}
diff --git a/openpgp/src/serialize/mod.rs b/openpgp/src/serialize/mod.rs
index dba3c443..d1b7393d 100644
--- a/openpgp/src/serialize/mod.rs
+++ b/openpgp/src/serialize/mod.rs
@@ -1194,8 +1194,8 @@ impl Serialize for Signature4 {
write_be_u16(o, self.unhashed_area().data.len() as u16)?;
o.write_all(&self.unhashed_area().data[..])?;
- write_byte(o, self.hash_prefix()[0])?;
- write_byte(o, self.hash_prefix()[1])?;
+ write_byte(o, self.digest_prefix()[0])?;
+ write_byte(o, self.digest_prefix()[1])?;
self.mpis().serialize(o)?;
diff --git a/tool/src/commands/dump.rs b/tool/src/commands/dump.rs
index 324a34a9..cd9c2cea 100644
--- a/tool/src/commands/dump.rs
+++ b/tool/src/commands/dump.rs
@@ -447,8 +447,8 @@ impl PacketDumper {
self.dump_subpacket(output, i, pkt, s)?;
}
}
- writeln!(output, "{} Hash prefix: {}", i,
- hex::encode(s.hash_prefix()))?;
+ writeln!(output, "{} Digest prefix: {}", i,
+ hex::encode(s.digest_prefix()))?;
write!(output, "{} Level: {} ", i, s.level())?;
match s.level() {
0 => writeln!(output, "(signature over data)")?,