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§

source

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.

Implementations on Foreign Types§

source§

impl BERDecodable for bool

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl BERDecodable for i16

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl BERDecodable for i32

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl BERDecodable for i64

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl BERDecodable for u16

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl BERDecodable for u32

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl BERDecodable for u64

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl BERDecodable for ()

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl BERDecodable for BitVec

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl BERDecodable for BigInt

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl BERDecodable for BigUint

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl BERDecodable for String

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl BERDecodable for Vec<u8>

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl<T0> BERDecodable for (T0,)
where T0: BERDecodable,

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl<T0, T1> BERDecodable for (T0, T1)
where T0: BERDecodable, T1: BERDecodable,

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl<T0, T1, T2> BERDecodable for (T0, T1, T2)

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl<T0, T1, T2, T3> BERDecodable for (T0, T1, T2, T3)

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl<T0, T1, T2, T3, T4> BERDecodable for (T0, T1, T2, T3, T4)

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl<T0, T1, T2, T3, T4, T5> BERDecodable for (T0, T1, T2, T3, T4, T5)

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl<T0, T1, T2, T3, T4, T5, T6> BERDecodable for (T0, T1, T2, T3, T4, T5, T6)

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl<T0, T1, T2, T3, T4, T5, T6, T7> BERDecodable for (T0, T1, T2, T3, T4, T5, T6, T7)

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8> BERDecodable for (T0, T1, T2, T3, T4, T5, T6, T7, T8)

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> BERDecodable for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10> BERDecodable for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10)

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11> BERDecodable for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11)

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

source§

impl<T> BERDecodable for Vec<T>
where T: BERDecodable,

source§

fn decode_ber(reader: BERReader<'_, '_>) -> ASN1Result<Self>

Implementors§