Struct der_parser::ber::BerObject[][src]

pub struct BerObject<'a> {
    pub header: BerObjectHeader<'a>,
    pub content: BerObjectContent<'a>,
}
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: BerObjectHeader<'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 structured 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

👎 Deprecated since 0.5.0:

please use obj.header or obj.header.clone() instead

Build a BER header from this object content

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.

Constructs a shared &BitSlice reference over the object data, if available as slice.

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 NumericString, VisibleString, UTCTime, GeneralizedTime, PrintableString, UTF8String and IA5String are considered here. Other string types can be read using as_slice.

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

This is supported on crate feature bigint only.

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(), Some(65537.into()))
This is supported on crate feature bigint only.

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(), Some(65537_u32.into()))
This is supported on crate feature serialize only.

Attempt to encode object as BER

Note that the encoding will not check that the values of the BerObject fields are correct. The length is automatically calculated, and the field is ignored.

Tagged objects will be encoded as EXPLICIT.

This function is only available if the serialize feature is enabled.

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.

Performs the conversion.

Build a DER object from an OID.

Performs the conversion.

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

Converts self into T using Into<T>. Read more

Converts self into a target type. Read more

Causes self to use its Binary implementation when Debug-formatted.

Causes self to use its Display implementation when Debug-formatted. Read more

Causes self to use its LowerExp implementation when Debug-formatted. Read more

Causes self to use its LowerHex implementation when Debug-formatted. Read more

Causes self to use its Octal implementation when Debug-formatted.

Causes self to use its Pointer implementation when Debug-formatted. Read more

Causes self to use its UpperExp implementation when Debug-formatted. Read more

Causes self to use its UpperHex implementation when Debug-formatted. Read more

Performs the conversion.

Performs the conversion.

Pipes by value. This is generally the method you want to use. Read more

Borrows self and passes that borrow into the pipe function. Read more

Mutably borrows self and passes that borrow into the pipe function. Read more

Borrows self, then passes self.borrow() into the pipe function. Read more

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more

Borrows self, then passes self.as_ref() into the pipe function.

Mutably borrows self, then passes self.as_mut() into the pipe function. Read more

Borrows self, then passes self.deref() into the pipe function.

Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more

Pipes a value into a function that cannot ordinarily be called in suffix position. Read more

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more

Pipes a trait mutable borrow into a function that cannot normally be called in suffix position. Read more

Pipes a dereference into a function that cannot normally be called in suffix position. Read more

Pipes a mutable dereference into a function that cannot normally be called in suffix position. Read more

Pipes a reference into a function that cannot ordinarily be called in suffix position. Read more

Pipes a mutable reference into a function that cannot ordinarily be called in suffix position. Read more

Immutable access to a value. Read more

Mutable access to a value. Read more

Immutable access to the Borrow<B> of a value. Read more

Mutable access to the BorrowMut<B> of a value. Read more

Immutable access to the AsRef<R> view of a value. Read more

Mutable access to the AsMut<R> view of a value. Read more

Immutable access to the Deref::Target of a value. Read more

Mutable access to the Deref::Target of a value. Read more

Calls .tap() only in debug builds, and is erased in release builds.

Calls .tap_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more

Provides immutable access for inspection. Read more

Calls tap in debug builds, and does nothing in release builds.

Provides mutable access for modification. Read more

Calls tap_mut in debug builds, and does nothing in release builds.

Provides immutable access to the reference for inspection.

Calls tap_ref in debug builds, and does nothing in release builds.

Provides mutable access to the reference for modification.

Calls tap_ref_mut in debug builds, and does nothing in release builds.

Provides immutable access to the borrow for inspection. Read more

Calls tap_borrow in debug builds, and does nothing in release builds.

Provides mutable access to the borrow for modification.

Calls tap_borrow_mut in debug builds, and does nothing in release builds. Read more

Immutably dereferences self for inspection.

Calls tap_deref in debug builds, and does nothing in release builds.

Mutably dereferences self for modification.

Calls tap_deref_mut in debug builds, and does nothing in release builds. Read more

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)

recently added

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

Attempts to convert self into T using TryInto<T>. Read more

Attempts to convert self into a target type. 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.