Struct bsn1::Der [−][src]
pub struct Der { /* fields omitted */ }
Expand description
Der
owns DerRef
and represents DER.
Implementations
impl Der
[src]
impl Der
[src]pub fn new(id: &IdRef, contents: &[u8]) -> Self
[src]
pub fn new(id: &IdRef, contents: &[u8]) -> Self
[src]Creates a new instance from id
and contents
.
Warnings
ASN.1 does not allow some universal identifier for DER, however, this function accepts
such an identifier.
For example, ‘Octet String’ must be primitive in DER, but this function will construct a
new instance even if id
represenets constructed ‘Octet String.’
Examples
use bsn1::{Der, IdRef}; let id = IdRef::octet_string(); let contents: &[u8] = &[10, 20, 30]; let der = Der::new(id, contents); assert_eq!(id, der.id()); assert_eq!(contents, der.contents());
pub fn from_id_iterator<I>(id: &IdRef, contents: I) -> Self where
I: Iterator + Clone,
I::Item: AsRef<[u8]>,
[src]
pub fn from_id_iterator<I>(id: &IdRef, contents: I) -> Self where
I: Iterator + Clone,
I::Item: AsRef<[u8]>,
[src]Creates a new instance from id
and contents
.
Warnings
ASN.1 does not allow some universal identifier for DER, however, this function accepts
such an identifier.
For example, ‘Octet String’ must be primitive in DER, but this function will construct a
new instance even if id
represenets constructed ‘Octet String.’
Examples
use bsn1::{Der, IdRef}; let id = IdRef::sequence(); // Build instance using function 'from_id_iterator()'. let contents: &[Der] = &[Der::utf8_string("foo"), Der::integer(29)]; let der = Der::from_id_iterator(id, contents.iter()); // Build instance using function 'new()'. let contents: Vec<u8> = contents.iter() .map(|i| Vec::from(i.as_ref() as &[u8])) .flatten().collect(); let expected = Der::new(id, &contents); assert_eq!(expected, der);
pub fn boolean(val: bool) -> Self
[src]
pub fn boolean(val: bool) -> Self
[src]Returns a new instance representing boolean.
Examples
use bsn1::{contents, Der, IdRef}; let val = true; let der = Der::boolean(val); assert_eq!(IdRef::boolean(), der.id()); assert_eq!(val, contents::to_bool_der(der.contents()).unwrap());
pub fn integer(val: i128) -> Self
[src]
pub fn integer(val: i128) -> Self
[src]Returns a new instance representing ingeger.
Examples
use bsn1::{contents, Der, IdRef}; let val = 39; let der = Der::integer(val); assert_eq!(IdRef::integer(), der.id()); assert_eq!(val, contents::to_integer(der.contents()).unwrap());
pub fn utf8_string(val: &str) -> Self
[src]
pub fn utf8_string(val: &str) -> Self
[src]Returns a new instance representing utf8_string.
Examples
use bsn1::{Der, IdRef}; let val = &"foo"; let der = Der::utf8_string(val); assert_eq!(IdRef::utf8_string(), der.id()); assert_eq!(val.as_bytes(), der.contents());
Methods from Deref<Target = DerRef>
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 TryFrom<&'_ [u8]> for Der
[src]
impl TryFrom<&'_ [u8]> for Der
[src]fn try_from(bytes: &[u8]) -> Result<Self, Self::Error>
[src]
fn try_from(bytes: &[u8]) -> Result<Self, Self::Error>
[src]Parses bytes
starting with DER octets and builds a new instance.
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 accepts
such an identifier.
For example, ‘Octet String’ must be primitive in DER, but this function returns Ok
for
constructed Octet String DER.
impl Eq for Der
[src]
impl StructuralEq for Der
[src]
impl StructuralPartialEq for Der
[src]
Auto Trait Implementations
impl RefUnwindSafe for Der
impl Send for Der
impl Sync for Der
impl Unpin for Der
impl UnwindSafe for Der
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[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