Skip to content

der_derive: derive(Choice) should implement DecodeValue #1796

@dishmaker

Description

@dishmaker

Currently, Choice automatically derives Decode.

But DecodeValue can be derived the same way.

For example, in x509-cert the following DecodeValue for DirectoryString is redundant.

impl<'a> der::DecodeValue<'a> for DirectoryString {
type Error = der::Error;
fn decode_value<R: Reader<'a>>(reader: &mut R, header: Header) -> Result<Self, Self::Error> {
match header.tag {
PrintableString::TAG => {
PrintableString::decode_value(reader, header).map(Self::PrintableString)
}
TeletexString::TAG => {
TeletexString::decode_value(reader, header).map(Self::TeletexString)
}
String::TAG => String::decode_value(reader, header).map(Self::Utf8String),
actual => Err(der::ErrorKind::TagUnexpected {
expected: None,
actual,
}
.into()),
}
}
}

I think Decode should use DecodeValue in derive(Choice).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions