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
use ::{ Asn1DerError, types::{ FromDerObject, IntoDerObject }, der::{ DerObject, DerTag} };
impl FromDerObject for bool {
fn from_der_object(der_object: DerObject) -> Result<Self, Asn1DerError> {
if der_object.tag != DerTag::Boolean { return Err(Asn1DerError::InvalidTag) }
match der_object.value.data.as_slice() {
&[0x00u8] => Ok(false),
&[0xffu8] => Ok(true),
_ => return Err(Asn1DerError::InvalidEncoding)
}
}
}
impl IntoDerObject for bool {
fn into_der_object(self) -> DerObject {
DerObject::new(DerTag::Boolean, match self {
true => vec![0xffu8],
false => vec![0x00u8]
}.into())
}
fn serialized_len(&self) -> usize {
DerObject::compute_serialized_len(1)
}
}