Struct bsn1::DerRef [−][src]
pub struct DerRef { /* fields omitted */ }Expand description
DerRef is a wrapper of [u8] and represents DER.
This struct is ‘Unsized’, and user usually uses a reference to the instance.
Implementations
Provides a reference from bytes without any sanitization.
bytes must not include any extra octet.
If it is sure that bytes starts with DER 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 DER octets or not, use TryFrom
implementation.
Safety
The behavior is undefined if bytes is not formatted as a DER.
Examples
use bsn1::{Der, DerRef, IdRef};
let der = Der::new(IdRef::octet_string(), &[]);
let der_ref = unsafe { DerRef::from_bytes_unchecked(der.as_ref()) };
assert_eq!(der.as_ref() as &DerRef, der_ref);Provides a reference from bytes that starts with a DER.
bytes may include some extra octet(s) at the end.
If it is not sure whether bytes starts with DER octets or not, use TryFrom
implementation.
Safety
The behavior is undefined if bytes does not start with ‘ASN.1 DER’ octets.
Examples
use bsn1::{Der, DerRef, IdRef};
let der = Der::new(IdRef::octet_string(), &[]);
let mut bytes = Vec::from(der.as_ref() as &[u8]);
bytes.extend(&[1, 2, 3]);
let der_ref = unsafe { DerRef::from_bytes_starts_with_unchecked(bytes.as_ref()) };
assert_eq!(der.as_ref() as &DerRef, der_ref);Returns a reference to IdRef of self .
Examples
use bsn1::{Der, IdRef};
let id = IdRef::octet_string();
let contents = &[1, 2, 3];
// 'DER' implements 'Deref<Target=DerRef>'
let der = Der::new(id, contents);
assert_eq!(id, der.id());Returns Length to represent the length of contents.
Note that DER does not allow indefinite Length.
The return value must be Length::Definite .
Warnings
Length stands for the length octets in DER.
The total bytes is greater than the value.
Examples
use bsn1::{Der, IdRef, Length};
let id = IdRef::octet_string();
let contents = &[1, 2, 3];
// 'DER' implements 'Deref<Target=DerRef>'
let der = Der::new(id, contents);
assert_eq!(Length::Definite(contents.len()), der.length());Returns a reference to the contents octets of self .
Examples
use bsn1::{Der, IdRef};
let id = IdRef::octet_string();
let contents = &[1, 2, 3];
// 'DER' implements 'Deref<Target=DerRef>'
let der = Der::new(id, contents);
assert_eq!(contents, der.contents());Trait Implementations
Parses bytes starting with octets of ‘ASN.1 DER’ and returns a reference to DerRef .
This function ignores extra octet(s) at the end of bytes if any.
Warnings
ASN.1 does not allow some universal identifier for DER, however, this function will accept
such an identifier.
For example, ‘Octet String’ must be primitive in DER, but this function returns Ok for
constructed Octet String DER.