Skip to main content

BerElement

Struct BerElement 

Source
pub struct BerElement<'a> { /* private fields */ }
Expand description

One tag-length-value element, borrowing its contents from the input.

Implementations§

Source§

impl<'a> BerElement<'a>

Source

pub const fn tag(&self) -> BerTag

The element’s tag.

Source

pub const fn length(&self) -> BerLength

How the contents were delimited.

Source

pub const fn content(&self) -> &'a [u8] ⓘ

The contents, borrowed from the input.

For a constructed element these are the encoded children; use children to walk them.

Source

pub const fn encoded_len(&self) -> usize

How many octets the whole element occupies, header included.

Source

pub const fn offset(&self) -> usize

Where the element began in the input it was read from.

Source

pub fn children(&self) -> Result<BerReader<'a>, DecodeError>

A reader over this element’s children.

§Errors

DecodeError when the element is primitive: its contents are raw bytes, and reading them as elements would produce fields that are not there.

Source

pub fn as_u64(&self) -> Result<u64, DecodeError>

The contents as an unsigned integer.

§Errors

DecodeError for an empty field, one wider than eight octets, a negative value, or a non-minimal encoding — X.690 §8.3 requires the shortest form, and a padded integer is a second encoding of one value.

Source

pub fn validate(&self, max_depth: usize) -> Result<usize, DecodeError>

Walk this element’s structure, refusing to descend past max_depth.

Returns how many elements were visited, this one included.

Nesting is attacker-controlled in a record that arrived over a network, so the bound is mandatory rather than optional. The walk is iterative and never recurses, so exceeding the bound is reported rather than crashing.

§Errors

DecodeError when the structure is malformed, or nests deeper than max_depth.

Source

pub fn find(&self, tag: BerTag) -> Result<Option<Self>, DecodeError>

The first child whose tag matches, searching only this element’s own children.

Not recursive: a tag number is only meaningful at the level its schema places it, and a deep search would happily return a field from an unrelated nested structure.

§Errors

DecodeError when the element is primitive or its children are malformed.

Trait Implementations§

Source§

impl<'a> Clone for BerElement<'a>

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Copy for BerElement<'a>

Source§

impl<'a> Debug for BerElement<'a>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Display for BerElement<'_>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<'a> Eq for BerElement<'a>

Source§

impl<'a> PartialEq for BerElement<'a>

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<'a> StructuralPartialEq for BerElement<'a>

Auto Trait Implementations§

§

impl<'a> Forget for BerElement<'a>

§

impl<'a> Freeze for BerElement<'a>

§

impl<'a> Move for BerElement<'a>

§

impl<'a> RefUnwindSafe for BerElement<'a>

§

impl<'a> Send for BerElement<'a>

§

impl<'a> Sync for BerElement<'a>

§

impl<'a> Unpin for BerElement<'a>

§

impl<'a> UnsafeUnpin for BerElement<'a>

§

impl<'a> UnwindSafe for BerElement<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.