summaryrefslogtreecommitdiffstats
path: root/openpgp/src
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 /openpgp/src
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.
Diffstat (limited to 'openpgp/src')
-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
6 files changed, 7 insertions, 25 deletions
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!");