Struct yasna::BERReaderSeq
source · pub struct BERReaderSeq<'a, 'b>where
'a: 'b,{ /* private fields */ }
Expand description
A reader object for a sequence of BER/DER-encoded ASN.1 data.
The main source of this object is the read_sequence
method from
BERReader
.
Examples
use yasna;
let data = &[48, 6, 2, 1, 10, 1, 1, 255];
let asn = yasna::parse_der(data, |reader| {
reader.read_sequence(|reader| {
let i = reader.next().read_i64()?;
let b = reader.next().read_bool()?;
return Ok((i, b));
})
}).unwrap();
assert_eq!(asn, (10, true));
Implementations§
source§impl<'a, 'b> BERReaderSeq<'a, 'b>
impl<'a, 'b> BERReaderSeq<'a, 'b>
sourcepub fn read_optional<T, F>(&mut self, callback: F) -> ASN1Result<Option<T>>where
F: for<'c> FnOnce(BERReader<'a, 'c>) -> ASN1Result<T>,
pub fn read_optional<T, F>(&mut self, callback: F) -> ASN1Result<Option<T>>where F: for<'c> FnOnce(BERReader<'a, 'c>) -> ASN1Result<T>,
Tries to read an ASN.1 value. If it fails at the first tag,
it doesn’t consume buffer and returns None
.
Used to parse OPTIONAL elements.
Examples
use yasna;
let data = &[48, 3, 1, 1, 255];
let asn = yasna::parse_der(data, |reader| {
reader.read_sequence(|reader| {
let i = reader.read_optional(|reader| {
reader.read_i64()
})?;
let b = reader.next().read_bool()?;
return Ok((i, b));
})
}).unwrap();
assert_eq!(asn, (None, true));
sourcepub fn read_default<T, F>(&mut self, default: T, callback: F) -> ASN1Result<T>where
F: for<'c> FnOnce(BERReader<'a, 'c>) -> ASN1Result<T>,
T: Eq,
pub fn read_default<T, F>(&mut self, 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;
let data = &[48, 3, 1, 1, 255];
let asn = yasna::parse_der(data, |reader| {
reader.read_sequence(|reader| {
let i = reader.read_default(10, |reader| {
reader.read_i64()
})?;
let b = reader.next().read_bool()?;
return Ok((i, b));
})
}).unwrap();
assert_eq!(asn, (10, true));