From 9dbab74e689bece1d150ddb87d44af7ffcee2cc9 Mon Sep 17 00:00:00 2001 From: Allen Date: Fri, 14 Jan 2022 13:05:41 -0800 Subject: [PATCH] fix conversion bug --- did-webkey/Cargo.toml | 1 + did-webkey/src/lib.rs | 28 +++++++++++++++++++++------- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/did-webkey/Cargo.toml b/did-webkey/Cargo.toml index 04cd1e5b1..16c67f48b 100644 --- a/did-webkey/Cargo.toml +++ b/did-webkey/Cargo.toml @@ -25,6 +25,7 @@ ssi = { version = "0.3", path = "../", features = [ ], default-features = false } async-trait = "0.1" reqwest = { version = "0.11", features = ["json"] } +hex = "0.4" http = "0.2" serde_json = "1.0" serde = { version = "1.0", features = ["derive"] } diff --git a/did-webkey/src/lib.rs b/did-webkey/src/lib.rs index 02b4e7505..528ac518e 100644 --- a/did-webkey/src/lib.rs +++ b/did-webkey/src/lib.rs @@ -3,7 +3,11 @@ use core::str::FromStr; use async_trait::async_trait; use serde::{Deserialize, Serialize}; -#[cfg(all(not(target_arch = "wasm32"), feature = "sequoia-openpgp"))] +#[cfg(all( + not(target_arch = "wasm32"), + feature = "sequoia-openpgp", + not(feature = "pgp") +))] use openpgp::{ cert::prelude::*, parse::{PacketParser, Parse}, @@ -15,7 +19,11 @@ use pgp::{ errors::Error as PgpError, types::KeyTrait, }; -#[cfg(all(not(target_arch = "wasm32"), feature = "sequoia-openpgp"))] +#[cfg(all( + not(target_arch = "wasm32"), + feature = "sequoia-openpgp", + not(feature = "pgp") +))] use sequoia_openpgp as openpgp; use sshkeys::PublicKeyKind; use ssi::did::{DIDMethod, Document, VerificationMethod, VerificationMethodMap, DIDURL}; @@ -52,7 +60,11 @@ impl FromStr for DIDWebKeyType { } } -#[cfg(all(not(target_arch = "wasm32"), feature = "sequoia-openpgp"))] +#[cfg(all( + not(target_arch = "wasm32"), + feature = "sequoia-openpgp", + not(feature = "pgp") +))] fn parse_pubkeys_gpg( did: &str, bytes: Vec, @@ -77,7 +89,11 @@ fn parse_pubkeys_gpg( Ok((vm_maps, did_urls)) } -#[cfg(all(not(target_arch = "wasm32"), feature = "sequoia-openpgp"))] +#[cfg(all( + not(target_arch = "wasm32"), + feature = "sequoia-openpgp", + not(feature = "pgp") +))] fn gpg_pk_to_vm(did: &str, cert: Cert) -> Result<(VerificationMethodMap, DIDURL), String> { let vm_url = DIDURL { did: did.to_string(), @@ -144,9 +160,7 @@ fn gpg_pk_to_vm( did: &str, key: SignedPublicKey, ) -> Result<(VerificationMethodMap, DIDURL), String> { - // BUG: Can't convert to UTF-8 here - let fingerprint: String = String::from_utf8(key.fingerprint()) - .map_err(|e| format!("Error converting fingerprint to utf8: {}", e))?; + let fingerprint: String = hex::encode_upper(key.fingerprint()); let vm_url = DIDURL { did: did.to_string(),