/// Parses a non-negative `INTEGER`.
///
/// We reject all integers with the sign bit set.
Parses a non-negative `INTEGER`.
We reject all integers with the sign bit set.
Parses a non - negative ` INTEGER ` . We reject all integers with the sign bit set .
pub fn uint<'cert>(
    buf: &mut untrusted::Reader<'cert>,
) -> Result<untrusted::Input<'cert>, Error> {
    let (tag, data) = any(buf)?;
    if tag != Tag::INTEGER {
        return Err(Error::BadEncoding);
    }
    data.read_all(Error::BadEncoding, |buf| {
        // `data` must be non-empty.
        let first = buf.read_byte()?;
        // `[0x00]` is the valid representation of `0`.
        if first == 0 && buf.at_end() {
            return Ok(());
        }
        // Check the sign bit; negative values are forbidden.
        if first & 0x80 != 0 {
            return Err(Error::BadEncoding);
        }
        // A leading zero is only permitted if the byte that
        // follows has a high bit set, to disambiguate
        // `-128 == [0x80]` from `128 == [0x00, 0x80]`.
        if first == 0 && buf.read_byte()? & 0x80 == 0 {
            return Err(Error::BadEncoding);
        }
        buf.skip_to_end();
        Ok(())
    })?;
    Ok(data)
}
pub fn uint < ' cert > ( buf : & mut untrusted :: Reader < ' cert > , ) -> Result < untrusted :: Input < ' cert > , Error > { let ( tag , data ) = any ( buf ) ? ; if tag != Tag :: INTEGER { return Err ( Error :: BadEncoding ) ; } data . read_all ( Error :: BadEncoding , | buf | { // `data` must be non-empty. let first = buf . read_byte ( ) ? ; // `[0x00]` is the valid representation of `0`. if first == 0 && buf . at_end ( ) { return Ok ( ( ) ) ; } // Check the sign bit; negative values are forbidden. if first & 0x80 != 0 { return Err ( Error :: BadEncoding ) ; } // A leading zero is only permitted if the byte that // follows has a high bit set, to disambiguate // `-128 == [0x80]` from `128 == [0x00, 0x80]`. if first == 0 && buf . read_byte ( ) ? & 0x80 == 0 { return Err ( Error :: BadEncoding ) ; } buf . skip_to_end ( ) ; Ok ( ( ) ) } ) ? ; Ok ( data ) }
Parses a non-negative `INTEGER`.
Parses a non - negative ` INTEGER ` .
buf
&mut untrusted::Reader<'cert>