[−][src]Struct bsn1::DerBuilder
DerBuilder is a struct to build Der effectively.
Examples
Empty contents.
use bsn1::{Der, DerBuilder, IdRef, Length}; let id = IdRef::octet_string(); let expected = Der::new(IdRef::octet_string(), &[]); // Because the contents is empty, do not need to call method 'extend_contents()'. let mut builder = DerBuilder::new(id, Length::Definite(0)); let der = builder.finish(); assert_eq!(expected, der);
Not empty contents
use bsn1::{Der, DerBuilder, IdRef, Length}; let id = IdRef::octet_string(); let contents = &[0, 1, 2, 3, 4]; let expected = Der::new(IdRef::octet_string(), contents); // Append 'contents' at once. { let length = Length::Definite(contents.len()); let mut builder = DerBuilder::new(id, length); builder.extend_contents(contents); let der = builder.finish(); assert_eq!(expected, der); } // Split contents into 2 pieces and append them one by one. { let length = Length::Definite(contents.len()); let mut builder = DerBuilder::new(id, length); builder.extend_contents(&contents[..2]); builder.extend_contents(&contents[2..]); let der = builder.finish(); assert_eq!(expected, der); }
Implementations
impl DerBuilder[src]
pub fn new(id: &IdRef, contents_len: Length) -> Self[src]
Creates a new instance to build Der with id and contents whose length equals to
contents_len .
contents_len must be Length::Definite because DER does not allow indefinite length.
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.'
Panics
Panics if contents_len equals Length::Indefinite .
Examples
See examples for the struct .
pub fn extend_contents<B>(&mut self, bytes: B) where
B: AsRef<[u8]>, [src]
B: AsRef<[u8]>,
Appends bytes to the end of the DER contents to be build.
Panics
Panics if the accumerated length of the 'contents' exceeds contents_len passed to
the constructor function new as the argument.
Examples
See examples for the struct .
pub fn finish(self) -> Der[src]
Auto Trait Implementations
impl RefUnwindSafe for DerBuilder
impl Send for DerBuilder
impl Sync for DerBuilder
impl Unpin for DerBuilder
impl UnwindSafe for DerBuilder
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>, [src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,