Skip to content

Commit

Permalink
add unknown variant and test
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Piña committed Aug 20, 2024
1 parent c733c78 commit 6c60efa
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/jwk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ pub enum KeyAlgorithm {
/// RSAES-OAEP-256 using SHA-2
#[serde(rename = "RSA-OAEP-256")]
RSA_OAEP_256,

/// Catch-All for when the key algorithm can not be determined
#[serde(other)]
UNKNOWN_ALGORITHM
}

impl FromStr for KeyAlgorithm {
Expand Down Expand Up @@ -435,7 +439,7 @@ impl JwkSet {

#[cfg(test)]
mod tests {
use crate::jwk::{AlgorithmParameters, JwkSet, OctetKeyType};
use crate::jwk::{AlgorithmParameters, JwkSet, KeyAlgorithm, OctetKeyType};
use crate::serialization::b64_encode;
use crate::Algorithm;
use serde_json::json;
Expand Down Expand Up @@ -471,4 +475,11 @@ mod tests {
_ => panic!("Unexpected key algorithm"),
}
}

#[test]
fn deserialize_unknown_key_algorithm(){
let key_alg_json = json!("");
let key_alg_result: KeyAlgorithm = serde_json::from_value(key_alg_json).expect("Could not deserialize json");
assert_eq!(key_alg_result,KeyAlgorithm::UNKNOWN_ALGORITHM);
}
}

0 comments on commit 6c60efa

Please sign in to comment.