[][src]Trait yasna::DEREncodable

pub trait DEREncodable {
    fn encode_der<'a>(&self, writer: DERWriter<'a>);
}

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

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]);
}
Loading content...

Implementations on Foreign Types

impl<T> DEREncodable for Vec<T> where
    T: DEREncodable
[src]

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

impl DEREncodable for i64[src]

impl DEREncodable for u64[src]

impl DEREncodable for i32[src]

impl DEREncodable for u32[src]

impl DEREncodable for i16[src]

impl DEREncodable for u16[src]

impl DEREncodable for BigInt[src]

impl DEREncodable for BigUint[src]

impl DEREncodable for bool[src]

impl DEREncodable for BitVec[src]

impl DEREncodable for Vec<u8>[src]

impl DEREncodable for [u8][src]

impl DEREncodable for String[src]

impl DEREncodable for str[src]

impl DEREncodable for ()[src]

impl<T0> DEREncodable for (T0,) where
    T0: DEREncodable
[src]

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

impl<T0, T1, T2> DEREncodable for (T0, T1, T2) where
    T0: DEREncodable,
    T1: DEREncodable,
    T2: DEREncodable
[src]

impl<T0, T1, T2, T3> DEREncodable for (T0, T1, T2, T3) where
    T0: DEREncodable,
    T1: DEREncodable,
    T2: DEREncodable,
    T3: DEREncodable
[src]

impl<T0, T1, T2, T3, T4> DEREncodable for (T0, T1, T2, T3, T4) where
    T0: DEREncodable,
    T1: DEREncodable,
    T2: DEREncodable,
    T3: DEREncodable,
    T4: DEREncodable
[src]

impl<T0, T1, T2, T3, T4, T5> DEREncodable for (T0, T1, T2, T3, T4, T5) where
    T0: DEREncodable,
    T1: DEREncodable,
    T2: DEREncodable,
    T3: DEREncodable,
    T4: DEREncodable,
    T5: DEREncodable
[src]

impl<T0, T1, T2, T3, T4, T5, T6> DEREncodable for (T0, T1, T2, T3, T4, T5, T6) where
    T0: DEREncodable,
    T1: DEREncodable,
    T2: DEREncodable,
    T3: DEREncodable,
    T4: DEREncodable,
    T5: DEREncodable,
    T6: DEREncodable
[src]

impl<T0, T1, T2, T3, T4, T5, T6, T7> DEREncodable for (T0, T1, T2, T3, T4, T5, T6, T7) where
    T0: DEREncodable,
    T1: DEREncodable,
    T2: DEREncodable,
    T3: DEREncodable,
    T4: DEREncodable,
    T5: DEREncodable,
    T6: DEREncodable,
    T7: DEREncodable
[src]

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8> DEREncodable for (T0, T1, T2, T3, T4, T5, T6, T7, T8) where
    T0: DEREncodable,
    T1: DEREncodable,
    T2: DEREncodable,
    T3: DEREncodable,
    T4: DEREncodable,
    T5: DEREncodable,
    T6: DEREncodable,
    T7: DEREncodable,
    T8: DEREncodable
[src]

impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> DEREncodable for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) where
    T0: DEREncodable,
    T1: DEREncodable,
    T2: DEREncodable,
    T3: DEREncodable,
    T4: DEREncodable,
    T5: DEREncodable,
    T6: DEREncodable,
    T7: DEREncodable,
    T8: DEREncodable,
    T9: DEREncodable
[src]

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) where
    T0: DEREncodable,
    T1: DEREncodable,
    T2: DEREncodable,
    T3: DEREncodable,
    T4: DEREncodable,
    T5: DEREncodable,
    T6: DEREncodable,
    T7: DEREncodable,
    T8: DEREncodable,
    T9: DEREncodable,
    T10: DEREncodable
[src]

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) where
    T0: DEREncodable,
    T1: DEREncodable,
    T2: DEREncodable,
    T3: DEREncodable,
    T4: DEREncodable,
    T5: DEREncodable,
    T6: DEREncodable,
    T7: DEREncodable,
    T8: DEREncodable,
    T9: DEREncodable,
    T10: DEREncodable,
    T11: DEREncodable
[src]

Loading content...

Implementors

impl DEREncodable for GeneralizedTime[src]

impl DEREncodable for ObjectIdentifier[src]

impl DEREncodable for UTCTime[src]

Loading content...