pub fn decode_with_jwks<J>(
        &self,
        jwks: &JWKSet<J>,
        expected_algorithm: Option<SignatureAlgorithm>,
    ) -> Result<Self, Error> {
        match *self {
            Compact::Decoded { .. } => Err(Error::UnsupportedOperation),
            Compact::Encoded(ref encoded) => {
                if encoded.len() != 3 {
                    Err(DecodeError::PartsLengthError {
                        actual: encoded.len(),
                        expected: 3,
                    })?
                }

                let signature: Vec<u8> = encoded.part(2)?;
                let payload = &encoded.parts[0..2].join(".");

                let header: Header<H> = encoded.part(0)?;
                let key_id = header
                    .registered
                    .key_id
                    .as_ref()
                    .ok_or(ValidationError::KidMissing)?;
                let jwk = jwks.find(key_id).ok_or(ValidationError::KeyNotFound)?;

                let algorithm = match jwk.common.algorithm {
                    Some(jwk_alg) => {
                        let algorithm = match jwk_alg {
                            Algorithm::Signature(algorithm) => algorithm,
                            _ => Err(ValidationError::UnsupportedKeyAlgorithm)?,
                        };

                        if header.registered.algorithm != algorithm {
                            Err(ValidationError::WrongAlgorithmHeader)?;
                        }

                        if let Some(expected_algorithm) = expected_algorithm {
                            if expected_algorithm != algorithm {
                                Err(ValidationError::WrongAlgorithmHeader)?;
                            }
                        }

                        algorithm
                    }
                    None => match expected_algorithm {
                        Some(expected_algorithm) => {
                            if expected_algorithm != header.registered.algorithm {
                                Err(ValidationError::WrongAlgorithmHeader)?;
                            }
                            expected_algorithm
                        }
                        None => Err(ValidationError::MissingAlgorithm)?,
                    },
                };

                let secret = match &jwk.algorithm {
                    AlgorithmParameters::RSA(rsa) => rsa.jws_public_key_secret(),
                    AlgorithmParameters::OctetKey(oct) => Secret::Bytes(oct.value.clone()),
                    _ => Err(ValidationError::UnsupportedKeyAlgorithm)?,
                };

                algorithm
                    .verify(signature.as_ref(), payload.as_ref(), &secret)
                    .map_err(|_| ValidationError::InvalidSignature)?;

                let decoded_claims: T = encoded.part(1)?;

                Ok(Self::new_decoded(header, decoded_claims))
            }
        }
    }
/// Decode a token into the JWT struct and verify its signature using a JWKS
///
/// If the JWK does not contain an optional algorithm parameter, you will have to specify
/// the expected algorithm or an error will be returned.
///
/// If the JWK specifies an algorithm and you provide an expected algorithm,
/// both will be checked for equality. If they do not match, an error will be returned.
///
/// If the token or its signature is invalid, it will return an error
Decode a token into the JWT struct and verify its signature using a JWKS
If the JWK does not contain an optional algorithm parameter, you will have to specify
the expected algorithm or an error will be returned.

If the JWK specifies an algorithm and you provide an expected algorithm,
both will be checked for equality. If they do not match, an error will be returned.

If the token or its signature is invalid, it will return an error
Decode a token into the JWT struct and verify its signature using a JWKS If the JWK does not contain an optional algorithm parameter you will have to specify the expected algorithm or an error will be returned . If the JWK specifies an algorithm and you provide an expected algorithm both will be checked for equality . If they do not match an error will be returned . If the token or its signature is invalid it will return an error
pub fn decode_with_jwks<J>(
        &self,
        jwks: &JWKSet<J>,
        expected_algorithm: Option<SignatureAlgorithm>,
    ) -> Result<Self, Error> {
        match *self {
            Compact::Decoded { .. } => Err(Error::UnsupportedOperation),
            Compact::Encoded(ref encoded) => {
                if encoded.len() != 3 {
                    Err(DecodeError::PartsLengthError {
                        actual: encoded.len(),
                        expected: 3,
                    })?
                }
                let signature: Vec<u8> = encoded.part(2)?;
                let payload = &encoded.parts[0..2].join(".");
                let header: Header<H> = encoded.part(0)?;
                let key_id = header
                    .registered
                    .key_id
                    .as_ref()
                    .ok_or(ValidationError::KidMissing)?;
                let jwk = jwks.find(key_id).ok_or(ValidationError::KeyNotFound)?;
                let algorithm = match jwk.common.algorithm {
                    Some(jwk_alg) => {
                        let algorithm = match jwk_alg {
                            Algorithm::Signature(algorithm) => algorithm,
                            _ => Err(ValidationError::UnsupportedKeyAlgorithm)?,
                        };
                        if header.registered.algorithm != algorithm {
                            Err(ValidationError::WrongAlgorithmHeader)?;
                        }
                        if let Some(expected_algorithm) = expected_algorithm {
                            if expected_algorithm != algorithm {
                                Err(ValidationError::WrongAlgorithmHeader)?;
                            }
                        }
                        algorithm
                    }
                    None => match expected_algorithm {
                        Some(expected_algorithm) => {
                            if expected_algorithm != header.registered.algorithm {
                                Err(ValidationError::WrongAlgorithmHeader)?;
                            }
                            expected_algorithm
                        }
                        None => Err(ValidationError::MissingAlgorithm)?,
                    },
                };
                let secret = match &jwk.algorithm {
                    AlgorithmParameters::RSA(rsa) => rsa.jws_public_key_secret(),
                    AlgorithmParameters::OctetKey(oct) => Secret::Bytes(oct.value.clone()),
                    _ => Err(ValidationError::UnsupportedKeyAlgorithm)?,
                };
                algorithm
                    .verify(signature.as_ref(), payload.as_ref(), &secret)
                    .map_err(|_| ValidationError::InvalidSignature)?;
                let decoded_claims: T = encoded.part(1)?;
                Ok(Self::new_decoded(header, decoded_claims))
            }
        }
    }
pub fn decode_with_jwks < J > ( & self , jwks : & JWKSet < J > , expected_algorithm : Option < SignatureAlgorithm > , ) -> Result < Self , Error > { match * self { Compact :: Decoded { .. } => Err ( Error :: UnsupportedOperation ) , Compact :: Encoded ( ref encoded ) => { if encoded . len ( ) != 3 { Err ( DecodeError :: PartsLengthError { actual : encoded . len ( ) , expected : 3 , } ) ? } let signature : Vec < u8 > = encoded . part ( 2 ) ? ; let payload = & encoded . parts [ 0 .. 2 ] . join ( " " ) ; let header : Header < H > = encoded . part ( 0 ) ? ; let key_id = header . registered . key_id . as_ref ( ) . ok_or ( ValidationError :: KidMissing ) ? ; let jwk = jwks . find ( key_id ) . ok_or ( ValidationError :: KeyNotFound ) ? ; let algorithm = match jwk . common . algorithm { Some ( jwk_alg ) => { let algorithm = match jwk_alg { Algorithm :: Signature ( algorithm ) => algorithm , _ => Err ( ValidationError :: UnsupportedKeyAlgorithm ) ? , } ; if header . registered . algorithm != algorithm { Err ( ValidationError :: WrongAlgorithmHeader ) ? ; } if let Some ( expected_algorithm ) = expected_algorithm { if expected_algorithm != algorithm { Err ( ValidationError :: WrongAlgorithmHeader ) ? ; } } algorithm } None => match expected_algorithm { Some ( expected_algorithm ) => { if expected_algorithm != header . registered . algorithm { Err ( ValidationError :: WrongAlgorithmHeader ) ? ; } expected_algorithm } None => Err ( ValidationError :: MissingAlgorithm ) ? , } , } ; let secret = match & jwk . algorithm { AlgorithmParameters :: RSA ( rsa ) => rsa . jws_public_key_secret ( ) , AlgorithmParameters :: OctetKey ( oct ) => Secret :: Bytes ( oct . value . clone ( ) ) , _ => Err ( ValidationError :: UnsupportedKeyAlgorithm ) ? , } ; algorithm . verify ( signature . as_ref ( ) , payload . as_ref ( ) , & secret ) . map_err ( | _ | ValidationError :: InvalidSignature ) ? ; let decoded_claims : T = encoded . part ( 1 ) ? ; Ok ( Self :: new_decoded ( header , decoded_claims ) ) } } }
Decode a token into the JWT struct and verify its signature using a JWKS
If the JWK does not contain an optional algorithm parameter, you will have to specify
the expected algorithm or an error will be returned.
Decode a token into the JWT struct and verify its signature using a JWKS If the JWK does not contain an optional algorithm parameter you will have to specify the expected algorithm or an error will be returned .
&self
jwks
&JWKSet<J>
expected_algorithm
Option<SignatureAlgorithm>
&self
jwks
&JWKSet<J>
expected_algorithm
Option<SignatureAlgorithm>