Skip to content

Commit 26ede7f

Browse files
committed
validation: support constructing for a family of algorithms
1 parent 42e5702 commit 26ede7f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

src/validation.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::marker::PhantomData;
66
use serde::de::{self, Visitor};
77
use serde::{Deserialize, Deserializer};
88

9-
use crate::algorithms::Algorithm;
9+
use crate::algorithms::{Algorithm, AlgorithmFamily};
1010
use crate::errors::{ErrorKind, Result, new_error};
1111

1212
/// Contains the various validations that are applied after decoding a JWT.
@@ -111,12 +111,21 @@ pub struct Validation {
111111
impl Validation {
112112
/// Create a default validation setup allowing the given alg
113113
pub fn new(alg: Algorithm) -> Validation {
114+
Self::new_impl(vec![alg])
115+
}
116+
117+
/// Create a default validation setup allowing any algorithm in the family
118+
pub fn new_for_family(family: AlgorithmFamily) -> Validation {
119+
Self::new_impl(family.algorithms().into_iter().copied().collect())
120+
}
121+
122+
fn new_impl(algorithms: Vec<Algorithm>) -> Validation {
114123
let mut required_claims = HashSet::with_capacity(1);
115124
required_claims.insert("exp".to_owned());
116125

117126
Validation {
118127
required_spec_claims: required_claims,
119-
algorithms: vec![alg],
128+
algorithms,
120129
leeway: 60,
121130
reject_tokens_expiring_in_less_than: 0,
122131

0 commit comments

Comments
 (0)