pub(crate) fn validate_format_footer<'a>(
    header: &'a str,
    token: &'a str,
    footer: &[u8],
) -> Result<Vec<&'a str>, Error> {
    use orion::util::secure_cmp;

    if !token.starts_with(header) {
        return Err(Error::TokenFormat);
    }

    let parts_split = token.split('.').collect::<Vec<&str>>();
    if parts_split.len() < 3 || parts_split.len() > 4 {
        return Err(Error::TokenFormat);
    }

    let is_footer_present = parts_split.len() == 4;
    if !is_footer_present && !footer.is_empty() {
        return Err(Error::TokenValidation);
    }
    if is_footer_present {
        if footer.is_empty() {
            return Err(Error::TokenValidation);
        }

        let token_footer = decode_b64(parts_split[3])?;
        if secure_cmp(footer, token_footer.as_ref()).is_err() {
            return Err(Error::TokenValidation);
        }
    }

    Ok(parts_split)
}
/// Validate that a token begins with a given header.purpose and does not contain more than:
/// header.purpose.payload.footer
/// If a footer is present, this is validated against the supplied.
Validate that a token begins with a given header.purpose and does not contain more than:
header.purpose.payload.footer
If a footer is present, this is validated against the supplied.
Validate that a token begins with a given header . purpose and does not contain more than : header . purpose . payload . footer If a footer is present this is validated against the supplied .
pub(crate) fn validate_format_footer<'a>(
    header: &'a str,
    token: &'a str,
    footer: &[u8],
) -> Result<Vec<&'a str>, Error> {
    use orion::util::secure_cmp;
    if !token.starts_with(header) {
        return Err(Error::TokenFormat);
    }
    let parts_split = token.split('.').collect::<Vec<&str>>();
    if parts_split.len() < 3 || parts_split.len() > 4 {
        return Err(Error::TokenFormat);
    }
    let is_footer_present = parts_split.len() == 4;
    if !is_footer_present && !footer.is_empty() {
        return Err(Error::TokenValidation);
    }
    if is_footer_present {
        if footer.is_empty() {
            return Err(Error::TokenValidation);
        }
        let token_footer = decode_b64(parts_split[3])?;
        if secure_cmp(footer, token_footer.as_ref()).is_err() {
            return Err(Error::TokenValidation);
        }
    }
    Ok(parts_split)
}
pub ( crate ) fn validate_format_footer < ' a > ( header : & ' a str , token : & ' a str , footer : & [ u8 ] , ) -> Result < Vec < & ' a str > , Error > { use orion :: util :: secure_cmp ; if ! token . starts_with ( header ) { return Err ( Error :: TokenFormat ) ; } let parts_split = token . split ( '.' ) . collect :: < Vec < & str > > ( ) ; if parts_split . len ( ) < 3 || parts_split . len ( ) > 4 { return Err ( Error :: TokenFormat ) ; } let is_footer_present = parts_split . len ( ) == 4 ; if ! is_footer_present && ! footer . is_empty ( ) { return Err ( Error :: TokenValidation ) ; } if is_footer_present { if footer . is_empty ( ) { return Err ( Error :: TokenValidation ) ; } let token_footer = decode_b64 ( parts_split [ 3 ] ) ? ; if secure_cmp ( footer , token_footer . as_ref ( ) ) . is_err ( ) { return Err ( Error :: TokenValidation ) ; } } Ok ( parts_split ) }
Validate that a token begins with a given header.purpose and does not contain more than:
header.purpose.payload.footer
If a footer is present, this is validated against the supplied.
Validate that a token begins with a given header . purpose and does not contain more than : header . purpose . payload . footer If a footer is present this is validated against the supplied .
header
&'a str
token
&'a str
footer
&[u8]