summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@sequoia-pgp.org>2019-11-26 13:04:47 +0100
committerJustus Winter <justus@sequoia-pgp.org>2019-11-26 14:29:29 +0100
commitb24d1c5a099e2c741cf724816d49b8dd7977e049 (patch)
tree0288feb61d74b61acc39045a5e2b31551eb7b131
parent33fd6f48682b15e140d479574ec3377610acb22d (diff)
openpgp: Implement From<Fingerprint> for KeyID.
- Remove Fingerprint::to_keyid, use From instead.
-rw-r--r--net/src/lib.rs2
-rw-r--r--openpgp-ffi/src/fingerprint.rs2
-rw-r--r--openpgp/src/fingerprint.rs12
-rw-r--r--openpgp/src/keyid.rs26
-rw-r--r--openpgp/src/packet/key/mod.rs2
-rw-r--r--openpgp/src/packet/signature/mod.rs4
-rw-r--r--openpgp/src/packet/signature/subpacket.rs4
-rw-r--r--openpgp/src/tpk/parser/mod.rs2
-rw-r--r--sqv/src/sqv.rs2
-rw-r--r--sqv/tests/revoked-key.rs12
-rw-r--r--sqv/tests/wrong-key-flags.rs2
-rw-r--r--store/src/backend/mod.rs6
-rw-r--r--store/src/lib.rs2
-rw-r--r--tool/src/commands/decrypt.rs10
-rw-r--r--tool/src/commands/mod.rs2
15 files changed, 51 insertions, 39 deletions
diff --git a/net/src/lib.rs b/net/src/lib.rs
index 277761a8..3ab03a61 100644
--- a/net/src/lib.rs
+++ b/net/src/lib.rs
@@ -184,7 +184,7 @@ impl KeyServer {
match TPK::from_reader(r) {
Ok(tpk) => {
if tpk.keys_all().any(|(_, _, key)| {
- key.fingerprint().to_keyid()
+ KeyID::from(key.fingerprint())
== keyid_want
}) {
future::done(Ok(tpk))
diff --git a/openpgp-ffi/src/fingerprint.rs b/openpgp-ffi/src/fingerprint.rs
index 794973aa..a74f64f0 100644
--- a/openpgp-ffi/src/fingerprint.rs
+++ b/openpgp-ffi/src/fingerprint.rs
@@ -99,5 +99,5 @@ fn pgp_fingerprint_to_hex(fp: *const Fingerprint)
#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "C"
fn pgp_fingerprint_to_keyid(fp: *const Fingerprint)
-> *mut KeyID {
- fp.ref_raw().to_keyid().move_into_raw()
+ openpgp::KeyID::from(fp.ref_raw()).move_into_raw()
}
diff --git a/openpgp/src/fingerprint.rs b/openpgp/src/fingerprint.rs
index 309313be..ab662ed1 100644
--- a/openpgp/src/fingerprint.rs
+++ b/openpgp/src/fingerprint.rs
@@ -1,7 +1,6 @@
use std::fmt;
use crate::Fingerprint;
-use crate::KeyID;
use crate::Result;
impl fmt::Display for Fingerprint {
@@ -129,17 +128,6 @@ impl Fingerprint {
String::from_utf8(output).unwrap()
}
- /// Converts the fingerprint to a key ID.
- pub fn to_keyid(&self) -> KeyID {
- match self {
- &Fingerprint::V4(ref fp) =>
- KeyID::from_bytes(&fp[fp.len() - 8..]),
- &Fingerprint::Invalid(ref fp) => {
- KeyID::Invalid(fp.clone())
- }
- }
- }
-
/// Converts the hex representation of the fingerprint to a phrase in the
/// ICAO alphabet.
pub fn to_icao(&self) -> String {
diff --git a/openpgp/src/keyid.rs b/openpgp/src/keyid.rs
index 275599f9..5cda407b 100644
--- a/openpgp/src/keyid.rs
+++ b/openpgp/src/keyid.rs
@@ -45,6 +45,30 @@ impl From<u64> for KeyID {
}
}
+impl From<&Fingerprint> for KeyID {
+ fn from(fp: &Fingerprint) -> Self {
+ match fp {
+ Fingerprint::V4(fp) =>
+ KeyID::from_bytes(&fp[fp.len() - 8..]),
+ Fingerprint::Invalid(fp) => {
+ KeyID::Invalid(fp.clone())
+ }
+ }
+ }
+}
+
+impl From<Fingerprint> for KeyID {
+ fn from(fp: Fingerprint) -> Self {
+ match fp {
+ Fingerprint::V4(fp) =>
+ KeyID::from_bytes(&fp[fp.len() - 8..]),
+ Fingerprint::Invalid(fp) => {
+ KeyID::Invalid(fp)
+ }
+ }
+ }
+}
+
impl KeyID {
/// Converts a u64 to a KeyID.
pub fn new(data: u64) -> KeyID {
@@ -100,7 +124,7 @@ impl KeyID {
} else {
// Maybe a fingerprint was given. Try to parse it and
// convert it to a KeyID.
- Ok(Fingerprint::from_hex(hex)?.to_keyid())
+ Ok(Fingerprint::from_hex(hex)?.into())
}
}
diff --git a/openpgp/src/packet/key/mod.rs b/openpgp/src/packet/key/mod.rs
index a1b3c561..ea1178f1 100644
--- a/openpgp/src/packet/key/mod.rs
+++ b/openpgp/src/packet/key/mod.rs
@@ -1070,7 +1070,7 @@ impl<P, R> Key4<P, R>
/// Computes and returns the key's key ID as per Section 12.2 of
/// RFC 4880.
pub fn keyid(&self) -> KeyID {
- self.fingerprint().to_keyid()
+ self.fingerprint().into()
}
}
diff --git a/openpgp/src/packet/signature/mod.rs b/openpgp/src/packet/signature/mod.rs
index 460dbe21..4fb15d18 100644
--- a/openpgp/src/packet/signature/mod.rs
+++ b/openpgp/src/packet/signature/mod.rs
@@ -507,7 +507,7 @@ impl Signature4 {
if let Some(issuer) = self.issuer_fingerprint() {
// Prefer the IssuerFingerprint.
area.add(Subpacket::new(
- SubpacketValue::Issuer(issuer.to_keyid()), false).unwrap())
+ SubpacketValue::Issuer(issuer.into()), false).unwrap())
.unwrap();
} else if let Some(issuer) = self.issuer() {
// Fall back to the Issuer, which we will also get
@@ -1394,7 +1394,7 @@ mod test {
hash.update(&msg[..]);
let fp = Fingerprint::from_bytes(b"bbbbbbbbbbbbbbbbbbbb");
- let keyid = fp.to_keyid();
+ let keyid = KeyID::from(&fp);
// First, make sure any superfluous subpackets are removed,
// yet the Issuer and EmbeddedSignature ones are kept.
diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs
index f0950a1d..557c8eef 100644
--- a/openpgp/src/packet/signature/subpacket.rs
+++ b/openpgp/src/packet/signature/subpacket.rs
@@ -2847,10 +2847,10 @@ fn accessors() {
assert_eq!(sig_.revocation_key(),
Some((2, pk_algo.into(), fp.clone())));
- sig = sig.set_issuer(fp.to_keyid()).unwrap();
+ sig = sig.set_issuer(fp.clone().into()).unwrap();
let sig_ =
sig.clone().sign_hash(&mut keypair, hash_algo, hash.clone()).unwrap();
- assert_eq!(sig_.issuer(), Some(fp.to_keyid()));
+ assert_eq!(sig_.issuer(), Some(fp.clone().into()));
let pref = vec![HashAlgorithm::SHA512,
HashAlgorithm::SHA384,
diff --git a/openpgp/src/tpk/parser/mod.rs b/openpgp/src/tpk/parser/mod.rs
index d3d6260c..e014ef30 100644
--- a/openpgp/src/tpk/parser/mod.rs
+++ b/openpgp/src/tpk/parser/mod.rs
@@ -673,7 +673,7 @@ impl<'a, I: Iterator<Item=Packet>> TPKParser<'a, I> {
}
let primary_fp = tpk.primary().fingerprint();
- let primary_keyid = primary_fp.to_keyid();
+ let primary_keyid = KeyID::from(&primary_fp);
// The parser puts all of the signatures on the
// certifications field. Split them now.
diff --git a/sqv/src/sqv.rs b/sqv/src/sqv.rs
index 193dc88c..71ffd912 100644
--- a/sqv/src/sqv.rs
+++ b/sqv/src/sqv.rs
@@ -108,7 +108,7 @@ fn real_main() -> Result<(), failure::Error> {
// XXX: We use a KeyID even though we have a
// fingerprint!
- sigs.push((sig, fp.to_keyid(), None));
+ sigs.push((sig, fp.into(), None));
} else if let Some(keyid) = sig.issuer() {
if trace {
eprintln!("Will check signature allegedly issued by {}.",
diff --git a/sqv/tests/revoked-key.rs b/sqv/tests/revoked-key.rs
index dd7ef26b..7667a003 100644
--- a/sqv/tests/revoked-key.rs
+++ b/sqv/tests/revoked-key.rs
@@ -96,7 +96,7 @@ mod integration {
// b.set_signature_creation_time(t1).unwrap();
// b.set_key_expiration_time(Some(time::Duration::weeks(10 * 52))).unwrap();
// b.set_issuer_fingerprint(key.fingerprint()).unwrap();
-// b.set_issuer(key.fingerprint().to_keyid()).unwrap();
+// b.set_issuer(key.fingerprint().into()).unwrap();
// b.set_preferred_hash_algorithms(vec![HashAlgorithm::SHA512]).unwrap();
// let bind1 = b.sign_primary_key_binding(
// &mut KeyPair::new(key.clone(), mpis.clone()).unwrap(),
@@ -106,7 +106,7 @@ mod integration {
// b = signature::Builder::new(SignatureType::KeyRevocation);
// b.set_signature_creation_time(t2).unwrap();
// b.set_issuer_fingerprint(key.fingerprint()).unwrap();
-// b.set_issuer(key.fingerprint().to_keyid()).unwrap();
+// b.set_issuer(key.fingerprint().into()).unwrap();
// let rev = b.sign_primary_key_binding(
// &mut KeyPair::new(key.clone(), mpis.clone()).unwrap(),
// HashAlgorithm::SHA512).unwrap();
@@ -118,7 +118,7 @@ mod integration {
// b.set_signature_creation_time(t3).unwrap();
// b.set_key_expiration_time(Some(time::Duration::weeks(10 * 52))).unwrap();
// b.set_issuer_fingerprint(key.fingerprint()).unwrap();
-// b.set_issuer(key.fingerprint().to_keyid()).unwrap();
+// b.set_issuer(key.fingerprint().into()).unwrap();
// b.set_preferred_hash_algorithms(vec![HashAlgorithm::SHA512]).unwrap();
// let bind2 = b.sign_primary_key_binding(
// &mut KeyPair::new(key.clone(), mpis.clone()).unwrap(),
@@ -129,7 +129,7 @@ mod integration {
// b.set_features(&Features::sequoia()).unwrap();
// b.set_signature_creation_time(t12).unwrap();
// b.set_issuer_fingerprint(key.fingerprint()).unwrap();
-// b.set_issuer(key.fingerprint().to_keyid()).unwrap();
+// b.set_issuer(key.fingerprint().into()).unwrap();
// let sig1 = b.sign_message(
// &mut KeyPair::new(key.clone(), mpis.clone()).unwrap(),
// HashAlgorithm::SHA512, msg).unwrap();
@@ -139,7 +139,7 @@ mod integration {
// b.set_features(&Features::sequoia()).unwrap();
// b.set_signature_creation_time(t23).unwrap();
// b.set_issuer_fingerprint(key.fingerprint()).unwrap();
-// b.set_issuer(key.fingerprint().to_keyid()).unwrap();
+// b.set_issuer(key.fingerprint().into()).unwrap();
// let sig2 = b.sign_message(
// &mut KeyPair::new(key.clone(), mpis.clone()).unwrap(),
// HashAlgorithm::SHA512, msg).unwrap();
@@ -149,7 +149,7 @@ mod integration {
// b.set_features(&Features::sequoia()).unwrap();
// b.set_signature_creation_time(time::now()).unwrap();
// b.set_issuer_fingerprint(key.fingerprint()).unwrap();
-// b.set_issuer(key.fingerprint().to_keyid()).unwrap();
+// b.set_issuer(key.fingerprint().into()).unwrap();
// let sig3 = b.sign_message(
// &mut KeyPair::new(key.clone(), mpis.clone()).unwrap(),
// HashAlgorithm::SHA512, msg).unwrap();
diff --git a/sqv/tests/wrong-key-flags.rs b/sqv/tests/wrong-key-flags.rs
index 926d184c..dafbc6f9 100644
--- a/sqv/tests/wrong-key-flags.rs
+++ b/sqv/tests/wrong-key-flags.rs
@@ -53,7 +53,7 @@ mod integration {
// let mut b = signature::Builder::new(SignatureType::Binary);
// b.set_signature_creation_time(time::now()).unwrap();
// b.set_issuer_fingerprint(key.fingerprint()).unwrap();
-// b.set_issuer(key.fingerprint().to_keyid()).unwrap();
+// b.set_issuer(key.fingerprint().into()).unwrap();
// b.sign_message(
// &mut KeyPair::new(key.clone(), mpis.clone()).unwrap(),
// HashAlgorithm::SHA512, b"Hello, World").unwrap()
diff --git a/store/src/backend/mod.rs b/store/src/backend/mod.rs
index 1ed41288..2ed0458a 100644
--- a/store/src/backend/mod.rs
+++ b/store/src/backend/mod.rs
@@ -348,7 +348,7 @@ impl node::mapping::Server for MappingServer {
&self.c,
log::Refers::to().mapping(self.id).binding(binding_id).key(key_id),
&self.slug(),
- &format!("New binding {} -> {}", label, fp.to_keyid())));
+ &format!("New binding {} -> {}", label, KeyID::from(fp))));
}
@@ -913,7 +913,7 @@ impl KeyServer {
let keyserver = net::KeyServer::keys_openpgp_org(&ctx)?;
Ok((KeyServer::new(c.clone(), id),
- fingerprint.to_keyid(),
+ fingerprint.into(),
keyserver))
}
@@ -1005,7 +1005,7 @@ impl Query for KeyServer {
&[&self.id], |row| -> rusqlite::Result<String> { row.get(0) })
.ok()
.and_then(|fp| Fingerprint::from_hex(&fp).ok())
- .map(|fp| fp.to_keyid().to_string())
+ .map(|fp| KeyID::from(fp).to_string())
.unwrap_or(
format!("{}::{}", Self::table_name(), self.id())
)
diff --git a/store/src/lib.rs b/store/src/lib.rs
index c24cd0d3..29aff727 100644
--- a/store/src/lib.rs
+++ b/store/src/lib.rs
@@ -229,7 +229,7 @@ impl Store {
/// # let tpk = TPK::from_bytes(
/// # &include_bytes!("../../openpgp/tests/data/keys/testy.pgp")[..]).unwrap();
/// Store::import(&ctx, &tpk)?;
- /// let key = Store::lookup_by_keyid(&ctx, &tpk.fingerprint().to_keyid())?;
+ /// let key = Store::lookup_by_keyid(&ctx, &tpk.fingerprint().into())?;
/// assert_eq!(key.tpk()?.fingerprint(), tpk.fingerprint());
/// # Ok(())
/// # }
diff --git a/tool/src/commands/decrypt.rs b/tool/src/commands/decrypt.rs
index 095e247a..b85e6797 100644
--- a/tool/src/commands/decrypt.rs
+++ b/tool/src/commands/decrypt.rs
@@ -54,12 +54,12 @@ impl<'a> Helper<'a> {
let hint = match tsk.userids().nth(0) {
Some(uid) => format!("{} ({})", uid.userid(),
- tsk.fingerprint().to_keyid()),
- None => format!("{}", tsk.fingerprint().to_keyid()),
+ KeyID::from(tsk.fingerprint())),
+ None => format!("{}", KeyID::from(tsk.fingerprint())),
};
if can_encrypt(tsk.primary(), tsk.primary_key_signature(None)) {
- let id = tsk.fingerprint().to_keyid();
+ let id: KeyID = tsk.fingerprint().into();
keys.insert(id.clone(), tsk.primary().clone().into());
identities.insert(id.clone(), tsk.fingerprint());
hints.insert(id, hint.clone());
@@ -68,7 +68,7 @@ impl<'a> Helper<'a> {
for skb in tsk.subkeys() {
let key = skb.key();
if can_encrypt(key, skb.binding_signature(None)) {
- let id = key.fingerprint().to_keyid();
+ let id: KeyID = key.fingerprint().into();
keys.insert(id.clone(), key.clone().into());
identities.insert(id.clone(), tsk.fingerprint());
hints.insert(id, hint.clone());
@@ -101,7 +101,7 @@ impl<'a> Helper<'a> {
-> openpgp::Result<Option<Fingerprint>>
where D: FnMut(SymmetricAlgorithm, &SessionKey) -> openpgp::Result<()>
{
- let keyid = keypair.public().fingerprint().to_keyid();
+ let keyid = keypair.public().fingerprint().into();
match pkesk.decrypt(keypair)
.and_then(|(algo, sk)| {
decrypt(algo, &sk)?; Ok(sk)
diff --git a/tool/src/commands/mod.rs b/tool/src/commands/mod.rs
index 9bdb548a..6189ac4c 100644
--- a/tool/src/commands/mod.rs
+++ b/tool/src/commands/mod.rs
@@ -320,7 +320,7 @@ impl<'a> VerificationHelper for VHelper<'a> {
.flat_map(|tpk| {
// Even if a key is revoked or expired, we can still
// use it to verify a message.
- tpk.keys_all().map(|(_, _, key)| key.fingerprint().to_keyid())
+ tpk.keys_all().map(|(_, _, key)| key.fingerprint().into())
}).collect();
// Explicitly provided keys are trusted.