Skip to content

Commit c3ca386

Browse files
authored
Make family public (#351)
* Made algorithm family public * made family public * Added src doc for alorightms on family
1 parent 8b8fc1f commit c3ca386

File tree

3 files changed

+33
-1
lines changed

3 files changed

+33
-1
lines changed

src/algorithms.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,35 @@ use serde::{Deserialize, Serialize};
55
use crate::errors::{Error, ErrorKind, Result};
66

77
#[derive(Debug, Eq, PartialEq, Copy, Clone, Serialize, Deserialize)]
8-
pub(crate) enum AlgorithmFamily {
8+
pub enum AlgorithmFamily {
99
Hmac,
1010
Rsa,
1111
Ec,
1212
Ed,
1313
}
1414

15+
impl AlgorithmFamily {
16+
/// A list of all possible Algorithms that are part of the family.
17+
pub fn algorithms(&self) -> &[Algorithm] {
18+
match self {
19+
Self::Hmac => &[Algorithm::HS256, Algorithm::HS384, Algorithm::HS512],
20+
Self::Rsa => &[
21+
Algorithm::RS256,
22+
Algorithm::RS384,
23+
Algorithm::RS512,
24+
Algorithm::PS256,
25+
Algorithm::PS384,
26+
Algorithm::PS384,
27+
Algorithm::PS512,
28+
],
29+
Self::Ec => &[Algorithm::ES256, Algorithm::ES384],
30+
Self::Ed => &[Algorithm::EdDSA],
31+
}
32+
}
33+
}
34+
35+
36+
1537
/// The algorithms supported for signing/verifying JWTs
1638
#[allow(clippy::upper_case_acronyms)]
1739
#[derive(Debug, Default, PartialEq, Eq, Hash, Copy, Clone, Serialize, Deserialize)]

src/decoding.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ pub struct DecodingKey {
9393
}
9494

9595
impl DecodingKey {
96+
/// The algorithm family this key is for.
97+
pub fn family(&self) -> AlgorithmFamily {
98+
self.family
99+
}
100+
96101
/// If you're using HMAC, use this.
97102
pub fn from_secret(secret: &[u8]) -> Self {
98103
DecodingKey {

src/encoding.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ pub struct EncodingKey {
4040
}
4141

4242
impl EncodingKey {
43+
/// The algorithm family this key is for.
44+
pub fn family(&self) -> AlgorithmFamily {
45+
self.family
46+
}
47+
4348
/// If you're using a HMAC secret that is not base64, use that.
4449
pub fn from_secret(secret: &[u8]) -> Self {
4550
EncodingKey { family: AlgorithmFamily::Hmac, content: secret.to_vec() }

0 commit comments

Comments
 (0)