pub fn decode(&self, secret: &Secret, algorithm: 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(".");

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

                let header: Header<H> = encoded.part(0)?;
                if header.registered.algorithm != algorithm {
                    Err(ValidationError::WrongAlgorithmHeader)?;
                }
                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 the concrete Secret
/// 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 the concrete Secret
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 the concrete Secret If the token or its signature is invalid it will return an error
pub fn decode(&self, secret: &Secret, algorithm: 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(".");
                algorithm
                    .verify(signature.as_ref(), payload.as_ref(), secret)
                    .map_err(|_| ValidationError::InvalidSignature)?;
                let header: Header<H> = encoded.part(0)?;
                if header.registered.algorithm != algorithm {
                    Err(ValidationError::WrongAlgorithmHeader)?;
                }
                let decoded_claims: T = encoded.part(1)?;
                Ok(Self::new_decoded(header, decoded_claims))
            }
        }
    }
pub fn decode ( & self , secret : & Secret , algorithm : 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 ( " " ) ; algorithm . verify ( signature . as_ref ( ) , payload . as_ref ( ) , secret ) . map_err ( | _ | ValidationError :: InvalidSignature ) ? ; let header : Header < H > = encoded . part ( 0 ) ? ; if header . registered . algorithm != algorithm { Err ( ValidationError :: WrongAlgorithmHeader ) ? ; } 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 the concrete Secret
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 the concrete Secret If the token or its signature is invalid it will return an error
&self
secret
&Secret
algorithm
SignatureAlgorithm
&self
secret
&Secret
algorithm
SignatureAlgorithm