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,