[−][src]Function bsn1::try_length_from
pub fn try_length_from(bytes: &[u8]) -> Result<(Length, &[u8]), Error>
Tries to parse bytes starting with 'length' and returns Length .
This function ignores extra octets at the end of bytes .
Warnings
This function may return Ok(Length::Indefinite) , however, 'DER' and 'CER' don't allow such
value.
It does not always mean bytes is valid that this function returns Ok .
Examples
use bsn1::{length_to_bytes, try_length_from, Length}; let length = Length::Definite(3); let bytes = length_to_bytes(&length); let deserialized = try_length_from(bytes.as_ref()).unwrap(); assert_eq!(length, deserialized.0);