use super::{
take_n,
tlf::{Ty, TypeLengthField},
ResTy, SmlParseTlf,
};
pub type OctetStr<'i> = &'i [u8];
impl<'i> SmlParseTlf<'i> for OctetStr<'i> {
fn check_tlf(tlf: &TypeLengthField) -> bool {
matches!(tlf.ty, Ty::OctetString)
}
fn parse_with_tlf(input: &'i [u8], tlf: &TypeLengthField) -> ResTy<'i, Self> {
take_n(input, tlf.len as usize)
}
}
#[cfg(test)]
mod test {
use super::*;
use crate::parser::SmlParse;
use hex_literal::hex;
#[test]
fn test_octet_str() {
assert_eq!(
OctetStr::parse_complete(&hex!("0648656C6C6F")).expect("Decode Error"),
&b"Hello"[..]
);
assert_eq!(
<&[u8]>::parse_complete(b"\x81\x0Cqwertzuiopasdfghjklyxcvbnm").expect("Decode Error"),
&b"qwertzuiopasdfghjklyxcvbnm"[..]
);
assert_eq!(
Option::<&[u8]>::parse_complete(b"\x01").expect("Decode Error"),
None
);
}
}