From 00de85f833eb3d0de562f3ae22e4e6386dba915d Mon Sep 17 00:00:00 2001 From: Philip Ye Date: Mon, 22 Jul 2024 01:28:41 +1200 Subject: [PATCH] Fix encoding of optional TaggedImplicit object --- src/asn1_types/tagged/implicit.rs | 2 +- tests/to_der.rs | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/asn1_types/tagged/implicit.rs b/src/asn1_types/tagged/implicit.rs index 01e6ae5..2189b6b 100644 --- a/src/asn1_types/tagged/implicit.rs +++ b/src/asn1_types/tagged/implicit.rs @@ -130,7 +130,7 @@ where } fn write_der_content(&self, writer: &mut dyn std::io::Write) -> SerializeResult { - self.inner.write_der(writer) + self.inner.write_der_content(writer) } } diff --git a/tests/to_der.rs b/tests/to_der.rs index 05c523f..62f09c6 100644 --- a/tests/to_der.rs +++ b/tests/to_der.rs @@ -482,6 +482,17 @@ fn to_der_tagged_implicit() { assert!(tagged.eq(&t2)); } +#[test] +fn to_der_tagged_implicit_optional() { + // TaggedValue API + let tagged = Some(TaggedValue::implicit(Integer::from(2))); + let v = tagged.to_der_vec().expect("serialization failed"); + assert_eq!(&v, &hex!("81 01 02")); + let (_, t2) = OptTaggedImplicit::::from_der(&v) + .expect("decoding serialized object failed"); + assert!(tagged.eq(&t2)); +} + #[test] fn to_der_teletexstring() { test_simple_string!(TeletexString, "abcdef");