Struct bsn1::BerRef [−][src]
pub struct BerRef { /* fields omitted */ }Expand description
BerRef is a wrapper of [u8] and represents a BER.
This struct is ‘Unsized’, and user usually uses a reference to the instance.
Implementations
Provides a reference from bytes without any sanitization.
bytes must be BER octets and must not include any extra octet.
If it is sure that bytes starts with BER octets, but if some extra octet(s) may added
after that, use from_bytes_starts_with_unchecked instead.
If it is not sure whether bytes starts with BER octets or not, use TryFrom
implementation.
Safety
The behavior is undefined if bytes is not formatted as a BER.
Examples
use bsn1::{Ber, BerRef, IdRef};
let id = IdRef::octet_string();
let ber = Ber::new(id, &[]);
let bytes: &[u8] = ber.as_ref();
let deserialized = unsafe { BerRef::from_bytes_unchecked(bytes) };
assert_eq!(ber.as_ref() as &BerRef, deserialized);Provides a reference from bytes that starts with a BER octets.
bytes may include some extra octet(s) at the end.
If it is not sure whether bytes starts with BER octets or not, use TryFrom
implementation.
Safety
The behavior is undefined if bytes does not start with BER octets.
Examples
use bsn1::{Ber, BerRef, IdRef};
let id = IdRef::octet_string();
let ber = Ber::new(id, &[]);
let mut bytes = Vec::from(ber.as_ref() as &[u8]);
bytes.extend(&[1, 2, 3]);
let deserialized = unsafe { BerRef::from_bytes_starts_with_unchecked(bytes.as_ref()) };
assert_eq!(ber.as_ref() as &BerRef, deserialized);Provides a reference to IdRef of self .
Examples
use bsn1::{Ber, BerRef, IdRef};
let id = IdRef::octet_string();
let contents = &[1, 2, 3];
// 'Ber' implements 'Deref<Target=BerRef>.'
let ber = Ber::new(id, contents);
assert_eq!(id, ber.id());Returns Length of self .
Warnings
Length stands for ‘the length octets of the contents’ in BER.
The total bytes is greater than the value.
Examples
use bsn1::{Ber, BerRef, IdRef, Length};
let id = IdRef::octet_string();
let contents = &[1, 2, 3];
// 'Ber' implements 'Deref<Target=BerRef>.'
let ber = Ber::new(id, contents);
assert_eq!(Length::Definite(contents.len()), ber.length());Provides a reference to the ‘contents’ octets of self .
Examples
use bsn1::{Ber, BerRef, IdRef};
let id = IdRef::octet_string();
let contents = &[1, 2, 3];
// 'Ber' implements 'Deref<Target=BerRef>.'
let ber = Ber::new(id, contents);
assert_eq!(contents, ber.contents());