summaryrefslogtreecommitdiffstats
path: root/vendor/der/src/encode.rs
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/der/src/encode.rs')
-rw-r--r--vendor/der/src/encode.rs29
1 files changed, 19 insertions, 10 deletions
diff --git a/vendor/der/src/encode.rs b/vendor/der/src/encode.rs
index 51fc13d8b..d480b7bbd 100644
--- a/vendor/der/src/encode.rs
+++ b/vendor/der/src/encode.rs
@@ -3,7 +3,7 @@
use crate::{Header, Length, Result, SliceWriter, Tagged, Writer};
#[cfg(feature = "alloc")]
-use {alloc::vec::Vec, core::iter};
+use {alloc::boxed::Box, alloc::vec::Vec, core::iter};
#[cfg(feature = "pem")]
use {
@@ -24,7 +24,7 @@ pub trait Encode {
fn encoded_len(&self) -> Result<Length>;
/// Encode this value as ASN.1 DER using the provided [`Writer`].
- fn encode(&self, encoder: &mut dyn Writer) -> Result<()>;
+ fn encode(&self, encoder: &mut impl Writer) -> Result<()>;
/// Encode this value to the provided byte slice, returning a sub-slice
/// containing the encoded message.
@@ -37,7 +37,6 @@ pub trait Encode {
/// Encode this message as ASN.1 DER, appending it to the provided
/// byte vector.
#[cfg(feature = "alloc")]
- #[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
fn encode_to_vec(&self, buf: &mut Vec<u8>) -> Result<Length> {
let expected_len = usize::try_from(self.encoded_len()?)?;
buf.reserve(expected_len);
@@ -58,10 +57,9 @@ pub trait Encode {
actual_len.try_into()
}
- /// Serialize this message as a byte vector.
+ /// Encode this type as DER, returning a byte vector.
#[cfg(feature = "alloc")]
- #[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
- fn to_vec(&self) -> Result<Vec<u8>> {
+ fn to_der(&self) -> Result<Vec<u8>> {
let mut buf = Vec::new();
self.encode_to_vec(&mut buf)?;
Ok(buf)
@@ -78,7 +76,7 @@ where
}
/// Encode this value as ASN.1 DER using the provided [`Writer`].
- fn encode(&self, writer: &mut dyn Writer) -> Result<()> {
+ fn encode(&self, writer: &mut impl Writer) -> Result<()> {
self.header()?.encode(writer)?;
self.encode_value(writer)
}
@@ -89,14 +87,12 @@ where
/// This trait is automatically impl'd for any type which impls both
/// [`Encode`] and [`PemLabel`].
#[cfg(feature = "pem")]
-#[cfg_attr(docsrs, doc(cfg(feature = "pem")))]
pub trait EncodePem: Encode + PemLabel {
/// Try to encode this type as PEM.
fn to_pem(&self, line_ending: LineEnding) -> Result<String>;
}
#[cfg(feature = "pem")]
-#[cfg_attr(docsrs, doc(cfg(feature = "pem")))]
impl<T: Encode + PemLabel> EncodePem for T {
fn to_pem(&self, line_ending: LineEnding) -> Result<String> {
let der_len = usize::try_from(self.encoded_len()?)?;
@@ -129,5 +125,18 @@ pub trait EncodeValue {
/// Encode value (sans [`Tag`]+[`Length`] header) as ASN.1 DER using the
/// provided [`Writer`].
- fn encode_value(&self, encoder: &mut dyn Writer) -> Result<()>;
+ fn encode_value(&self, encoder: &mut impl Writer) -> Result<()>;
+}
+
+#[cfg(feature = "alloc")]
+impl<T> EncodeValue for Box<T>
+where
+ T: EncodeValue,
+{
+ fn value_len(&self) -> Result<Length> {
+ T::value_len(self)
+ }
+ fn encode_value(&self, writer: &mut impl Writer) -> Result<()> {
+ T::encode_value(self, writer)
+ }
}