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
impl DerRef
[src]
impl DerRef
[src]pub unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &Self
[src]
pub unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &Self
[src]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);
pub unsafe fn from_bytes_starts_with_unchecked(bytes: &[u8]) -> &Self
[src]
pub unsafe fn from_bytes_starts_with_unchecked(bytes: &[u8]) -> &Self
[src]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);
impl DerRef
[src]
impl DerRef
[src]pub fn id(&self) -> &IdRef
[src]
pub fn id(&self) -> &IdRef
[src]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());
pub fn length(&self) -> Length
[src]
pub fn length(&self) -> Length
[src]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());
Trait Implementations
impl ToOwned for DerRef
[src]
impl ToOwned for DerRef
[src]fn to_owned(&self) -> Self::Owned
[src]
fn to_owned(&self) -> Self::Owned
[src]Creates owned data from borrowed data, usually by cloning. Read more
fn clone_into(&self, target: &mut Self::Owned)
[src]
fn clone_into(&self, target: &mut Self::Owned)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<'a> TryFrom<&'a [u8]> for &'a DerRef
[src]
impl<'a> TryFrom<&'a [u8]> for &'a DerRef
[src]fn try_from(bytes: &'a [u8]) -> Result<Self, Self::Error>
[src]
fn try_from(bytes: &'a [u8]) -> Result<Self, Self::Error>
[src]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.