Skip to content

Commit 4639024

Browse files
committed
Add unimplemented ES256K algorithm for aws_lc_rs
1 parent bcb6d41 commit 4639024

4 files changed

Lines changed: 55 additions & 4 deletions

File tree

src/crypto/aws_lc/ecdsa.rs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,59 @@ macro_rules! define_ecdsa_verifier {
7676
};
7777
}
7878

79+
macro_rules! define_ecdsa_signer_not_implemented {
80+
($name:ident, $alg:expr) => {
81+
pub struct $name;
82+
83+
impl $name {
84+
pub(crate) fn new(_encoding_key: &EncodingKey) -> Result<Self> {
85+
return Err(new_error(ErrorKind::InvalidKeyFormat));
86+
}
87+
}
88+
89+
impl Signer<Vec<u8>> for $name {
90+
fn try_sign(&self, _msg: &[u8]) -> std::result::Result<Vec<u8>, Error> {
91+
return Err(Error::from_source(new_error(ErrorKind::InvalidKeyFormat)));
92+
}
93+
}
94+
95+
impl JwtSigner for $name {
96+
fn algorithm(&self) -> Algorithm {
97+
$alg
98+
}
99+
}
100+
}
101+
}
102+
103+
macro_rules! define_ecdsa_verifier_not_implemented {
104+
($name:ident, $alg:expr) => {
105+
pub struct $name;
106+
107+
impl $name {
108+
pub(crate) fn new(_decoding_key: &DecodingKey) -> Result<Self> {
109+
return Err(new_error(ErrorKind::InvalidKeyFormat));
110+
}
111+
}
112+
113+
impl Verifier<Vec<u8>> for $name {
114+
fn verify(&self, _msg: &[u8], _signature: &Vec<u8>) -> std::result::Result<(), Error> {
115+
return Err(Error::from_source(new_error(ErrorKind::InvalidKeyFormat)));
116+
}
117+
}
118+
119+
impl JwtVerifier for $name {
120+
fn algorithm(&self) -> Algorithm {
121+
$alg
122+
}
123+
}
124+
};
125+
}
126+
79127
define_ecdsa_signer!(Es256Signer, Algorithm::ES256, &ECDSA_P256_SHA256_FIXED_SIGNING);
80128
define_ecdsa_verifier!(Es256Verifier, Algorithm::ES256, ECDSA_P256_SHA256_FIXED);
81129

82130
define_ecdsa_signer!(Es384Signer, Algorithm::ES384, &ECDSA_P384_SHA384_FIXED_SIGNING);
83131
define_ecdsa_verifier!(Es384Verifier, Algorithm::ES384, ECDSA_P384_SHA384_FIXED);
132+
133+
define_ecdsa_signer_not_implemented!(Es256KSigner, Algorithm::ES256K);
134+
define_ecdsa_verifier_not_implemented!(Es256KVerifier, Algorithm::ES256K);

src/decoding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ use crate::validation::{Validation, validate};
1616
// Crypto
1717
#[cfg(feature = "aws_lc_rs")]
1818
use crate::crypto::aws_lc::{
19-
ecdsa::{Es256Verifier, Es384Verifier},
19+
ecdsa::{Es256Verifier, Es384Verifier, Es256KVerifier},
2020
eddsa::EdDSAVerifier,
2121
hmac::{Hs256Verifier, Hs384Verifier, Hs512Verifier},
2222
rsa::{

src/encoding.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use crate::serialization::{b64_encode, b64_encode_part};
1717
// Crypto
1818
#[cfg(feature = "aws_lc_rs")]
1919
use crate::crypto::aws_lc::{
20-
ecdsa::{Es256Signer, Es384Signer},
20+
ecdsa::{Es256Signer, Es384Signer, Es256KSigner},
2121
eddsa::EdDSASigner,
2222
hmac::{Hs256Signer, Hs384Signer, Hs512Signer},
2323
rsa::{

tests/ecdsa/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ fn ec_x_y() {
103103
assert!(res.is_ok());
104104
}
105105

106-
#[cfg(feature = "use_pem")]
106+
#[cfg(all(feature = "use_pem", feature = "rust_crypto"))]
107107
#[test]
108108
#[wasm_bindgen_test]
109109
fn es256k_pem() {
@@ -131,7 +131,7 @@ fn es256k_pem() {
131131
assert!(res.is_ok());
132132
}
133133

134-
#[cfg(feature = "use_pem")]
134+
#[cfg(all(feature = "use_pem", feature = "rust_crypto"))]
135135
#[test]
136136
#[wasm_bindgen_test]
137137
fn es256k_jwk() {

0 commit comments

Comments
 (0)