Skip to content

Commit

Permalink
der: allow all blanket impls on ?Sized types
Browse files Browse the repository at this point in the history
This fixes the `Tagged` and `Encode` trait impls on `str`, for example.

Closes #1365
  • Loading branch information
tarcieri committed Jul 24, 2024
1 parent 97ead54 commit 1b06e36
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions der/src/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ pub trait Encode {

impl<T> Encode for T
where
T: EncodeValue + Tagged,
T: EncodeValue + Tagged + ?Sized,
{
/// Compute the length of this value in bytes when encoded as ASN.1 DER.
fn encoded_len(&self) -> Result<Length> {
Expand Down Expand Up @@ -109,7 +109,10 @@ pub trait EncodePem: Encode + PemLabel {
}

#[cfg(feature = "pem")]
impl<T: Encode + PemLabel> EncodePem for T {
impl<T> EncodePem for T
where
T: Encode + PemLabel + ?Sized,
{
fn to_pem(&self, line_ending: LineEnding) -> Result<String> {
let der_len = usize::try_from(self.encoded_len()?)?;
let pem_len = pem::encapsulated_len(Self::PEM_LABEL, line_ending, der_len)?;
Expand Down
2 changes: 1 addition & 1 deletion der/src/tag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ pub trait Tagged {
}

/// Types which are [`FixedTag`] always have a known [`Tag`] type.
impl<T: FixedTag> Tagged for T {
impl<T: FixedTag + ?Sized> Tagged for T {
fn tag(&self) -> Tag {
T::TAG
}
Expand Down

0 comments on commit 1b06e36

Please sign in to comment.