diff --git a/src/lib.rs b/src/lib.rs index e91bb48..33baad4 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -401,7 +401,7 @@ pub enum ASN1EncodeErr { impl fmt::Display for ASN1EncodeErr { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - f.write_str(self.description()) + f.write_str(&self.to_string()) } } @@ -1684,4 +1684,21 @@ mod tests { ]))))])]), ); } + + #[test] + fn encode_unknowns() { + fn encode_structure(bufs: &[Vec]) -> Vec { + let mut body = Vec::new(); + for (i, buf) in bufs.iter().enumerate() { + let mut der = to_der(&ASN1Block::Unknown(ASN1Class::ContextSpecific, false, 0, BigUint::from_usize(i).unwrap(), buf.to_vec())).unwrap(); + body.append(&mut der); + } + let block = ASN1Block::Unknown(ASN1Class::ContextSpecific, true, 0, BigUint::from_u8(0).unwrap(), body); + to_der(&block).unwrap() + } + + let decoded = from_der(&encode_structure(&vec![vec![0]])).unwrap(); + let expected = [ASN1Block::Unknown(ASN1Class::ContextSpecific, true, 0, BigUint::from_u8(0).unwrap(), vec![128, 1, 0])]; + assert_eq!(decoded, expected); + } }