logo
pub struct BerObject<'a> {
    pub header: Header<'a>,
    pub content: BerObjectContent<'a>,
}
Available on crate feature mtls only.
Expand description

Representation of a BER-encoded (X.690) object

A BER object is composed of a header describing the object class, type and length, and the content.

Note that the content may sometimes not match the header tag (for ex when parsing IMPLICIT tagged values).

Fields

header: Header<'a>content: BerObjectContent<'a>

Implementations

Build a BerObject from a header and content.

Note: values are not checked, so the tag can be different from the real content, or flags can be invalid.

Build a BerObject from its content, using default flags (no class, correct tag, and constructed flag set only for Set and Sequence)

Build a DER integer object from a slice containing an encoded integer

Set a tag for the BER object

Build a DER sequence object from a vector of DER objects

Build a DER set object from a vector of DER objects

Attempt to read a signed integer value from DER object.

This can fail if the object is not an integer, or if it is too large.

Examples
let der_int  = BerObject::from_int_slice(b"\x80");
assert_eq!(
    der_int.as_i64(),
    Ok(-128)
);

Attempt to read a signed integer value from DER object.

This can fail if the object is not an integer, or if it is too large.

Examples
let der_int  = BerObject::from_int_slice(b"\x80");
assert_eq!(
    der_int.as_i32(),
    Ok(-128)
);

Attempt to read integer value from DER object.

This can fail if the object is not an unsigned integer, or if it is too large.

Examples
let der_int  = BerObject::from_int_slice(b"\x01\x00\x01");
assert_eq!(
    der_int.as_u64(),
    Ok(0x10001)
);

Attempt to read integer value from DER object.

This can fail if the object is not an unsigned integer, or if it is too large.

Examples
let der_int  = BerObject::from_obj(BerObjectContent::Integer(b"\x01\x00\x01"));
assert_eq!(
    der_int.as_u32(),
    Ok(0x10001)
);

Attempt to read integer value from DER object. This can fail if the object is not a boolean.

Attempt to read an OID value from DER object. This can fail if the object is not an OID.

Attempt to read an OID value from DER object. This can fail if the object is not an OID.

Attempt to get a reference on the content from an optional object. This can fail if the object is not optional.

Attempt to get a reference on the content from a tagged object. This can fail if the object is not tagged.

Attempt to read a reference to a BitString value from DER object. This can fail if the object is not an BitString.

Note that this function returns a reference to the BitString. To get an owned value, use as_bitstring

Attempt to read a BitString value from DER object. This can fail if the object is not an BitString.

Attempt to extract the list of objects from a DER sequence. This can fail if the object is not a sequence.

Attempt to extract the list of objects from a DER set. This can fail if the object is not a set.

Attempt to get the content from a DER object, as a slice. This can fail if the object does not contain a type directly equivalent to a slice (e.g a sequence). This function mostly concerns string types, integers, or unknown DER objects.

Attempt to get the content from a DER object, as a str. This can fail if the object does not contain a string type.

Only some string types are considered here. Other string types can be read using as_slice.

Get the BER object header’s class.

Get the BER object header’s tag.

Get the BER object header’s length.

Test if object class is Universal

Test if object class is Application

Test if object class is Context-specific

Test if object class is Private

Test if object is primitive

Test if object is constructed

Return error if class is not the expected class

Return error if tag is not the expected tag

Return error if object is not constructed

Return error if object is not primitive

Attempt to read an integer value from this object.

This can fail if the object is not an integer.

Examples
use der_parser::ber::*;

let data = &[0x02, 0x03, 0x01, 0x00, 0x01];

let (_, object) = parse_ber_integer(data).expect("parsing failed");
assert_eq!(object.as_bigint(), Ok(65537.into()))

Attempt to read a positive integer value from this object.

This can fail if the object is not an integer, or is negative.

Examples
use der_parser::ber::*;

let data = &[0x02, 0x03, 0x01, 0x00, 0x01];

let (_, object) = parse_ber_integer(data).expect("parsing failed");
assert_eq!(object.as_biguint(), Ok(65537_u32.into()))

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Build a DER object from a BerObjectContent.

Converts to this type from the input type.

Build a DER object from an OID.

Converts to this type from the input type.

The returned type after indexing.

Performs the indexing (container[index]) operation. Read more

The type of the elements being iterated over.

Which kind of iterator are we turning this into?

Creates an iterator from a value. Read more

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

This method tests for !=.

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

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

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

Converts self into a collection.

Should always be Self

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.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more