From a925293ca7dbbdd2b5a0b3b5b81d12ea6c8fd159 Mon Sep 17 00:00:00 2001 From: Pierre Chifflier Date: Fri, 23 Feb 2024 14:04:11 +0100 Subject: [PATCH] Provide implementations for Option::from_der Since Any does not implement `Tagged`, a separate implementation is required. --- src/asn1_types/optional.rs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/src/asn1_types/optional.rs b/src/asn1_types/optional.rs index 4aa31ae..3386092 100644 --- a/src/asn1_types/optional.rs +++ b/src/asn1_types/optional.rs @@ -27,6 +27,18 @@ where } } +impl<'a> FromBer<'a> for Option> { + fn from_ber(bytes: &'a [u8]) -> ParseResult { + if bytes.is_empty() { + return Ok((bytes, None)); + } + match Any::from_ber(bytes) { + Ok((rem, t)) => Ok((rem, Some(t))), + Err(e) => Err(e), + } + } +} + impl<'a, T> FromDer<'a> for Option where T: FromDer<'a>, @@ -49,6 +61,18 @@ where } } +impl<'a> FromDer<'a> for Option> { + fn from_der(bytes: &'a [u8]) -> ParseResult { + if bytes.is_empty() { + return Ok((bytes, None)); + } + match Any::from_der(bytes) { + Ok((rem, t)) => Ok((rem, Some(t))), + Err(e) => Err(e), + } + } +} + impl CheckDerConstraints for Option where T: CheckDerConstraints,