Skip to content

pkcs8 & pkcs1 should not have duplicate implementations for Decodeable/Encodeable #419

@Scarjit

Description

@Scarjit

This is related to #410.

The crate could use the Integer proc macro, if pkcs8's Version enum get's a repr attribute.

This would remove this duplicate code:

pkcs1

impl Decodable<'_> for Version {
fn decode(decoder: &mut Decoder<'_>) -> der::Result<Self> {
Version::try_from(u8::decode(decoder)?).map_err(|_| Self::TAG.value_error())
}
}
impl Encodable for Version {
fn encoded_len(&self) -> der::Result<der::Length> {
der::Length::ONE.for_tlv()
}
fn encode(&self, encoder: &mut Encoder<'_>) -> der::Result<()> {
u8::from(*self).encode(encoder)
}
}
impl FixedTag for Version {
const TAG: Tag = Tag::Integer;
}

pkcs8

impl Decodable<'_> for Version {
fn decode(decoder: &mut Decoder<'_>) -> der::Result<Self> {
Version::try_from(u8::decode(decoder)?).map_err(|_| Self::TAG.value_error())
}
}
impl Encodable for Version {
fn encoded_len(&self) -> der::Result<der::Length> {
der::Length::from(1u8).for_tlv()
}
fn encode(&self, encoder: &mut Encoder<'_>) -> der::Result<()> {
u8::from(*self).encode(encoder)
}
}

impl FixedTag for Version {
const TAG: Tag = Tag::Integer;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions