From d1c439092ed12692e0537f2a5a5cb2235b1c681b Mon Sep 17 00:00:00 2001 From: kirahsapong <102400653+kirahsapong@users.noreply.github.com> Date: Fri, 3 May 2024 13:56:00 -0700 Subject: [PATCH] fix typo ed25199 to ed25519 (#154) --- crates/crypto/src/ed25519.rs | 30 +++++++++---------- crates/jws/src/lib.rs | 4 +-- crates/keys/src/key.rs | 18 +++++------ .../key_store/in_memory_key_store.rs | 4 +-- 4 files changed, 28 insertions(+), 28 deletions(-) diff --git a/crates/crypto/src/ed25519.rs b/crates/crypto/src/ed25519.rs index 97fe3ad4..19627a20 100644 --- a/crates/crypto/src/ed25519.rs +++ b/crates/crypto/src/ed25519.rs @@ -7,11 +7,11 @@ use ed25519_dalek::{ use jwk::Jwk; use rand::rngs::OsRng; -pub struct Ed25199; +pub struct Ed25519; -impl Ed25199 {} +impl Ed25519 {} -impl CurveOperations for Ed25199 { +impl CurveOperations for Ed25519 { fn generate() -> Result { let signing_key = SigningKey::generate(&mut OsRng {}); let verifying_key = signing_key.verifying_key(); @@ -78,7 +78,7 @@ mod tests { #[test] fn test_generate_keys() { - let jwk = Ed25199::generate().unwrap(); + let jwk = Ed25519::generate().unwrap(); assert_eq!(jwk.alg, "EdDSA"); assert_eq!(jwk.kty, "OKP"); assert_eq!(jwk.crv, "Ed25519"); @@ -95,43 +95,43 @@ mod tests { #[test] fn test_sign_and_verify() { - let jwk = Ed25199::generate().unwrap(); + let jwk = Ed25519::generate().unwrap(); let payload = b"test payload"; - let signature = Ed25199::sign(&jwk, payload).unwrap(); - assert!(Ed25199::verify(&jwk, payload, &signature).is_ok()); + let signature = Ed25519::sign(&jwk, payload).unwrap(); + assert!(Ed25519::verify(&jwk, payload, &signature).is_ok()); } #[test] fn test_sign_with_invalid_private_key_length() { - let mut jwk = Ed25199::generate().unwrap(); + let mut jwk = Ed25519::generate().unwrap(); let payload = b"another test payload"; // Alter the private key to an invalid length jwk.d = Some(general_purpose::URL_SAFE_NO_PAD.encode(&[0u8; 31])); // one byte short - assert!(Ed25199::sign(&jwk, payload).is_err()); + assert!(Ed25519::sign(&jwk, payload).is_err()); } #[test] fn test_verification_failure_with_invalid_public_key_length() { - let jwk = Ed25199::generate().unwrap(); + let jwk = Ed25519::generate().unwrap(); let payload = b"test payload again"; - let signature = Ed25199::sign(&jwk, payload).unwrap(); + let signature = Ed25519::sign(&jwk, payload).unwrap(); let mut jwk_modified = jwk.clone(); // Alter the public key to an invalid length jwk_modified.x = general_purpose::URL_SAFE_NO_PAD.encode(&[0u8; 31]); // one byte short - assert!(Ed25199::verify(&jwk_modified, payload, &signature).is_err()); + assert!(Ed25519::verify(&jwk_modified, payload, &signature).is_err()); } #[test] fn test_verification_failure_with_modified_signature() { - let jwk = Ed25199::generate().unwrap(); + let jwk = Ed25519::generate().unwrap(); let payload = b"yet another test payload"; - let mut signature = Ed25199::sign(&jwk, payload).unwrap(); + let mut signature = Ed25519::sign(&jwk, payload).unwrap(); // Introduce an error in the signature signature[0] ^= 0xff; - assert!(Ed25199::verify(&jwk, payload, &signature).is_err()); + assert!(Ed25519::verify(&jwk, payload, &signature).is_err()); } } diff --git a/crates/jws/src/lib.rs b/crates/jws/src/lib.rs index 447b9144..1a6a0e04 100644 --- a/crates/jws/src/lib.rs +++ b/crates/jws/src/lib.rs @@ -1,5 +1,5 @@ use base64::{engine::general_purpose, Engine as _}; -use crypto::{ed25519::Ed25199, secp256k1::Secp256k1, CryptoError, CurveOperations}; +use crypto::{ed25519::Ed25519, secp256k1::Secp256k1, CryptoError, CurveOperations}; use dids::{ bearer::{BearerDid, BearerDidError}, document::{DocumentError, KeyIdFragment, KeySelector}, @@ -137,7 +137,7 @@ pub async fn verify_compact_jws(compact_jws: &str) -> Result<(), JwsError> { .decode(&parts[2]) .map_err(|e| JwsError::DecodingError(e.to_string()))?; match alg.as_str() { - "EdDSA" => Ed25199::verify(&public_key, &to_verify.into_bytes(), &decoded_signature), + "EdDSA" => Ed25519::verify(&public_key, &to_verify.into_bytes(), &decoded_signature), "ES256K" => Secp256k1::verify(&public_key, &to_verify.into_bytes(), &decoded_signature), _ => return Err(JwsError::AlgorithmNotFound(alg)), }?; diff --git a/crates/keys/src/key.rs b/crates/keys/src/key.rs index a19582c0..dc8b4f0c 100644 --- a/crates/keys/src/key.rs +++ b/crates/keys/src/key.rs @@ -1,4 +1,4 @@ -use crypto::{ed25519::Ed25199, secp256k1::Secp256k1, CryptoError, CurveOperations}; +use crypto::{ed25519::Ed25519, secp256k1::Secp256k1, CryptoError, CurveOperations}; use jwk::{Jwk, JwkError}; use std::sync::Arc; @@ -50,7 +50,7 @@ impl Key for Jwk { impl PublicKey for Jwk { fn verify(&self, payload: &[u8], signature: &[u8]) -> Result<(), KeyError> { match self.crv.as_str() { - "Ed25519" => Ed25199::verify(self, payload, signature), + "Ed25519" => Ed25519::verify(self, payload, signature), "secp256k1" => Secp256k1::verify(self, payload, signature), _ => return Err(KeyError::CurveNotFound), }?; @@ -74,7 +74,7 @@ impl PrivateKey for Jwk { fn sign(&self, payload: &[u8]) -> Result, KeyError> { let signature = match self.crv.as_str() { - "Ed25519" => Ed25199::sign(self, payload), + "Ed25519" => Ed25519::sign(self, payload), "secp256k1" => Secp256k1::sign(self, payload), _ => return Err(KeyError::CurveNotFound), }?; @@ -84,13 +84,13 @@ impl PrivateKey for Jwk { #[cfg(test)] mod tests { - use crypto::{ed25519::Ed25199, CurveOperations}; + use crypto::{ed25519::Ed25519, CurveOperations}; use super::*; #[test] fn test_verify() { - let private_key = Ed25199::generate().unwrap(); + let private_key = Ed25519::generate().unwrap(); let payload = b"hello world"; let signature = private_key.sign(payload).unwrap(); @@ -100,12 +100,12 @@ mod tests { #[test] fn test_verify_failure() { - let private_key = Ed25199::generate().unwrap(); + let private_key = Ed25519::generate().unwrap(); let payload: &[u8] = b"hello world"; let signature = private_key.sign(payload).unwrap(); // public_key is unrelated to the private_key used to sign the payload, so it should fail - let private_key_2 = Ed25199::generate().unwrap(); + let private_key_2 = Ed25519::generate().unwrap(); let public_key = private_key_2.to_public().unwrap(); let verification_warnings = public_key.verify(payload, &signature); assert!(verification_warnings.is_err()); @@ -113,7 +113,7 @@ mod tests { #[test] fn test_to_public() { - let private_key = Ed25199::generate().unwrap(); + let private_key = Ed25519::generate().unwrap(); let public_key = private_key.to_public().unwrap().jwk().unwrap(); assert_eq!(private_key.x, public_key.x); @@ -125,7 +125,7 @@ mod tests { #[test] fn test_sign() { - let private_key = Ed25199::generate().unwrap(); + let private_key = Ed25519::generate().unwrap(); let payload: &[u8] = b"hello world"; let signature = private_key.sign(payload).unwrap(); diff --git a/crates/keys/src/key_manager/key_store/in_memory_key_store.rs b/crates/keys/src/key_manager/key_store/in_memory_key_store.rs index 4f465b29..059e4bf6 100644 --- a/crates/keys/src/key_manager/key_store/in_memory_key_store.rs +++ b/crates/keys/src/key_manager/key_store/in_memory_key_store.rs @@ -1,6 +1,6 @@ use crate::key::{PrivateKey, PublicKey}; use crate::key_manager::key_store::{KeyStore, KeyStoreError}; -use crypto::ed25519::Ed25199; +use crypto::ed25519::Ed25519; use crypto::secp256k1::Secp256k1; use crypto::{Curve, CurveOperations}; use std::collections::HashMap; @@ -25,7 +25,7 @@ impl KeyStore for InMemoryKeyStore { key_alias: Option, ) -> Result { let private_key = Arc::new(match curve { - Curve::Ed25519 => Ed25199::generate(), + Curve::Ed25519 => Ed25519::generate(), Curve::Secp256k1 => Secp256k1::generate(), }?); let key_alias = match key_alias {