Skip to content

Commit 42e5702

Browse files
committed
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
1 parent 53a3fc2 commit 42e5702

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/algorithms.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,16 @@ use serde::{Deserialize, Serialize};
44

55
use crate::errors::{Error, ErrorKind, Result};
66

7+
/// Supported families of algorithms.
78
#[derive(Debug, Eq, PartialEq, Copy, Clone, Serialize, Deserialize)]
89
pub enum AlgorithmFamily {
10+
/// HMAC shared secret family.
911
Hmac,
12+
/// RSA-based public key family.
1013
Rsa,
14+
/// Edwards curve public key family.
1115
Ec,
16+
/// Elliptic curve public key family.
1217
Ed,
1318
}
1419

@@ -88,7 +93,8 @@ impl FromStr for Algorithm {
8893
}
8994

9095
impl Algorithm {
91-
pub(crate) fn family(self) -> AlgorithmFamily {
96+
/// The family of the algorithm.
97+
pub fn family(self) -> AlgorithmFamily {
9298
match self {
9399
Algorithm::HS256 | Algorithm::HS384 | Algorithm::HS512 => AlgorithmFamily::Hmac,
94100
Algorithm::RS256

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ compile_error!(
1313
#[cfg(not(any(feature = "rust_crypto", feature = "aws_lc_rs")))]
1414
compile_error!("at least one of the features \"rust_crypto\" or \"aws_lc_rs\" must be enabled");
1515

16-
pub use algorithms::Algorithm;
16+
pub use algorithms::{Algorithm, AlgorithmFamily};
1717
pub use decoding::{DecodingKey, TokenData, decode, decode_header};
1818
pub use encoding::{EncodingKey, encode};
1919
pub use header::Header;

0 commit comments

Comments
 (0)