1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
use ::{ Asn1DerError, der::DerObject };
mod boolean;
mod integer;
mod null;
mod octet_string;
mod sequence;
mod utf8_string;
pub use self::integer::U128Ext;
pub trait FromDerObject where Self: Sized {
fn from_der_object(der_object: DerObject) -> Result<Self, Asn1DerError>;
fn deserialize<'a>(source: impl Iterator<Item = &'a u8>) -> Result<Self, Asn1DerError> {
Self::from_der_object(DerObject::deserialize(source)?)
}
}
pub trait IntoDerObject where Self: Sized {
fn into_der_object(self) -> DerObject;
fn serialized_len(&self) -> usize;
fn serialize<'a>(self, buf: impl Iterator<Item = &'a mut u8>) -> Result<usize, Asn1DerError> {
DerObject::serialize(&self.into_der_object(), buf)
}
}
impl FromDerObject for DerObject {
fn from_der_object(der_object: DerObject) -> Result<Self, Asn1DerError> {
Ok(der_object)
}
}
impl IntoDerObject for DerObject {
fn into_der_object(self) -> DerObject {
self
}
fn serialized_len(&self) -> usize {
self.serialized_len()
}
}