Skip to content

Commit 4afccae

Browse files
committed
Add unknown alg for jwk
From #400 by @ThatNerdUKnow
1 parent 08a15f3 commit 4afccae

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/jwk.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ pub enum KeyAlgorithm {
190190
/// RSAES-OAEP-256 using SHA-2
191191
#[serde(rename = "RSA-OAEP-256")]
192192
RSA_OAEP_256,
193+
194+
/// Catch-All for when the key algorithm can not be determined or is not supported
195+
#[serde(other)]
196+
UNKNOWN_ALGORITHM,
193197
}
194198

195199
impl FromStr for KeyAlgorithm {
@@ -443,7 +447,7 @@ mod tests {
443447
use serde_json::json;
444448
use wasm_bindgen_test::wasm_bindgen_test;
445449

446-
use crate::jwk::{AlgorithmParameters, JwkSet, OctetKeyType};
450+
use crate::jwk::{AlgorithmParameters, JwkSet, KeyAlgorithm, OctetKeyType};
447451
use crate::serialization::b64_encode;
448452
use crate::Algorithm;
449453

@@ -477,4 +481,12 @@ mod tests {
477481
_ => panic!("Unexpected key algorithm"),
478482
}
479483
}
484+
485+
#[test]
486+
fn deserialize_unknown_key_algorithm() {
487+
let key_alg_json = json!("");
488+
let key_alg_result: KeyAlgorithm =
489+
serde_json::from_value(key_alg_json).expect("Could not deserialize json");
490+
assert_eq!(key_alg_result, KeyAlgorithm::UNKNOWN_ALGORITHM);
491+
}
480492
}

0 commit comments

Comments
 (0)