[][src]Struct bsn1::Ber

pub struct Ber { /* fields omitted */ }

Ber owns BerRef and represents a BER.

Implementations

impl Ber[src]

pub fn new(id: &IdRef, contents: &[u8]) -> Self[src]

Creates a new instance from id and contents with definite length.

Note that BER allows both definite and indefinite length, however, the length of return value is always definite. (Generally speaking, the performance of definite length is better than that of indefinite length. Indefinite length is seldom used these days.)

Examples

use bsn1::{Ber, IdRef};

let id = IdRef::octet_string();
let _ber = Ber::new(id, &[]);

impl Ber[src]

pub fn into_vec(self) -> Vec<u8>[src]

Consumes self , returning Vec .

Examples

use bsn1::{Ber, IdRef};

let id = IdRef::octet_string();
let contents: &[u8] = &[0, 1, 2, 3, 4];

let ber = Ber::new(id, contents);
let v = ber.clone().into_vec();

assert_eq!(ber.as_ref() as &[u8], v.as_ref() as &[u8]);

Methods from Deref<Target = BerRef>

pub fn id(&self) -> &IdRef[src]

Provides a reference to the 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());

pub fn length(&self) -> Length[src]

Returns Length of self .

Warnings

Length stands for 'the length of the contents' in BER. The length of 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());

pub fn contents(&self) -> &[u8][src]

Provides a reference to the 'contents' 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());

Trait Implementations

impl AsRef<[u8]> for Ber[src]

impl AsRef<BerRef> for Ber[src]

impl Borrow<[u8]> for Ber[src]

impl Borrow<BerRef> for Ber[src]

impl Clone for Ber[src]

impl Debug for Ber[src]

impl Deref for Ber[src]

type Target = BerRef

The resulting type after dereferencing.

impl Eq for Ber[src]

impl<'_> From<&'_ BerRef> for Ber[src]

impl<'_> From<&'_ DerRef> for Ber[src]

impl From<Der> for Ber[src]

impl PartialEq<Ber> for Ber[src]

impl StructuralEq for Ber[src]

impl StructuralPartialEq for Ber[src]

impl<'_> TryFrom<&'_ [u8]> for Ber[src]

type Error = Error

The type returned in the event of a conversion error.

fn try_from(bytes: &[u8]) -> Result<Self, Self::Error>[src]

Parses bytes starting with octets of 'ASN.1 BER' and returns a new instance.

This function ignores extra octet(s) at the end of bytes if any.

Auto Trait Implementations

impl RefUnwindSafe for Ber

impl Send for Ber

impl Sync for Ber

impl Unpin for Ber

impl UnwindSafe for Ber

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.