Struct der_parser::DerObject
source · pub struct DerObject<'a> {
pub class: u8,
pub structured: u8,
pub tag: u8,
pub content: DerObjectContent<'a>,
}
Expand description
Representation of a DER-encoded (X.690) object
Fields
class: u8
structured: u8
tag: u8
content: DerObjectContent<'a>
Implementations
sourceimpl<'a> DerObject<'a>
impl<'a> DerObject<'a>
sourcepub fn from_header_and_content(
hdr: DerObjectHeader,
c: DerObjectContent<'_>
) -> DerObject<'_>
pub fn from_header_and_content(
hdr: DerObjectHeader,
c: DerObjectContent<'_>
) -> DerObject<'_>
Build a DerObject 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.
sourcepub fn from_obj(c: DerObjectContent<'_>) -> DerObject<'_>
pub fn from_obj(c: DerObjectContent<'_>) -> DerObject<'_>
Build a DerObject from its content, using default flags (no class, correct tag, and structured flag set only for Set and Sequence)
sourcepub fn from_int_slice(i: &'a [u8]) -> DerObject<'a>
pub fn from_int_slice(i: &'a [u8]) -> DerObject<'a>
Build a DER integer object from a slice containing an encoded integer
sourcepub fn from_seq(l: Vec<DerObject<'_>>) -> DerObject<'_>
pub fn from_seq(l: Vec<DerObject<'_>>) -> DerObject<'_>
Build a DER sequence object from a vector of DER objects
sourcepub fn from_set(l: Vec<DerObject<'_>>) -> DerObject<'_>
pub fn from_set(l: Vec<DerObject<'_>>) -> DerObject<'_>
Build a DER set object from a vector of DER objects
sourcepub fn as_u64(&self) -> Result<u64, DerError>
pub fn as_u64(&self) -> Result<u64, DerError>
Attempt to read integer value from DER object. This can fail if the object is not an integer, or if it is too large.
let der_int = DerObject::from_obj(DerObjectContent::Integer(b"\x01\x00\x01"));
assert_eq!(
der_int.as_u64(),
Ok(0x10001)
);
sourcepub fn as_u32(&self) -> Result<u32, DerError>
pub fn as_u32(&self) -> Result<u32, DerError>
Attempt to read integer value from DER object. This can fail if the object is not an integer, or if it is too large.
let der_int = DerObject::from_obj(DerObjectContent::Integer(b"\x01\x00\x01"));
assert_eq!(
der_int.as_u32(),
Ok(0x10001)
);
sourcepub fn as_bool(&self) -> Result<bool, DerError>
pub fn as_bool(&self) -> Result<bool, DerError>
Attempt to read integer value from DER object. This can fail if the object is not a boolean.
sourcepub fn as_oid(&self) -> Result<&Oid, DerError>
pub fn as_oid(&self) -> Result<&Oid, DerError>
Attempt to read an OID value from DER object. This can fail if the object is not an OID.
Note that this function returns a reference to the OID. To get an owned value,
use as_oid_val
sourcepub fn as_oid_val(&self) -> Result<Oid, DerError>
pub fn as_oid_val(&self) -> Result<Oid, DerError>
Attempt to read an OID value from DER object. This can fail if the object is not an OID.
sourcepub fn as_context_specific(
&self
) -> Result<(u8, Option<Box<DerObject<'a>>>), DerError>
pub fn as_context_specific(
&self
) -> Result<(u8, Option<Box<DerObject<'a>>>), DerError>
Attempt to read the content from a context-specific DER object. This can fail if the object is not context-specific.
Note: the object is cloned.
sourcepub fn as_bitstring_ref(&self) -> Result<&BitStringObject<'_>, DerError>
pub fn as_bitstring_ref(&self) -> Result<&BitStringObject<'_>, DerError>
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
sourcepub fn as_bitstring(&'a self) -> Result<BitStringObject<'a>, DerError>
pub fn as_bitstring(&'a self) -> Result<BitStringObject<'a>, DerError>
Attempt to read a BitString value from DER object. This can fail if the object is not an BitString.
sourcepub fn as_sequence(&self) -> Result<&Vec<DerObject<'a>>, DerError>
pub fn as_sequence(&self) -> Result<&Vec<DerObject<'a>>, DerError>
Attempt to extract the list of objects from a DER sequence. This can fail if the object is not a sequence.
sourcepub fn as_set(&self) -> Result<&Vec<DerObject<'a>>, DerError>
pub fn as_set(&self) -> Result<&Vec<DerObject<'a>>, DerError>
Attempt to extract the list of objects from a DER set. This can fail if the object is not a set.
sourcepub fn as_slice(&self) -> Result<&'a [u8], DerError>
pub fn as_slice(&self) -> Result<&'a [u8], DerError>
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.
sourcepub fn is_universal(&self) -> bool
pub fn is_universal(&self) -> bool
Test if object class is Universal
sourcepub fn is_application(&self) -> bool
pub fn is_application(&self) -> bool
Test if object class is Application
sourcepub fn is_contextspecific(&self) -> bool
pub fn is_contextspecific(&self) -> bool
Test if object class is Context-specific
sourcepub fn is_private(&self) -> bool
pub fn is_private(&self) -> bool
Test if object class is Private
sourcepub fn is_primitive(&self) -> bool
pub fn is_primitive(&self) -> bool
Test if object is primitive
sourcepub fn is_constructed(&self) -> bool
pub fn is_constructed(&self) -> bool
Test if object is constructed
sourceimpl<'a> DerObject<'a>
impl<'a> DerObject<'a>
pub fn ref_iter(&'a self) -> DerObjectRefIterator<'a>ⓘNotable traits for DerObjectRefIterator<'a>impl<'a> Iterator for DerObjectRefIterator<'a> type Item = &'a DerObject<'a>;
Trait Implementations
sourceimpl<'a> From<DerObjectContent<'a>> for DerObject<'a>
impl<'a> From<DerObjectContent<'a>> for DerObject<'a>
Build a DER object from a DerObjectContent.