Trait yasna::DEREncodable

source ·
pub trait DEREncodable {
    // Required method
    fn encode_der<'a>(&self, writer: DERWriter<'a>);
}
Expand description

Types encodable in DER.

§Examples

use yasna;
let der = yasna::encode_der::<i64>(&65535);
assert_eq!(&der, &[2, 3, 0, 255, 255]);

§Limitations

Rust types don’t correspond to ASN.1 types one-to-one. Not all kinds of ASN.1 types can be encoded via default DEREncodable implementation.

If you want to encode ASN.1, you may implement DEREncodable for your own types or use construct_der.

§Default implementations

  • The encoder for Vec<T>/[T] is implemented as SEQUENCE OF encoder.
  • () as NULL encoder.
  • Tuples (except ()) as SEQUENCE encoder.
  • Vec<u8>/[u8] as OCTETSTRING encoder.
  • BitVec as BITSTRING encoder.
  • String/str as UTF8String encoder.
  • i64, u64, i32, u32, i16, u16, BigInt, BigUint as INTEGER encoder. (u8 is avoided because of confliction.)
  • bool as BOOLEAN encoder.
  • ObjectIdentifier as OBJECTT IDENTIFIER encoder.
  • UTCTime/GeneralizedTime as UTCTime/GeneralizedTime encoder.

Required Methods§

source

fn encode_der<'a>(&self, writer: DERWriter<'a>)

Writes the value as an DER-encoded ASN.1 value.

§Examples
use yasna::{DEREncodable,DERWriter};
struct Entry {
    name: String,
    age: i64,
}

impl DEREncodable for Entry {
    fn encode_der(&self, writer: DERWriter) {
        writer.write_sequence(|writer| {
            writer.next().write_visible_string(&self.name);
            writer.next().write_i64(self.age);
        })
    }
}
fn main() {
    let entry = Entry {
        name: String::from("John"),
        age: 32,
    };
    let der = yasna::encode_der(&entry);
    assert_eq!(&der, &[48, 9, 26, 4, 74, 111, 104, 110, 2, 1, 32]);
}

Implementations on Foreign Types§

source§

impl DEREncodable for bool

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

impl DEREncodable for i16

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

impl DEREncodable for i32

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

impl DEREncodable for i64

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

impl DEREncodable for str

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

impl DEREncodable for u16

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

impl DEREncodable for u32

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

impl DEREncodable for u64

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

impl DEREncodable for ()

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

impl DEREncodable for BitVec

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

impl DEREncodable for BigInt

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

impl DEREncodable for BigUint

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

impl DEREncodable for String

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

impl DEREncodable for Vec<u8>

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

impl DEREncodable for [u8]

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

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

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

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

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

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

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

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

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

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

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

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

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

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

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

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

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

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

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

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

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

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

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

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

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

impl<T> DEREncodable for &T
where T: DEREncodable + ?Sized,

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

impl<T> DEREncodable for [T]
where T: DEREncodable,

source§

fn encode_der(&self, writer: DERWriter<'_>)

source§

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

source§

fn encode_der(&self, writer: DERWriter<'_>)

Implementors§