Struct der_parser::ber::BerObject
source · [−]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
sourceimpl<'a> BerObject<'a>
impl<'a> BerObject<'a>
sourcepub fn from_header_and_content<'o>(
header: BerObjectHeader<'o>,
content: BerObjectContent<'o>
) -> BerObject<'o>
pub fn from_header_and_content<'o>(
header: BerObjectHeader<'o>,
content: BerObjectContent<'o>
) -> BerObject<'o>
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.
sourcepub fn from_obj(c: BerObjectContent<'_>) -> BerObject<'_>
pub fn from_obj(c: BerObjectContent<'_>) -> BerObject<'_>
Build a BerObject 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]) -> BerObject<'a>
pub fn from_int_slice(i: &'a [u8]) -> BerObject<'a>
Build a DER integer object from a slice containing an encoded integer
sourcepub fn set_raw_tag(self, raw_tag: Option<&'a [u8]>) -> BerObject<'_>
pub fn set_raw_tag(self, raw_tag: Option<&'a [u8]>) -> BerObject<'_>
Set a tag for the BER object
sourcepub fn from_seq(l: Vec<BerObject<'_>>) -> BerObject<'_>
pub fn from_seq(l: Vec<BerObject<'_>>) -> BerObject<'_>
Build a DER sequence object from a vector of DER objects
sourcepub fn from_set(l: Vec<BerObject<'_>>) -> BerObject<'_>
pub fn from_set(l: Vec<BerObject<'_>>) -> BerObject<'_>
Build a DER set object from a vector of DER objects
sourcepub fn as_i64(&self) -> Result<i64, BerError>
pub fn as_i64(&self) -> Result<i64, BerError>
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)
);sourcepub fn as_i32(&self) -> Result<i32, BerError>
pub fn as_i32(&self) -> Result<i32, BerError>
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)
);sourcepub fn as_u64(&self) -> Result<u64, BerError>
pub fn as_u64(&self) -> Result<u64, BerError>
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)
);sourcepub fn as_u32(&self) -> Result<u32, BerError>
pub fn as_u32(&self) -> Result<u32, BerError>
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)
);sourcepub fn as_bool(&self) -> Result<bool, BerError>
pub fn as_bool(&self) -> Result<bool, BerError>
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<'a>, BerError>
pub fn as_oid(&self) -> Result<&Oid<'a>, BerError>
Attempt to read an OID value from DER object. This can fail if the object is not an OID.
sourcepub fn as_oid_val(&self) -> Result<Oid<'a>, BerError>
pub fn as_oid_val(&self) -> Result<Oid<'a>, BerError>
Attempt to read an OID value from DER object. This can fail if the object is not an OID.
sourcepub fn as_optional(&'a self) -> Result<Option<&BerObject<'a>>, BerError>
pub fn as_optional(&'a self) -> Result<Option<&BerObject<'a>>, BerError>
Attempt to get a reference on the content from an optional object. This can fail if the object is not optional.
sourcepub fn as_tagged(
&'a self
) -> Result<(BerClass, BerTag, &BerObject<'a>), BerError>
pub fn as_tagged(
&'a self
) -> Result<(BerClass, BerTag, &BerObject<'a>), BerError>
Attempt to get a reference on the content from a tagged object. This can fail if the object is not tagged.
sourcepub fn as_bitstring_ref(&self) -> Result<&BitStringObject<'_>, BerError>
pub fn as_bitstring_ref(&self) -> Result<&BitStringObject<'_>, BerError>
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>, BerError>
pub fn as_bitstring(&'a self) -> Result<BitStringObject<'a>, BerError>
Attempt to read a BitString value from DER object. This can fail if the object is not an BitString.
sourcepub fn as_bitslice(&self) -> Result<&BitSlice<Msb0, u8>, BerError>
pub fn as_bitslice(&self) -> Result<&BitSlice<Msb0, u8>, BerError>
Constructs a shared &BitSlice reference over the object data, if available as slice.
sourcepub fn as_sequence(&self) -> Result<&Vec<BerObject<'a>>, BerError>
pub fn as_sequence(&self) -> Result<&Vec<BerObject<'a>>, BerError>
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<BerObject<'a>>, BerError>
pub fn as_set(&self) -> Result<&Vec<BerObject<'a>>, BerError>
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], BerError>
pub fn as_slice(&self) -> Result<&'a [u8], BerError>
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 as_str(&self) -> Result<&'a str, BerError>
pub fn as_str(&self) -> Result<&'a str, BerError>
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.
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> BerObject<'a>
impl<'a> BerObject<'a>
sourcepub fn as_bigint(&self) -> Result<BigInt, BerError>
This is supported on crate feature bigint only.
pub fn as_bigint(&self) -> Result<BigInt, BerError>
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()))sourcepub fn as_biguint(&self) -> Result<BigUint, BerError>
This is supported on crate feature bigint only.
pub fn as_biguint(&self) -> Result<BigUint, BerError>
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()))sourceimpl<'a> BerObject<'a>
impl<'a> BerObject<'a>
pub fn ref_iter(&'a self) -> BerObjectRefIterator<'a>ⓘNotable traits for BerObjectRefIterator<'a>impl<'a> Iterator for BerObjectRefIterator<'a> type Item = &'a BerObject<'a>;
sourceimpl<'a> BerObject<'a>
impl<'a> BerObject<'a>
sourcepub fn to_vec(&self) -> Result<Vec<u8>, GenError>
This is supported on crate feature serialize only.
pub fn to_vec(&self) -> Result<Vec<u8>, GenError>
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
sourceimpl<'a> From<BerObjectContent<'a>> for BerObject<'a>
impl<'a> From<BerObjectContent<'a>> for BerObject<'a>
Build a DER object from a BerObjectContent.
sourcefn from(obj: BerObjectContent<'a>) -> BerObject<'a>
fn from(obj: BerObjectContent<'a>) -> BerObject<'a>
Performs the conversion.
sourceimpl<'a> IntoIterator for BerObject<'a>
impl<'a> IntoIterator for BerObject<'a>
impl<'a> StructuralPartialEq for BerObject<'a>
Auto Trait Implementations
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
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
impl<T> FmtForward for T
impl<T> FmtForward for T
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
Causes self to use its Binary implementation when Debug-formatted.
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
Causes self to use its Display implementation when
Debug-formatted. Read more
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
Causes self to use its LowerExp implementation when
Debug-formatted. Read more
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
Causes self to use its LowerHex implementation when
Debug-formatted. Read more
fn fmt_octal(self) -> FmtOctal<Self> where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self> where
Self: Octal,
Causes self to use its Octal implementation when Debug-formatted.
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
Causes self to use its Pointer implementation when
Debug-formatted. Read more
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
Causes self to use its UpperExp implementation when
Debug-formatted. Read more
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
Causes self to use its UpperHex implementation when
Debug-formatted. Read more
impl<T> Pipe for T where
T: ?Sized,
impl<T> Pipe for T where
T: ?Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
Pipes by value. This is generally the method you want to use. Read more
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R where
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R where
R: 'a,
Borrows self and passes that borrow into the pipe function. Read more
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
Mutably borrows self and passes that borrow into the pipe function. Read more
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
Borrows self, then passes self.borrow() into the pipe function. Read more
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
Mutably borrows self, then passes self.borrow_mut() into the pipe
function. Read more
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
Borrows self, then passes self.as_ref() into the pipe function.
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
Mutably borrows self, then passes self.as_mut() into the pipe
function. Read more
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
Borrows self, then passes self.deref() into the pipe function.
impl<T> Tap for T
impl<T> Tap for T
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Immutable access to the Borrow<B> of a value. Read more
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Mutable access to the BorrowMut<B> of a value. Read more
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
Immutable access to the AsRef<R> view of a value. Read more
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Mutable access to the AsMut<R> view of a value. Read more
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self where
Self: Deref<Target = T>,
T: ?Sized,
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self where
Self: Deref<Target = T>,
T: ?Sized,
Immutable access to the Deref::Target of a value. Read more
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self where
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self where
Self: DerefMut<Target = T> + Deref,
T: ?Sized,
Mutable access to the Deref::Target of a value. Read more
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
Calls .tap() only in debug builds, and is erased in release builds.
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls .tap_mut() only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Calls .tap_borrow() only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Calls .tap_borrow_mut() only in debug builds, and is erased in release
builds. Read more
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
Calls .tap_ref() only in debug builds, and is erased in release
builds. Read more
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Calls .tap_ref_mut() only in debug builds, and is erased in release
builds. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcepub fn to_owned(&self) -> T
pub fn to_owned(&self) -> T
Creates owned data from borrowed data, usually by cloning. Read more
sourcepub fn clone_into(&self, target: &mut T)
pub fn clone_into(&self, target: &mut T)
toowned_clone_into)Uses borrowed data to replace owned data, usually by cloning. Read more