RustCrypto / formats

Cryptography-related format encoders/decoders: DER, PEM, PKCS, PKIX
243 stars 129 forks source link

der: Cannot invoke `Encode::encoded_len()` or `Encode::encode()` on `str` #1365

Closed abonander closed 2 months ago

abonander commented 7 months ago

str does not implement Tagged despite implementing FixedTag because the blanket impl implicitly requires Sized:

impl<T: FixedTag> Tagged for T { 
    fn tag(&self) -> Tag {
        T::TAG
    }
}

The impl should look like this instead:

impl<T: FixedTag + ?Sized> Tagged for T { 
    fn tag(&self) -> Tag {
        T::TAG
    }
}

The blanket impl of Encode has the same problem:

impl<T> Encode for T
where
    T: EncodeValue + Tagged,
{
    // ...
}

It should look like this:

impl<T> Encode for T
where
    T: EncodeValue + Tagged + ?Sized,
{
    // ...
}

Without this, it's impossible to invoke methods of Encode on str.