Skip to content

Commit

Permalink
Improve instantiate_algorithm function.
Browse files Browse the repository at this point in the history
  • Loading branch information
timothee-haudebourg committed Aug 9, 2024
1 parent 862f089 commit ac43fed
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/claims/crates/cose/src/algorithm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,27 @@ use crate::key::{CoseKeyDecode, EC2_CRV};
/// Converts a COSE algorithm into an SSI algorithm instance.
pub fn instantiate_algorithm(algorithm: &Algorithm) -> Option<AlgorithmInstance> {
match algorithm {
Algorithm::Assigned(iana::Algorithm::PS256) => Some(AlgorithmInstance::PS256),
Algorithm::Assigned(iana::Algorithm::PS384) => Some(AlgorithmInstance::PS384),
Algorithm::Assigned(iana::Algorithm::PS512) => Some(AlgorithmInstance::PS512),
Algorithm::Assigned(iana::Algorithm::EdDSA) => Some(AlgorithmInstance::EdDSA),
Algorithm::Assigned(iana::Algorithm::ES256K) => Some(AlgorithmInstance::ES256K),
Algorithm::Assigned(iana::Algorithm::ES256) => Some(AlgorithmInstance::ES256),
Algorithm::Assigned(iana::Algorithm::ES384) => Some(AlgorithmInstance::ES384),
_ => None,
}
}

/// Computes a proper display name for the give COSE algorithm.
pub fn algorithm_name(algorithm: &Algorithm) -> String {
match algorithm {
Algorithm::Assigned(iana::Algorithm::PS256) => "PS256".to_owned(),
Algorithm::Assigned(iana::Algorithm::PS384) => "PS384".to_owned(),
Algorithm::Assigned(iana::Algorithm::PS512) => "PS512".to_owned(),
Algorithm::Assigned(iana::Algorithm::EdDSA) => "EdDSA".to_owned(),
Algorithm::Assigned(iana::Algorithm::ES256K) => "ES256K".to_owned(),
Algorithm::Assigned(iana::Algorithm::ES256) => "ES256".to_owned(),
Algorithm::Assigned(iana::Algorithm::ES384) => "ES384".to_owned(),
Algorithm::Assigned(i) => format!("assigned({})", i.to_i64()),
Algorithm::PrivateUse(i) => format!("private_use({i})"),
Algorithm::Text(text) => text.to_owned(),
Expand Down

0 comments on commit ac43fed

Please sign in to comment.