File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed
Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -6,7 +6,7 @@ use std::marker::PhantomData;
66use serde:: de:: { self , Visitor } ;
77use serde:: { Deserialize , Deserializer } ;
88
9- use crate :: algorithms:: Algorithm ;
9+ use crate :: algorithms:: { Algorithm , AlgorithmFamily } ;
1010use 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 {
111111impl 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
You can’t perform that action at this time.
0 commit comments