Skip to content

Commit 705400a

Browse files
authored
der: support Cow<[u8]> in derive(Sequence) (#1850)
1 parent fd18b42 commit 705400a

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

der/src/asn1/octet_string.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,7 @@ pub use self::allocating::OctetString;
160160
mod allocating {
161161
use super::*;
162162
use crate::referenced::*;
163+
use alloc::borrow::Cow;
163164
use alloc::vec::Vec;
164165

165166
/// ASN.1 `OCTET STRING` type: owned form..
@@ -282,6 +283,22 @@ mod allocating {
282283
}
283284
}
284285

286+
impl<'a> TryFrom<&'a Cow<'a, [u8]>> for OctetStringRef<'a> {
287+
type Error = Error;
288+
289+
fn try_from(byte_slice: &'a Cow<'a, [u8]>) -> Result<Self, Error> {
290+
OctetStringRef::new(byte_slice)
291+
}
292+
}
293+
294+
impl<'a> TryFrom<OctetStringRef<'a>> for Cow<'a, [u8]> {
295+
type Error = Error;
296+
297+
fn try_from(octet_string: OctetStringRef<'a>) -> Result<Self, Self::Error> {
298+
Ok(Cow::Borrowed(octet_string.as_bytes()))
299+
}
300+
}
301+
285302
// Implement by hand because the derive would create invalid values.
286303
// Use the constructor to create a valid value.
287304
#[cfg(feature = "arbitrary")]

0 commit comments

Comments
 (0)