Skip to content

Commit

Permalink
Provide implementations for Option<Any>::from_der
Browse files Browse the repository at this point in the history
Since Any does not implement `Tagged`, a separate implementation is required.
  • Loading branch information
chifflier committed Feb 23, 2024
1 parent a20e5f7 commit a925293
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/asn1_types/optional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ where
}
}

impl<'a> FromBer<'a> for Option<Any<'a>> {
fn from_ber(bytes: &'a [u8]) -> ParseResult<Self> {
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<T>
where
T: FromDer<'a>,
Expand All @@ -49,6 +61,18 @@ where
}
}

impl<'a> FromDer<'a> for Option<Any<'a>> {
fn from_der(bytes: &'a [u8]) -> ParseResult<Self> {
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<T> CheckDerConstraints for Option<T>
where
T: CheckDerConstraints,
Expand Down

0 comments on commit a925293

Please sign in to comment.