From 857845f523ab090638693d5498c8753e1e41cf36 Mon Sep 17 00:00:00 2001 From: Wiktor Kwapisiewicz Date: Fri, 20 Mar 2020 15:14:05 +0100 Subject: openpgp: Remove `to_hex` in KeyHandle, KeyID and Fingerprint. - Replace all usages of `to_hex` with formatting string with :X specifier. - Fixes #456. --- store/src/backend/mod.rs | 12 ++++++------ store/src/lib.rs | 6 +++--- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'store') 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(¤t)); - 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 { - 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 { - 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 { - 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(¤t)?; - 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 { 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 { 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) -- cgit v1.2.3