rocket::mtls::x509::ber

Function parse_ber_integer

Source
pub fn parse_ber_integer(i: &[u8]) -> Result<(&[u8], BerObject<'_>), Err<Error>>
Available on crate feature mtls only.
Expand description

Read an integer value

The encoding of a boolean value shall be primitive. The contents octets shall consist of one or more octets.

To access the content, use the as_u64, as_u32, as_biguint or as_bigint methods. Remember that a BER integer has unlimited size, so these methods return Result or Option objects.

ยงExamples

let empty = &b""[..];
let bytes = [0x02, 0x03, 0x01, 0x00, 0x01];
let expected  = BerObject::from_obj(BerObjectContent::Integer(b"\x01\x00\x01"));
assert_eq!(
    parse_ber_integer(&bytes),
    Ok((empty, expected))
);