diff options
author | Bryan Newbold <bnewbold@robocracy.org> | 2022-11-06 21:15:12 -0800 |
---|---|---|
committer | Bryan Newbold <bnewbold@robocracy.org> | 2022-11-06 21:15:12 -0800 |
commit | ae03334a64b1d7d6506ffb60a01f5c7f941900a6 (patch) | |
tree | 87ffe21c51e2e404d798a9e257079410ac044fde /adenosine-pds/src/ucan_p256.rs | |
parent | 8c217067ee5132c6e5453e1c09b2391880e51d83 (diff) | |
download | adenosine-ae03334a64b1d7d6506ffb60a01f5c7f941900a6.tar.gz adenosine-ae03334a64b1d7d6506ffb60a01f5c7f941900a6.zip |
pds: partial clippy clean
Diffstat (limited to 'adenosine-pds/src/ucan_p256.rs')
-rw-r--r-- | adenosine-pds/src/ucan_p256.rs | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/adenosine-pds/src/ucan_p256.rs b/adenosine-pds/src/ucan_p256.rs index 21e8a9a..b8b6cd2 100644 --- a/adenosine-pds/src/ucan_p256.rs +++ b/adenosine-pds/src/ucan_p256.rs @@ -11,11 +11,6 @@ use ucan::crypto::KeyMaterial; pub use ucan::crypto::{did::P256_MAGIC_BYTES, JwtSignatureAlgorithm}; -pub fn bytes_to_p256_key(bytes: Vec<u8>) -> Result<Box<dyn KeyMaterial>> { - let public_key = P256PublicKey::try_from(bytes.as_slice())?; - Ok(Box::new(P256KeyMaterial(public_key, None))) -} - #[derive(Clone)] pub struct P256KeyMaterial(pub P256PublicKey, pub Option<P256PrivateKey>); @@ -27,11 +22,7 @@ impl KeyMaterial for P256KeyMaterial { } async fn get_did(&self) -> Result<String> { - let bytes = [ - P256_MAGIC_BYTES, - &self.0.to_encoded_point(true).to_bytes().to_vec(), - ] - .concat(); + let bytes = [P256_MAGIC_BYTES, &self.0.to_encoded_point(true).to_bytes()].concat(); Ok(format!("did:key:z{}", bs58::encode(bytes).into_string())) } @@ -55,8 +46,7 @@ impl KeyMaterial for P256KeyMaterial { #[cfg(test)] mod tests { - use super::{bytes_to_p256_key, P256KeyMaterial, P256_MAGIC_BYTES}; - use p256::ecdsa::signature::{Signer, Verifier}; + use super::{P256KeyMaterial, Result, P256_MAGIC_BYTES}; use p256::ecdsa::{SigningKey as P256PrivateKey, VerifyingKey as P256PublicKey}; use ucan::{ builder::UcanBuilder, @@ -64,6 +54,11 @@ mod tests { ucan::Ucan, }; + pub fn bytes_to_p256_key(bytes: Vec<u8>) -> Result<Box<dyn KeyMaterial>> { + let public_key = P256PublicKey::try_from(bytes.as_slice())?; + Ok(Box::new(P256KeyMaterial(public_key, None))) + } + #[cfg_attr(not(target_arch = "wasm32"), tokio::test)] async fn it_can_sign_and_verify_a_ucan() { let private_key = P256PrivateKey::random(&mut p256::elliptic_curve::rand_core::OsRng); |