diff --git a/der/src/referenced.rs b/der/src/referenced.rs index bb920db3a..b0c8f0325 100644 --- a/der/src/referenced.rs +++ b/der/src/referenced.rs @@ -45,3 +45,25 @@ where self.as_ref().map(|o| o.ref_to_owned()) } } + +#[cfg(feature = "alloc")] +mod allocating { + use super::{OwnedToRef, RefToOwned}; + use alloc::boxed::Box; + + impl<'a> RefToOwned<'a> for &'a [u8] { + type Owned = Box<[u8]>; + + fn ref_to_owned(&self) -> Self::Owned { + Box::from(*self) + } + } + + impl OwnedToRef for Box<[u8]> { + type Borrowed<'a> = &'a [u8]; + + fn owned_to_ref(&self) -> Self::Borrowed<'_> { + self.as_ref() + } + } +}