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>
impl<'a> BerElement<'a>
Sourcepub const fn content(&self) -> &'a [u8] ⓘ
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.
Sourcepub const fn encoded_len(&self) -> usize
pub const fn encoded_len(&self) -> usize
How many octets the whole element occupies, header included.
Sourcepub fn children(&self) -> Result<BerReader<'a>, DecodeError>
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.
Sourcepub fn as_u64(&self) -> Result<u64, DecodeError>
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.
Sourcepub fn validate(&self, max_depth: usize) -> Result<usize, DecodeError>
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.
Sourcepub fn find(&self, tag: BerTag) -> Result<Option<Self>, DecodeError>
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.