pub fn pkcs7validate(b: &[u8]) -> Result<Vec<u8>, crate::Error> {
    let padding = b[b.len() - 1];

    if padding == 0 {
        return Err(crate::Error::InvalidPKCS7);
    }

    if padding as usize > b.len() {
        return Err(crate::Error::InvalidPKCS7);
    }

    for i in 1..padding as usize {
        if b[b.len() - 1 - i] != padding {
            return Err(crate::Error::InvalidPKCS7);
        }
    }

    Ok(Vec::from(&b[..b.len() - padding as usize]))
}
/// PKCS#7 padding validation
///
/// Solution for problem 7 from set 2: <https://cryptopals.com/sets/2/challenges/15>
PKCS#7 padding validation
Solution for problem 7 from set 2.
PKCS#7 padding validation Solution for problem 7 from set 2 .
pub fn pkcs7validate(b: &[u8]) -> Result<Vec<u8>, crate::Error> {
    let padding = b[b.len() - 1];
    if padding == 0 {
        return Err(crate::Error::InvalidPKCS7);
    }
    if padding as usize > b.len() {
        return Err(crate::Error::InvalidPKCS7);
    }
    for i in 1..padding as usize {
        if b[b.len() - 1 - i] != padding {
            return Err(crate::Error::InvalidPKCS7);
        }
    }
    Ok(Vec::from(&b[..b.len() - padding as usize]))
}
pub fn pkcs7validate ( b : & [ u8 ] ) -> Result < Vec < u8 > , crate :: Error > { let padding = b [ b . len ( ) - 1 ] ; if padding == 0 { return Err ( crate :: Error :: InvalidPKCS7 ) ; } if padding as usize > b . len ( ) { return Err ( crate :: Error :: InvalidPKCS7 ) ; } for i in 1 .. padding as usize { if b [ b . len ( ) - 1 - i ] != padding { return Err ( crate :: Error :: InvalidPKCS7 ) ; } } Ok ( Vec :: from ( & b [ .. b . len ( ) - padding as usize ] ) ) }
PKCS#7 padding validation
Solution for problem 7 from set 2: <https://cryptopals.com/sets/2/challenges/15>
PKCS#7 padding validation Solution for problem 7 from set 2 : <https : // cryptopals . com / sets / 2 / challenges / 15 >
b
&[u8]