Trait yasna::BERDecodable
source · pub trait BERDecodable: Sized {
// Required method
fn decode_ber<'a, 'b>(reader: BERReader<'a, 'b>) -> ASN1Result<Self>;
}
Expand description
Types decodable in BER.
§Examples
use yasna;
let asn : i64 = yasna::decode_der(&[2, 3, 0, 255, 255]).unwrap();
assert_eq!(asn, 65535);
§Limitations
Rust types don’t correspond to ASN.1 types one-to-one. Not all kinds
of ASN.1 types can be decoded via default BERDecodable
implementation.
If you want to decode ASN.1, you may implement BERDecodable
for your
own types or use parse_der
/
parse_ber
.
§Default implementations
- The decoder for
Vec<T>
is implemented as SEQUENCE OF decoder. ()
as NULL decoder.- Tuples (except
()
) as SEQUENCE decoder. Vec<u8>
as OCTETSTRING decoder.BitVec
as BITSTRING decoder.String
as UTF8String decoder.i64
,u64
,i32
,u32
,i16
,u16
,BigInt
,BigUint
as INTEGER decoder. (u8
is avoided because of confliction.)bool
as BOOLEAN decoder.ObjectIdentifier
as OBJECTT IDENTIFIER decoder.UTCTime
/GeneralizedTime
as UTCTime/GeneralizedTime decoder.
Required Methods§
sourcefn decode_ber<'a, 'b>(reader: BERReader<'a, 'b>) -> ASN1Result<Self>
fn decode_ber<'a, 'b>(reader: BERReader<'a, 'b>) -> ASN1Result<Self>
Reads an ASN.1 value from BERReader
and converts it to Self
.
§Examples
use yasna::{BERDecodable,BERReader,ASN1Result};
struct Entry {
name: String,
age: i64,
}
impl BERDecodable for Entry {
fn decode_ber(reader: BERReader) -> ASN1Result<Self> {
reader.read_sequence(|reader| {
let name = reader.next().read_visible_string()?;
let age = reader.next().read_i64()?;
return Ok(Entry {
name: name,
age: age,
});
})
}
}
fn main() {
let entry : Entry = yasna::decode_der(
&[48, 9, 26, 4, 74, 111, 104, 110, 2, 1, 32]).unwrap();
assert_eq!(entry.name, "John");
assert_eq!(entry.age, 32);
}
Object Safety§
This trait is not object safe.