Struct BerObject
pub struct BerObject<'a> {
pub header: Header<'a>,
pub content: BerObjectContent<'a>,
}crypto 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§
§impl<'a> BerObject<'a>
impl<'a> BerObject<'a>
pub const fn from_header_and_content<'o>(
header: Header<'o>,
content: BerObjectContent<'o>,
) -> BerObject<'o>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub const fn from_header_and_content<'o>( header: Header<'o>, content: BerObjectContent<'o>, ) -> BerObject<'o>
rustls or boring or acme) and crate feature rustls only.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.
pub const fn from_obj(c: BerObjectContent<'_>) -> BerObject<'_>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub const fn from_obj(c: BerObjectContent<'_>) -> BerObject<'_>
rustls or boring or acme) and crate feature rustls only.Build a BerObject from its content, using default flags (no class, correct tag, and constructed flag set only for Set and Sequence)
pub const fn from_int_slice(i: &'a [u8]) -> BerObject<'a>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub const fn from_int_slice(i: &'a [u8]) -> BerObject<'a>
rustls or boring or acme) and crate feature rustls only.Build a DER integer object from a slice containing an encoded integer
pub fn set_raw_tag(self, raw_tag: Option<&'a [u8]>) -> BerObject<'a>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub fn set_raw_tag(self, raw_tag: Option<&'a [u8]>) -> BerObject<'a>
rustls or boring or acme) and crate feature rustls only.Set a tag for the BER object
pub const fn from_seq(l: Vec<BerObject<'_>>) -> BerObject<'_>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub const fn from_seq(l: Vec<BerObject<'_>>) -> BerObject<'_>
rustls or boring or acme) and crate feature rustls only.Build a DER sequence object from a vector of DER objects
pub const fn from_set(l: Vec<BerObject<'_>>) -> BerObject<'_>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub const fn from_set(l: Vec<BerObject<'_>>) -> BerObject<'_>
rustls or boring or acme) and crate feature rustls only.Build a DER set object from a vector of DER objects
pub fn as_i64(&self) -> Result<i64, Error>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub fn as_i64(&self) -> Result<i64, Error>
rustls or boring or acme) and crate feature rustls only.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)
);pub fn as_i32(&self) -> Result<i32, Error>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub fn as_i32(&self) -> Result<i32, Error>
rustls or boring or acme) and crate feature rustls only.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)
);pub fn as_u64(&self) -> Result<u64, Error>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub fn as_u64(&self) -> Result<u64, Error>
rustls or boring or acme) and crate feature rustls only.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)
);pub fn as_u32(&self) -> Result<u32, Error>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub fn as_u32(&self) -> Result<u32, Error>
rustls or boring or acme) and crate feature rustls only.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)
);pub fn as_bool(&self) -> Result<bool, Error>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub fn as_bool(&self) -> Result<bool, Error>
rustls or boring or acme) and crate feature rustls only.Attempt to read integer value from DER object. This can fail if the object is not a boolean.
pub fn as_oid(&self) -> Result<&Oid<'a>, Error>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub fn as_oid(&self) -> Result<&Oid<'a>, Error>
rustls or boring or acme) and crate feature rustls only.Attempt to read an OID value from DER object. This can fail if the object is not an OID.
pub fn as_oid_val(&self) -> Result<Oid<'a>, Error>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub fn as_oid_val(&self) -> Result<Oid<'a>, Error>
rustls or boring or acme) and crate feature rustls only.Attempt to read an OID value from DER object. This can fail if the object is not an OID.
pub fn as_optional(&self) -> Result<Option<&BerObject<'a>>, Error>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub fn as_optional(&self) -> Result<Option<&BerObject<'a>>, Error>
rustls or boring or acme) and crate feature rustls only.Attempt to get a reference on the content from an optional object. This can fail if the object is not optional.
pub fn as_tagged(&self) -> Result<(Class, Tag, &BerObject<'a>), Error>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub fn as_tagged(&self) -> Result<(Class, Tag, &BerObject<'a>), Error>
rustls or boring or acme) and crate feature rustls only.Attempt to get a reference on the content from a tagged object. This can fail if the object is not tagged.
pub fn as_bitstring_ref(&self) -> Result<&BitStringObject<'_>, Error>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub fn as_bitstring_ref(&self) -> Result<&BitStringObject<'_>, Error>
rustls or boring or acme) and crate feature rustls only.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
pub fn as_bitstring(&self) -> Result<BitStringObject<'a>, Error>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub fn as_bitstring(&self) -> Result<BitStringObject<'a>, Error>
rustls or boring or acme) and crate feature rustls only.Attempt to read a BitString value from DER object. This can fail if the object is not an BitString.
pub fn as_sequence(&self) -> Result<&Vec<BerObject<'a>>, Error>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub fn as_sequence(&self) -> Result<&Vec<BerObject<'a>>, Error>
rustls or boring or acme) and crate feature rustls only.Attempt to extract the list of objects from a DER sequence. This can fail if the object is not a sequence.
pub fn as_set(&self) -> Result<&Vec<BerObject<'a>>, Error>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub fn as_set(&self) -> Result<&Vec<BerObject<'a>>, Error>
rustls or boring or acme) and crate feature rustls only.Attempt to extract the list of objects from a DER set. This can fail if the object is not a set.
pub fn as_slice(&self) -> Result<&'a [u8], Error>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub fn as_slice(&self) -> Result<&'a [u8], Error>
rustls or boring or acme) and crate feature rustls only.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.
pub fn as_str(&self) -> Result<&'a str, Error>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub fn as_str(&self) -> Result<&'a str, Error>
rustls or boring or acme) and crate feature rustls only.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.
pub const fn class(&self) -> Class
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub const fn class(&self) -> Class
rustls or boring or acme) and crate feature rustls only.Get the BER object header’s class.
pub const fn tag(&self) -> Tag
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub const fn tag(&self) -> Tag
rustls or boring or acme) and crate feature rustls only.Get the BER object header’s tag.
pub const fn length(&self) -> Length
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub const fn length(&self) -> Length
rustls or boring or acme) and crate feature rustls only.Get the BER object header’s length.
pub const fn is_universal(&self) -> bool
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub const fn is_universal(&self) -> bool
rustls or boring or acme) and crate feature rustls only.Test if object class is Universal
pub const fn is_application(&self) -> bool
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub const fn is_application(&self) -> bool
rustls or boring or acme) and crate feature rustls only.Test if object class is Application
pub const fn is_contextspecific(&self) -> bool
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub const fn is_contextspecific(&self) -> bool
rustls or boring or acme) and crate feature rustls only.Test if object class is Context-specific
pub fn is_private(&self) -> bool
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub fn is_private(&self) -> bool
rustls or boring or acme) and crate feature rustls only.Test if object class is Private
pub const fn is_primitive(&self) -> bool
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub const fn is_primitive(&self) -> bool
rustls or boring or acme) and crate feature rustls only.Test if object is primitive
pub const fn is_constructed(&self) -> bool
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub const fn is_constructed(&self) -> bool
rustls or boring or acme) and crate feature rustls only.Test if object is constructed
pub const fn assert_class(&self, class: Class) -> Result<(), Error>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub const fn assert_class(&self, class: Class) -> Result<(), Error>
rustls or boring or acme) and crate feature rustls only.Return error if class is not the expected class
pub const fn assert_tag(&self, tag: Tag) -> Result<(), Error>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub const fn assert_tag(&self, tag: Tag) -> Result<(), Error>
rustls or boring or acme) and crate feature rustls only.Return error if tag is not the expected tag
pub const fn assert_constructed(&self) -> Result<(), Error>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub const fn assert_constructed(&self) -> Result<(), Error>
rustls or boring or acme) and crate feature rustls only.Return error if object is not constructed
pub const fn assert_primitive(&self) -> Result<(), Error>
Available on (crate features rustls or boring or acme) and crate feature rustls only.
pub const fn assert_primitive(&self) -> Result<(), Error>
rustls or boring or acme) and crate feature rustls only.Return error if object is not primitive
§impl BerObject<'_>
impl BerObject<'_>
pub fn as_bigint(&self) -> Result<BigInt, Error>
Available on (crate features rustls or boring or acme) and crate feature rustls and crate feature bigint only.
pub fn as_bigint(&self) -> Result<BigInt, Error>
rustls or boring or acme) and crate feature rustls and 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(), Ok(65537.into()))pub fn as_biguint(&self) -> Result<BigUint, Error>
Available on (crate features rustls or boring or acme) and crate feature rustls and crate feature bigint only.
pub fn as_biguint(&self) -> Result<BigUint, Error>
rustls or boring or acme) and crate feature rustls and 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(), Ok(65537_u32.into()))§impl<'a> BerObject<'a>
impl<'a> BerObject<'a>
pub fn ref_iter(&'a self) -> BerObjectRefIterator<'a> ⓘ
rustls or boring or acme) and crate feature rustls only.Trait Implementations§
§impl<'a> From<BerObjectContent<'a>> for BerObject<'a>
Build a DER object from a BerObjectContent.
impl<'a> From<BerObjectContent<'a>> for BerObject<'a>
Build a DER object from a BerObjectContent.
§fn from(obj: BerObjectContent<'a>) -> BerObject<'a>
fn from(obj: BerObjectContent<'a>) -> BerObject<'a>
§impl<'a> IntoIterator for BerObject<'a>
impl<'a> IntoIterator for BerObject<'a>
impl<'a> StructuralPartialEq for BerObject<'a>
Auto Trait Implementations§
impl<'a> Freeze for BerObject<'a>
impl<'a> RefUnwindSafe for BerObject<'a>
impl<'a> Send for BerObject<'a>
impl<'a> Sync for BerObject<'a>
impl<'a> Unpin for BerObject<'a>
impl<'a> UnwindSafe for BerObject<'a>
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§fn and<P, B, E>(self, other: P) -> And<T, P>
fn and<P, B, E>(self, other: P) -> And<T, P>
Policy that returns Action::Follow only if self and other return
Action::Follow. Read more