pub fn decode_header(&self, input: impl AsRef<[u8]>) -> Result<Box<dyn JoseHeader>, JoseError> {
        (|| -> anyhow::Result<Box<dyn JoseHeader>> {
            let input = input.as_ref();
            let parts: Vec<&[u8]> = input.split(|b| *b == '.' as u8).collect();
            if parts.len() == 3 {
                // JWS
                let header = base64::decode_config(parts[0], base64::URL_SAFE_NO_PAD)?;
                let header: Map<String, Value> = serde_json::from_slice(&header)?;
                let header = JwsHeader::from_map(header)?;
                Ok(Box::new(header))
            } else if parts.len() == 5 {
                // JWE
                let header = base64::decode_config(parts[0], base64::URL_SAFE_NO_PAD)?;
                let header: Map<String, Value> = serde_json::from_slice(&header)?;
                let header = JweHeader::from_map(header)?;
                Ok(Box::new(header))
            } else {
                bail!("The input cannot be recognized as a JWT.");
            }
        })()
        .map_err(|err| match err.downcast::<JoseError>() {
            Ok(err) => err,
            Err(err) => JoseError::InvalidJwtFormat(err),
        })
    }
/// Return the Jose header decoded from JWT.
///
/// # Arguments
///
/// * `input` - a JWT string representation.
Return the Jose header decoded from JWT.
Return the Jose header decoded from JWT .
pub fn decode_header(&self, input: impl AsRef<[u8]>) -> Result<Box<dyn JoseHeader>, JoseError> {
        (|| -> anyhow::Result<Box<dyn JoseHeader>> {
            let input = input.as_ref();
            let parts: Vec<&[u8]> = input.split(|b| *b == '.' as u8).collect();
            if parts.len() == 3 {
                // JWS
                let header = base64::decode_config(parts[0], base64::URL_SAFE_NO_PAD)?;
                let header: Map<String, Value> = serde_json::from_slice(&header)?;
                let header = JwsHeader::from_map(header)?;
                Ok(Box::new(header))
            } else if parts.len() == 5 {
                // JWE
                let header = base64::decode_config(parts[0], base64::URL_SAFE_NO_PAD)?;
                let header: Map<String, Value> = serde_json::from_slice(&header)?;
                let header = JweHeader::from_map(header)?;
                Ok(Box::new(header))
            } else {
                bail!("The input cannot be recognized as a JWT.");
            }
        })()
        .map_err(|err| match err.downcast::<JoseError>() {
            Ok(err) => err,
            Err(err) => JoseError::InvalidJwtFormat(err),
        })
    }
pub fn decode_header ( & self , input : impl AsRef < [ u8 ] > ) -> Result < Box < dyn JoseHeader > , JoseError > { ( | | -> anyhow :: Result < Box < dyn JoseHeader > > { let input = input . as_ref ( ) ; let parts : Vec < & [ u8 ] > = input . split ( | b | * b == '.' as u8 ) . collect ( ) ; if parts . len ( ) == 3 { // JWS let header = base64 :: decode_config ( parts [ 0 ] , base64 :: URL_SAFE_NO_PAD ) ? ; let header : Map < String , Value > = serde_json :: from_slice ( & header ) ? ; let header = JwsHeader :: from_map ( header ) ? ; Ok ( Box :: new ( header ) ) } else if parts . len ( ) == 5 { // JWE let header = base64 :: decode_config ( parts [ 0 ] , base64 :: URL_SAFE_NO_PAD ) ? ; let header : Map < String , Value > = serde_json :: from_slice ( & header ) ? ; let header = JweHeader :: from_map ( header ) ? ; Ok ( Box :: new ( header ) ) } else { bail ! ( " " ) ; } } ) ( ) . map_err ( | err | match err . downcast :: < JoseError > ( ) { Ok ( err ) => err , Err ( err ) => JoseError :: InvalidJwtFormat ( err ) , } ) }
Return the Jose header decoded from JWT.
Return the Jose header decoded from JWT .
&self
input
impl AsRef<[u8]>
&self
input
impl AsRef<[u8]>