Skip to content

der: fix BMPString compatibility in derive macros #1793

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion der/src/asn1/bmp_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

use crate::{
BytesOwned, DecodeValue, EncodeValue, Error, FixedTag, Header, Length, Reader, Result, Tag,
Writer,
Writer, ord::OrdIsValueOrd,
};
use alloc::{boxed::Box, vec::Vec};
use core::{fmt, str::FromStr};
Expand Down Expand Up @@ -119,6 +119,18 @@ impl FromStr for BmpString {
}
}

impl OrdIsValueOrd for BmpString {}

/// Hack for simplifying the custom derive use case,
/// as there is no `BmpStringRef` yet.
impl From<&BmpString> for BmpString {
fn from(value: &BmpString) -> Self {
BmpString {
bytes: value.bytes.clone(),
}
}
}

impl fmt::Debug for BmpString {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!(f, "BmpString(\"{}\")", self)
Expand Down
7 changes: 7 additions & 0 deletions der_derive/src/asn1_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ pub(crate) enum Asn1Type {

/// ASN.1 `UTF8String`.
Utf8String,

/// ASN.1 `BMPString`.
BmpString,
}

impl Asn1Type {
Expand All @@ -49,6 +52,7 @@ impl Asn1Type {
Asn1Type::VideotexString => quote!(::der::Tag::VideotexString),
Asn1Type::UtcTime => quote!(::der::Tag::UtcTime),
Asn1Type::Utf8String => quote!(::der::Tag::Utf8String),
Asn1Type::BmpString => quote!(::der::Tag::BmpString),
}
}

Expand Down Expand Up @@ -82,6 +86,7 @@ impl Asn1Type {
Asn1Type::VideotexString => quote!(::der::asn1::VideotexStringRef),
Asn1Type::UtcTime => quote!(::der::asn1::UtcTime),
Asn1Type::Utf8String => quote!(::der::asn1::Utf8StringRef),
Asn1Type::BmpString => quote!(::der::asn1::BmpString),
}
}
}
Expand All @@ -100,6 +105,7 @@ impl FromStr for Asn1Type {
"VideotexString" => Ok(Self::VideotexString),
"UTCTime" => Ok(Self::UtcTime),
"UTF8String" => Ok(Self::Utf8String),
"BMPString" => Ok(Self::BmpString),
_ => Err(ParseError),
}
}
Expand All @@ -117,6 +123,7 @@ impl fmt::Display for Asn1Type {
Asn1Type::VideotexString => "VideotexString",
Asn1Type::UtcTime => "UTCTime",
Asn1Type::Utf8String => "UTF8String",
Asn1Type::BmpString => "BMPString",
})
}
}
Expand Down