Struct bsn1::Ber[][src]

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

Ber owns BerRef and represents a BER.

Implementations

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

Note that BER allows both definite and indefinite length, however, the length of the 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, &[]);

Creates a new instance from id and contents .

Examples
use bsn1::{Ber, IdRef};

let id = IdRef::sequence();

// Build instance using function 'from_id_iterator()'.
let contents: &[Ber] = &[Ber::utf8_string("foo"), Ber::integer(29)];
let ber = Ber::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 = Ber::new(id, &contents);

assert_eq!(expected, ber);

Returns a new instance representing boolean.

Examples
use bsn1::{contents, Ber, IdRef};

let val = true;
let ber = Ber::boolean(val);

assert_eq!(IdRef::boolean(), ber.id());
assert_eq!(val, contents::to_bool_ber(ber.contents()).unwrap());

Returns a new instance representing integer.

Type T should be the builtin primitive integer types (e.g., u8, u32, isize, i128, …)

Examples
use bsn1::{contents, Ber, IdRef};

let val = 39;
let ber = Ber::integer(val);

assert_eq!(IdRef::integer(), ber.id());
assert_eq!(val, contents::to_integer(ber.contents()).unwrap());

Returns a new instance representing utf8_string.

Examples
use bsn1::{Ber, IdRef};

let val = &"foo";
let ber = Ber::utf8_string(val);

assert_eq!(IdRef::utf8_string(), ber.id());
assert_eq!(val.as_bytes(), ber.contents());

Returns a new instance representing octet_string.

Examples
use bsn1::{Ber, IdRef};

let val = &[1, 2, 3];
let ber = Ber::octet_string(val);

assert_eq!(IdRef::octet_string(), ber.id());
assert_eq!(val, ber.contents());

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>

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());

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());

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

Performs the conversion.

Performs the conversion.

Immutably borrows from an owned value. Read more

Immutably borrows from an owned value. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Performs the conversion.

Performs the conversion.

Performs the conversion.

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

This method tests for !=.

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.

The type returned in the event of a conversion error.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.