summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWiktor Kwapisiewicz <wiktor@metacode.biz>2020-03-20 15:14:05 +0100
committerWiktor Kwapisiewicz <wiktor@metacode.biz>2020-03-20 15:36:58 +0100
commit857845f523ab090638693d5498c8753e1e41cf36 (patch)
tree589fe471f65f98f3438633d83894fb160aa04f6f
parent8905aabfa245754426bd67ba5319024e61fc39db (diff)
openpgp: Remove `to_hex` in KeyHandle, KeyID and Fingerprint.
- Replace all usages of `to_hex` with formatting string with :X specifier. - Fixes #456.
-rw-r--r--ipc/examples/gpg-agent-decrypt.rs12
-rw-r--r--net/src/lib.rs3
-rw-r--r--openpgp-ffi/src/fingerprint.rs2
-rw-r--r--openpgp-ffi/src/keyid.rs2
-rw-r--r--openpgp/src/cert/mod.rs6
-rw-r--r--openpgp/src/fingerprint.rs9
-rw-r--r--openpgp/src/keyhandle.rs8
-rw-r--r--openpgp/src/keyid.rs5
-rw-r--r--openpgp/src/packet/signature/subpacket.rs2
-rw-r--r--openpgp/src/parse/parse.rs2
-rw-r--r--sqv/src/sqv.rs26
-rw-r--r--store/src/backend/mod.rs12
-rw-r--r--store/src/lib.rs6
13 files changed, 38 insertions, 57 deletions
diff --git a/ipc/examples/gpg-agent-decrypt.rs b/ipc/examples/gpg-agent-decrypt.rs
index f2ba2903..bd524e80 100644
--- a/ipc/examples/gpg-agent-decrypt.rs
+++ b/ipc/examples/gpg-agent-decrypt.rs
@@ -150,17 +150,17 @@ impl<'a> VerificationHelper for Helper<'a> {
},
Err(MissingKey { sig, .. }) => {
let issuers = sig.get_issuers();
- eprintln!("Missing key {}, which is needed to \
+ eprintln!("Missing key {:X}, which is needed to \
verify signature.",
- issuers.first().unwrap().to_hex());
+ issuers.first().unwrap());
},
Err(UnboundKey { cert, error, .. }) => {
- eprintln!("Signing key on {} is not bound: {}",
- cert.fingerprint().to_hex(), error);
+ eprintln!("Signing key on {:X} is not bound: {}",
+ cert.fingerprint(), error);
},
Err(BadKey { ka, error, .. }) => {
- eprintln!("Signing key on {} is bad: {}",
- ka.cert().fingerprint().to_hex(),
+ eprintln!("Signing key on {:X} is bad: {}",
+ ka.cert().fingerprint(),
error);
},
Err(BadSignature { error, .. }) => {
diff --git a/net/src/lib.rs b/net/src/lib.rs
index 15f6ddb0..5f194550 100644
--- a/net/src/lib.rs
+++ b/net/src/lib.rs
@@ -159,8 +159,7 @@ impl KeyServer {
-> Box<dyn Future<Item=Cert, Error=anyhow::Error> + 'static> {
let keyid_want = keyid.clone();
let uri = self.uri.join(
- &format!("pks/lookup?op=get&options=mr&search=0x{}",
- keyid.to_hex()));
+ &format!("pks/lookup?op=get&options=mr&search=0x{:X}", keyid));
if let Err(e) = uri {
// This shouldn't happen, but better safe than sorry.
return Box::new(future::err(Error::from(e).into()));
diff --git a/openpgp-ffi/src/fingerprint.rs b/openpgp-ffi/src/fingerprint.rs
index 549311b5..86bb7d21 100644
--- a/openpgp-ffi/src/fingerprint.rs
+++ b/openpgp-ffi/src/fingerprint.rs
@@ -92,7 +92,7 @@ fn pgp_fingerprint_as_bytes(fp: *const Fingerprint,
#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "C"
fn pgp_fingerprint_to_hex(fp: *const Fingerprint)
-> *mut c_char {
- ffi_return_string!(fp.ref_raw().to_hex())
+ ffi_return_string!(format!("{:X}", fp.ref_raw()))
}
/// Converts the fingerprint to a key ID.
diff --git a/openpgp-ffi/src/keyid.rs b/openpgp-ffi/src/keyid.rs
index 8ec550a0..fb1fc735 100644
--- a/openpgp-ffi/src/keyid.rs
+++ b/openpgp-ffi/src/keyid.rs
@@ -87,5 +87,5 @@ fn pgp_keyid_from_hex(id: *const c_char) -> Maybe<KeyID> {
/// Converts the KeyID to a hexadecimal number.
#[::sequoia_ffi_macros::extern_fn] #[no_mangle] pub extern "C"
fn pgp_keyid_to_hex(id: *const KeyID) -> *mut c_char {
- ffi_return_string!(id.ref_raw().to_hex())
+ ffi_return_string!(format!("{:X}", id.ref_raw()))
}
diff --git a/openpgp/src/cert/mod.rs b/openpgp/src/cert/mod.rs
index df555a10..d1c07bb6 100644
--- a/openpgp/src/cert/mod.rs
+++ b/openpgp/src/cert/mod.rs
@@ -1531,7 +1531,7 @@ mod test {
i == 0).unwrap();
assert_eq!(cert.primary.key().creation_time(),
Timestamp::from(1511355130).into());
- assert_eq!(cert.fingerprint().to_hex(),
+ assert_eq!(format!("{:X}", cert.fingerprint()),
"3E8877C877274692975189F5D03F6F865226FE8B");
assert_eq!(cert.userids.len(), 1, "number of userids");
@@ -1553,7 +1553,7 @@ mod test {
i == 0).unwrap();
assert_eq!(cert.primary.key().creation_time(),
Timestamp::from(1511355130).into());
- assert_eq!(cert.fingerprint().to_hex(),
+ assert_eq!(format!("{:X}", cert.fingerprint()),
"3E8877C877274692975189F5D03F6F865226FE8B");
assert_eq!(cert.user_attributes.len(), 0);
@@ -1568,7 +1568,7 @@ mod test {
assert_eq!(cert.subkeys.len(), 0, "number of subkeys");
let cert = parse_cert(crate::tests::key("testy.asc"), i == 0).unwrap();
- assert_eq!(cert.fingerprint().to_hex(),
+ assert_eq!(format!("{:X}", cert.fingerprint()),
"3E8877C877274692975189F5D03F6F865226FE8B");
}
}
diff --git a/openpgp/src/fingerprint.rs b/openpgp/src/fingerprint.rs
index fedf23b5..edbc0774 100644
--- a/openpgp/src/fingerprint.rs
+++ b/openpgp/src/fingerprint.rs
@@ -63,7 +63,7 @@ impl Fingerprint {
/// let hex = "3E8877C877274692975189F5D03F6F865226FE8B";
/// let fp = Fingerprint::from_hex(hex);
/// assert!(fp.is_ok());
- /// assert_eq!(fp.unwrap().to_hex(), hex);
+ /// assert_eq!(format!("{:X}", fp.unwrap()), hex);
/// ```
pub fn from_hex(hex: &str) -> Result<Fingerprint> {
Ok(Fingerprint::from_bytes(&crate::fmt::from_hex(hex, true)?[..]))
@@ -77,11 +77,6 @@ impl Fingerprint {
}
}
- /// Converts the fingerprint to a hexadecimal number.
- pub fn to_hex(&self) -> String {
- self.convert_to_string(false)
- }
-
/// Common code for the above functions.
fn convert_to_string(&self, pretty: bool) -> String {
let raw = match self {
@@ -140,7 +135,7 @@ impl Fingerprint {
pub fn to_icao(&self) -> String {
let mut ret = String::default();
- for ch in self.to_hex().chars() {
+ for ch in self.convert_to_string(false).chars() {
let word = match ch {
'0' => "Zero",
'1' => "One",
diff --git a/openpgp/src/keyhandle.rs b/openpgp/src/keyhandle.rs
index 80293fe6..8c08c117 100644
--- a/openpgp/src/keyhandle.rs
+++ b/openpgp/src/keyhandle.rs
@@ -146,14 +146,6 @@ impl PartialEq for KeyHandle {
}
impl KeyHandle {
- /// Converts the key handle to a hexadecimal number.
- pub fn to_hex(&self) -> String {
- match self {
- KeyHandle::Fingerprint(i) => i.to_hex(),
- KeyHandle::KeyID(i) => i.to_hex(),
- }
- }
-
/// Returns a reference to the raw identifier.
pub fn as_slice(&self) -> &[u8] {
match self {
diff --git a/openpgp/src/keyid.rs b/openpgp/src/keyid.rs
index 44619252..e7e262fd 100644
--- a/openpgp/src/keyid.rs
+++ b/openpgp/src/keyid.rs
@@ -166,11 +166,6 @@ impl KeyID {
self.as_slice().iter().all(|b| *b == 0)
}
- /// Converts the key ID to a hexadecimal number.
- pub fn to_hex(&self) -> String {
- self.convert_to_string(false)
- }
-
/// Common code for the above functions.
fn convert_to_string(&self, pretty: bool) -> String {
let raw = match self {
diff --git a/openpgp/src/packet/signature/subpacket.rs b/openpgp/src/packet/signature/subpacket.rs
index bb597f4c..ecdca28e 100644
--- a/openpgp/src/packet/signature/subpacket.rs
+++ b/openpgp/src/packet/signature/subpacket.rs
@@ -2618,7 +2618,7 @@ fn subpacket_test_1 () {
fp == "7FAF 6ED7 2381 4355 7BDF 7ED2 6863 C9AD 5B4D 22D3"
|| fp == "C03F A641 1B03 AE12 5764 6118 7223 B566 78E0 2528");
- let hex = sig.issuer_fingerprint().unwrap().to_hex();
+ let hex = format!("{:X}", sig.issuer_fingerprint().unwrap());
assert!(
hex == "7FAF6ED7238143557BDF7ED26863C9AD5B4D22D3"
|| hex == "C03FA6411B03AE12576461187223B56678E02528");
diff --git a/openpgp/src/parse/parse.rs b/openpgp/src/parse/parse.rs
index 5031e796..6ef9fac0 100644
--- a/openpgp/src/parse/parse.rs
+++ b/openpgp/src/parse/parse.rs
@@ -1664,7 +1664,7 @@ fn one_pass_sig_parser_test () {
assert_eq!(p.typ(), SignatureType::Binary);
assert_eq!(p.hash_algo(), HashAlgorithm::SHA512);
assert_eq!(p.pk_algo(), PublicKeyAlgorithm::RSAEncryptSign);
- assert_eq!(p.issuer().to_hex(), "7223B56678E02528");
+ assert_eq!(format!("{:X}", p.issuer()), "7223B56678E02528");
assert_eq!(p.last_raw(), 1);
} else {
panic!("Wrong packet!");
diff --git a/sqv/src/sqv.rs b/sqv/src/sqv.rs
index dfa6042b..cb458797 100644
--- a/sqv/src/sqv.rs
+++ b/sqv/src/sqv.rs
@@ -152,14 +152,14 @@ impl<'a> VerificationHelper for VHelper<'a> {
(Some(t), Some(not_before), not_after) => {
if t < not_before {
eprintln!(
- "Signature by {} was created before \
+ "Signature by {:X} was created before \
the --not-before date.",
- ka.key().fingerprint().to_hex());
+ ka.key().fingerprint());
} else if t > not_after {
eprintln!(
- "Signature by {} was created after \
+ "Signature by {:X} was created after \
the --not-after date.",
- ka.key().fingerprint().to_hex());
+ ka.key().fingerprint());
} else {
signers.push(ka.cert().fingerprint());
}
@@ -167,9 +167,9 @@ impl<'a> VerificationHelper for VHelper<'a> {
(Some(t), None, not_after) => {
if t > not_after {
eprintln!(
- "Signature by {} was created after \
+ "Signature by {:X} was created after \
the --not-after date.",
- ka.key().fingerprint().to_hex());
+ ka.key().fingerprint());
} else {
signers.push(ka.cert().fingerprint());
}
@@ -181,17 +181,17 @@ impl<'a> VerificationHelper for VHelper<'a> {
}
Err(MissingKey { sig, .. }) => {
let issuers = sig.get_issuers();
- eprintln!("Missing key {}, which is needed to \
+ eprintln!("Missing key {:X}, which is needed to \
verify signature.",
- issuers.first().unwrap().to_hex());
+ issuers.first().unwrap());
}
Err(UnboundKey { cert, error, .. }) => {
- eprintln!("Signing key on {} is not bound: {}",
- cert.fingerprint().to_hex(), error);
+ eprintln!("Signing key on {:X} is not bound: {}",
+ cert.fingerprint(), error);
}
Err(BadKey { ka, error, .. }) => {
- eprintln!("Signing key on {} is bad: {}",
- ka.cert().fingerprint().to_hex(),
+ eprintln!("Signing key on {:X} is bad: {}",
+ ka.cert().fingerprint(),
error);
}
Err(BadSignature { error, .. }) => {
@@ -215,7 +215,7 @@ impl<'a> VerificationHelper for VHelper<'a> {
self.good = signers.len();
for signer in signers {
- println!("{}", signer.to_hex());
+ println!("{:X}", signer);
}
Ok(())
diff --git a/store/src/backend/mod.rs b/store/src/backend/mod.rs
index 342a14c4..91803a42 100644
--- a/store/src/backend/mod.rs
+++ b/store/src/backend/mod.rs
@@ -568,7 +568,7 @@ impl node::binding::Server for BindingServer {
// If we found one, convert it to Cert.
let current = if let Some(current) = key {
let current = sry!(Cert::from_bytes(&current));
- if current.fingerprint().to_hex() != fingerprint {
+ if format!("{:X}", current.fingerprint()) != fingerprint {
// Inconsistent database.
fail!(node::Error::SystemError);
}
@@ -578,7 +578,7 @@ impl node::binding::Server for BindingServer {
};
// Check for conflicts.
- if new.fingerprint().to_hex() != fingerprint {
+ if format!("{:X}", new.fingerprint()) != fingerprint {
if force {
// Update binding, and retry.
let key_id =
@@ -716,7 +716,7 @@ impl KeyServer {
///
/// On success, the id of the key is returned.
fn lookup(c: &Connection, fp: &Fingerprint) -> Result<ID> {
- let fp = fp.to_hex();
+ let fp = format!("{:X}", fp);
Ok(c.query_row(
"SELECT id FROM keys WHERE fingerprint = ?1",
&[&fp], |row| row.get(0))?)
@@ -726,7 +726,7 @@ impl KeyServer {
///
/// On success, the id of the key is returned.
fn lookup_by_id(c: &Connection, keyid: &KeyID) -> Result<ID> {
- let keyid = format!("%{}", keyid.to_hex());
+ let keyid = format!("%{:X}", keyid);
Ok(c.query_row(
"SELECT id FROM keys WHERE fingerprint LIKE ?1",
&[&keyid], |row| row.get(0))?)
@@ -736,7 +736,7 @@ impl KeyServer {
///
/// On success, the id of the key is returned.
fn lookup_or_create(c: &Connection, fp: &Fingerprint) -> Result<ID> {
- let fp = fp.to_hex();
+ let fp = format!("{:X}", fp);
if let Ok(x) = c.query_row(
"SELECT id FROM keys WHERE fingerprint = ?1",
&[&fp], |row| row.get(0)) {
@@ -780,7 +780,7 @@ impl KeyServer {
if let Some(current) = key {
let current = Cert::from_bytes(&current)?;
- if current.fingerprint().to_hex() != fingerprint {
+ if format!("{:X}", current.fingerprint()) != fingerprint {
// Inconsistent database.
return Err(node::Error::SystemError.into());
}
diff --git a/store/src/lib.rs b/store/src/lib.rs
index 28ef59c4..1156a5ad 100644
--- a/store/src/lib.rs
+++ b/store/src/lib.rs
@@ -200,7 +200,7 @@ impl Store {
pub fn lookup(c: &Context, fp: &Fingerprint) -> Result<Key> {
let (mut core, client) = Self::connect(c)?;
let mut request = client.lookup_by_fingerprint_request();
- let fp = fp.to_hex();
+ let fp = format!("{:X}", fp);
request.get().set_fingerprint(&fp);
let key = make_request!(&mut core, request)?;
Ok(Key::new(Rc::new(RefCell::new(core)), key))
@@ -385,7 +385,7 @@ impl Mapping {
pub fn add(&self, label: &str, fingerprint: &Fingerprint) -> Result<Binding> {
let mut request = self.mapping.add_request();
request.get().set_label(label);
- request.get().set_fingerprint(fingerprint.to_hex().as_ref());
+ request.get().set_fingerprint(format!("{:X}", fingerprint).as_ref());
let binding = make_request!(self.core.borrow_mut(), request)?;
Ok(Binding::new(self.core.clone(), Some(label), binding))
}
@@ -419,7 +419,7 @@ impl Mapping {
let fingerprint = cert.fingerprint();
let mut request = self.mapping.add_request();
request.get().set_label(label);
- request.get().set_fingerprint(fingerprint.to_hex().as_ref());
+ request.get().set_fingerprint(format!("{:X}", fingerprint).as_ref());
let binding = make_request!(self.core.borrow_mut(), request)?;
let binding = Binding::new(self.core.clone(), Some(label), binding);
binding.import(cert)