Struct bsn1::BerRef[][src]

pub struct BerRef { /* fields omitted */ }
Expand description

BerRef is a wrapper of [u8] and represents a BER.

This struct is ‘Unsized’, and user usually uses a reference to the instance.

Implementations

impl BerRef[src]

pub unsafe fn from_bytes_unchecked(bytes: &[u8]) -> &Self[src]

Provides a reference from bytes without any sanitization.

bytes must be BER octets and must not include any extra octet.

If it is sure that bytes starts with BER 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 BER octets or not, use TryFrom implementation.

Safety

The behavior is undefined if bytes is not formatted as a BER.

Examples

use bsn1::{Ber, BerRef, IdRef};

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

let bytes: &[u8] = ber.as_ref();
let deserialized = unsafe { BerRef::from_bytes_unchecked(bytes) };
assert_eq!(ber.as_ref() as &BerRef, deserialized);

pub unsafe fn from_bytes_starts_with_unchecked(bytes: &[u8]) -> &Self[src]

Provides a reference from bytes that starts with a BER octets.

bytes may include some extra octet(s) at the end.

If it is not sure whether bytes starts with BER octets or not, use TryFrom implementation.

Safety

The behavior is undefined if bytes does not start with BER octets.

Examples

use bsn1::{Ber, BerRef, IdRef};

let id = IdRef::octet_string();
let ber = Ber::new(id, &[]);
let mut bytes = Vec::from(ber.as_ref() as &[u8]);
bytes.extend(&[1, 2, 3]);

let deserialized = unsafe { BerRef::from_bytes_starts_with_unchecked(bytes.as_ref()) };
assert_eq!(ber.as_ref() as &BerRef, deserialized);

impl BerRef[src]

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

Provides a reference to 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 octets of the contents’ in BER. 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’ octets 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 BerRef[src]

fn as_ref(&self) -> &[u8][src]

Performs the conversion.

impl AsRef<BerRef> for Ber[src]

fn as_ref(&self) -> &BerRef[src]

Performs the conversion.

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

fn borrow(&self) -> &[u8][src]

Immutably borrows from an owned value. Read more

impl Borrow<BerRef> for Ber[src]

fn borrow(&self) -> &BerRef[src]

Immutably borrows from an owned value. Read more

impl Debug for BerRef[src]

fn fmt(&self, f: &mut Formatter<'_>) -> Result[src]

Formats the value using the given formatter. Read more

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

fn from(ber_ref: &BerRef) -> Self[src]

Performs the conversion.

impl<'a> From<&'a DerRef> for &'a BerRef[src]

fn from(der: &'a DerRef) -> Self[src]

Performs the conversion.

impl PartialEq<BerRef> for BerRef[src]

fn eq(&self, other: &BerRef) -> bool[src]

This method tests for self and other values to be equal, and is used by ==. Read more

fn ne(&self, other: &BerRef) -> bool[src]

This method tests for !=.

impl ToOwned for BerRef[src]

type Owned = Ber

The resulting type after obtaining ownership.

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]

🔬 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 BerRef[src]

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

Parses bytes starting with octets of ‘ASN.1 BER’ and returns a reference to BerRef .

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

type Error = Error

The type returned in the event of a conversion error.

impl Eq for BerRef[src]

impl StructuralEq for BerRef[src]

impl StructuralPartialEq for BerRef[src]

Auto Trait Implementations

impl RefUnwindSafe for BerRef

impl Send for BerRef

impl !Sized for BerRef

impl Sync for BerRef

impl Unpin for BerRef

impl UnwindSafe for BerRef

Blanket Implementations

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

pub fn type_id(&self) -> TypeId[src]

Gets the TypeId of self. Read more

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

pub fn borrow(&self) -> &T[src]

Immutably borrows from an owned value. Read more

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

pub fn borrow_mut(&mut self) -> &mut T[src]

Mutably borrows from an owned value. Read more