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.BitVecas BITSTRING encoder.String/stras UTF8String encoder.i64,u64,i32,u32,i16,u16,BigInt,BigUintas INTEGER encoder. (u8is avoided because of confliction.)boolas BOOLEAN encoder.ObjectIdentifieras OBJECTT IDENTIFIER encoder.UTCTime/GeneralizedTimeas UTCTime/GeneralizedTime encoder.
Required Methods§
Sourcefn encode_der<'a>(&self, writer: DERWriter<'a>)
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
impl DEREncodable for bool
fn encode_der(&self, writer: DERWriter<'_>)
Source§impl DEREncodable for i16
impl DEREncodable for i16
fn encode_der(&self, writer: DERWriter<'_>)
Source§impl DEREncodable for i32
impl DEREncodable for i32
fn encode_der(&self, writer: DERWriter<'_>)
Source§impl DEREncodable for i64
impl DEREncodable for i64
fn encode_der(&self, writer: DERWriter<'_>)
Source§impl DEREncodable for str
impl DEREncodable for str
fn encode_der(&self, writer: DERWriter<'_>)
Source§impl DEREncodable for u16
impl DEREncodable for u16
fn encode_der(&self, writer: DERWriter<'_>)
Source§impl DEREncodable for u32
impl DEREncodable for u32
fn encode_der(&self, writer: DERWriter<'_>)
Source§impl DEREncodable for u64
impl DEREncodable for u64
fn encode_der(&self, writer: DERWriter<'_>)
Source§impl DEREncodable for ()
impl DEREncodable for ()
fn encode_der(&self, writer: DERWriter<'_>)
Source§impl DEREncodable for BitVec
Available on crate feature bit-vec only.
impl DEREncodable for BitVec
Available on crate feature
bit-vec only.fn encode_der(&self, writer: DERWriter<'_>)
Source§impl DEREncodable for BigInt
Available on crate feature num-bigint only.
impl DEREncodable for BigInt
Available on crate feature
num-bigint only.fn encode_der(&self, writer: DERWriter<'_>)
Source§impl DEREncodable for BigUint
Available on crate feature num-bigint only.
impl DEREncodable for BigUint
Available on crate feature
num-bigint only.fn encode_der(&self, writer: DERWriter<'_>)
Source§impl DEREncodable for String
impl DEREncodable for String
fn encode_der(&self, writer: DERWriter<'_>)
Source§impl DEREncodable for Vec<u8>
impl DEREncodable for Vec<u8>
fn encode_der(&self, writer: DERWriter<'_>)
Source§impl DEREncodable for [u8]
impl DEREncodable for [u8]
fn encode_der(&self, writer: DERWriter<'_>)
Source§impl<T0> DEREncodable for (T0,)where
T0: DEREncodable,
impl<T0> DEREncodable for (T0,)where
T0: DEREncodable,
fn encode_der(&self, writer: DERWriter<'_>)
Source§impl<T0, T1> DEREncodable for (T0, T1)where
T0: DEREncodable,
T1: DEREncodable,
impl<T0, T1> DEREncodable for (T0, T1)where
T0: DEREncodable,
T1: DEREncodable,
fn encode_der(&self, writer: DERWriter<'_>)
Source§impl<T0, T1, T2> DEREncodable for (T0, T1, T2)
impl<T0, T1, T2> DEREncodable for (T0, T1, T2)
fn encode_der(&self, writer: DERWriter<'_>)
Source§impl<T0, T1, T2, T3> DEREncodable for (T0, T1, T2, T3)
impl<T0, T1, T2, T3> DEREncodable for (T0, T1, T2, T3)
fn encode_der(&self, writer: DERWriter<'_>)
Source§impl<T0, T1, T2, T3, T4> DEREncodable for (T0, T1, T2, T3, T4)
impl<T0, T1, T2, T3, T4> DEREncodable for (T0, T1, T2, T3, T4)
fn encode_der(&self, writer: DERWriter<'_>)
Source§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,
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,
fn encode_der(&self, writer: DERWriter<'_>)
Source§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,
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,
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)where
T0: DEREncodable,
T1: DEREncodable,
T2: DEREncodable,
T3: DEREncodable,
T4: DEREncodable,
T5: DEREncodable,
T6: DEREncodable,
T7: DEREncodable,
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,
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)where
T0: DEREncodable,
T1: DEREncodable,
T2: DEREncodable,
T3: DEREncodable,
T4: DEREncodable,
T5: DEREncodable,
T6: DEREncodable,
T7: DEREncodable,
T8: DEREncodable,
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,
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)where
T0: DEREncodable,
T1: DEREncodable,
T2: DEREncodable,
T3: DEREncodable,
T4: DEREncodable,
T5: DEREncodable,
T6: DEREncodable,
T7: DEREncodable,
T8: DEREncodable,
T9: DEREncodable,
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,
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)where
T0: DEREncodable,
T1: DEREncodable,
T2: DEREncodable,
T3: DEREncodable,
T4: DEREncodable,
T5: DEREncodable,
T6: DEREncodable,
T7: DEREncodable,
T8: DEREncodable,
T9: DEREncodable,
T10: DEREncodable,
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,
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)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,
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,
fn encode_der(&self, writer: DERWriter<'_>)
Source§impl<T> DEREncodable for &Twhere
T: DEREncodable + ?Sized,
impl<T> DEREncodable for &Twhere
T: DEREncodable + ?Sized,
fn encode_der(&self, writer: DERWriter<'_>)
Source§impl<T> DEREncodable for [T]where
T: DEREncodable,
impl<T> DEREncodable for [T]where
T: DEREncodable,
fn encode_der(&self, writer: DERWriter<'_>)
Source§impl<T> DEREncodable for Vec<T>where
T: DEREncodable,
impl<T> DEREncodable for Vec<T>where
T: DEREncodable,
fn encode_der(&self, writer: DERWriter<'_>)
Implementors§
impl DEREncodable for GeneralizedTime
Available on crate feature
time only.impl DEREncodable for ObjectIdentifier
impl DEREncodable for UTCTime
Available on crate feature
time only.