Struct yasna::BERReaderSet [−][src]
pub struct BERReaderSet<'a, 'b> where
'a: 'b, { /* fields omitted */ }
A reader object for a set of BER/DER-encoded ASN.1 data.
The main source of this object is the read_set
method from
BERReader
.
Examples
use yasna; use yasna::tags::{TAG_INTEGER,TAG_BOOLEAN}; let data = &[49, 6, 1, 1, 255, 2, 1, 10]; let asn = yasna::parse_der(data, |reader| { reader.read_set(|reader| { let i = reader.next(&[TAG_INTEGER])?.read_i64()?; let b = reader.next(&[TAG_BOOLEAN])?.read_bool()?; return Ok((i, b)); }) }).unwrap(); assert_eq!(asn, (10, true));
Implementations
impl<'a, 'b> BERReaderSet<'a, 'b>
[src]
impl<'a, 'b> BERReaderSet<'a, 'b>
[src]pub fn mode(&self) -> BERMode
[src]
Tells which format we are parsing, BER or DER.
pub fn next<'c>(&'c mut self, tag_hint: &[Tag]) -> ASN1Result<BERReader<'a, 'c>>
[src]
Generates a new BERReader
.
This method needs tag_hint
to determine the position of the data.
pub fn read_optional<T, F>(
&mut self,
tag_hint: &[Tag],
callback: F
) -> ASN1Result<Option<T>> where
F: for<'c> FnOnce(BERReader<'a, 'c>) -> ASN1Result<T>,
[src]
&mut self,
tag_hint: &[Tag],
callback: F
) -> ASN1Result<Option<T>> where
F: for<'c> FnOnce(BERReader<'a, 'c>) -> ASN1Result<T>,
If there is a set element with a tag in tag_hint
, reads an ASN.1
value from that element and returns Some(_)
.
Otherwise, returns None
.
Used to parse OPTIONAL elements.
Examples
use yasna; use yasna::tags::*; let data = &[49, 3, 1, 1, 255]; let asn = yasna::parse_der(data, |reader| { reader.read_set(|reader| { let i = reader.read_optional(&[TAG_INTEGER], |reader| { reader.read_i64() })?; let b = reader.next(&[TAG_BOOLEAN])?.read_bool()?; return Ok((i, b)); }) }).unwrap(); assert_eq!(asn, (None, true));
pub fn read_default<T, F>(
&mut self,
tag_hint: &[Tag],
default: T,
callback: F
) -> ASN1Result<T> where
F: for<'c> FnOnce(BERReader<'a, 'c>) -> ASN1Result<T>,
T: Eq,
[src]
&mut self,
tag_hint: &[Tag],
default: T,
callback: F
) -> ASN1Result<T> where
F: for<'c> FnOnce(BERReader<'a, 'c>) -> ASN1Result<T>,
T: Eq,
Similar to read_optional
, but uses default
if it fails.
T: Eq
is required because it fails in DER mode if the read value
is equal to default
.
Used to parse DEFAULT elements.
Examples
use yasna; use yasna::tags::*; let data = &[49, 3, 1, 1, 255]; let asn = yasna::parse_der(data, |reader| { reader.read_set(|reader| { let i = reader.read_default(&[TAG_INTEGER], 10, |reader| { reader.read_i64() })?; let b = reader.next(&[TAG_BOOLEAN])?.read_bool()?; return Ok((i, b)); }) }).unwrap(); assert_eq!(asn, (10, true));
Trait Implementations
Auto Trait Implementations
impl<'a, 'b> RefUnwindSafe for BERReaderSet<'a, 'b>
impl<'a, 'b> RefUnwindSafe for BERReaderSet<'a, 'b>
impl<'a, 'b> Send for BERReaderSet<'a, 'b>
impl<'a, 'b> Send for BERReaderSet<'a, 'b>
impl<'a, 'b> Sync for BERReaderSet<'a, 'b>
impl<'a, 'b> Sync for BERReaderSet<'a, 'b>
impl<'a, 'b> Unpin for BERReaderSet<'a, 'b> where
'a: 'b,
impl<'a, 'b> Unpin for BERReaderSet<'a, 'b> where
'a: 'b,
impl<'a, 'b> !UnwindSafe for BERReaderSet<'a, 'b>
impl<'a, 'b> !UnwindSafe for BERReaderSet<'a, 'b>