From 4a79e9a2c7cd85c0ec2ed91fda471f270fe00c52 Mon Sep 17 00:00:00 2001 From: Ben Boeckel Date: Tue, 18 Nov 2025 12:36:44 -0500 Subject: [PATCH] algorithms: expose `AlgorithmFamily` It is available on `DecodingKey`. Since `Validation` ends up masking out keys based on a single family, allow crates to create a list of supported algorithms based on the family in use. See: #297 --- src/algorithms.rs | 3 ++- src/lib.rs | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/algorithms.rs b/src/algorithms.rs index 94eb3637..36459d2a 100644 --- a/src/algorithms.rs +++ b/src/algorithms.rs @@ -4,6 +4,7 @@ use serde::{Deserialize, Serialize}; use crate::errors::{Error, ErrorKind, Result}; +/// Supported families of algorithms. #[derive(Debug, Eq, PartialEq, Copy, Clone, Serialize, Deserialize)] pub enum AlgorithmFamily { Hmac, @@ -88,7 +89,7 @@ impl FromStr for Algorithm { } impl Algorithm { - pub(crate) fn family(self) -> AlgorithmFamily { + pub fn family(self) -> AlgorithmFamily { match self { Algorithm::HS256 | Algorithm::HS384 | Algorithm::HS512 => AlgorithmFamily::Hmac, Algorithm::RS256 diff --git a/src/lib.rs b/src/lib.rs index 920b996b..b15c62dc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,7 +13,7 @@ compile_error!( #[cfg(not(any(feature = "rust_crypto", feature = "aws_lc_rs")))] compile_error!("at least one of the features \"rust_crypto\" or \"aws_lc_rs\" must be enabled"); -pub use algorithms::Algorithm; +pub use algorithms::{Algorithm, AlgorithmFamily}; pub use decoding::{DecodingKey, TokenData, decode, decode_header}; pub use encoding::{EncodingKey, encode}; pub use header::Header;