Skip to content

Commit 90b6617

Browse files
authored
der: fix BMPString compatibility in derive macros (#1793)
1 parent 217b6ef commit 90b6617

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

der/src/asn1/bmp_string.rs

+13-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use crate::{
44
BytesOwned, DecodeValue, EncodeValue, Error, FixedTag, Header, Length, Reader, Result, Tag,
5-
Writer,
5+
Writer, ord::OrdIsValueOrd,
66
};
77
use alloc::{boxed::Box, vec::Vec};
88
use core::{fmt, str::FromStr};
@@ -119,6 +119,18 @@ impl FromStr for BmpString {
119119
}
120120
}
121121

122+
impl OrdIsValueOrd for BmpString {}
123+
124+
/// Hack for simplifying the custom derive use case,
125+
/// as there is no `BmpStringRef` yet.
126+
impl From<&BmpString> for BmpString {
127+
fn from(value: &BmpString) -> Self {
128+
BmpString {
129+
bytes: value.bytes.clone(),
130+
}
131+
}
132+
}
133+
122134
impl fmt::Debug for BmpString {
123135
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
124136
write!(f, "BmpString(\"{}\")", self)

der_derive/src/asn1_type.rs

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ pub(crate) enum Asn1Type {
3434

3535
/// ASN.1 `UTF8String`.
3636
Utf8String,
37+
38+
/// ASN.1 `BMPString`.
39+
BmpString,
3740
}
3841

3942
impl Asn1Type {
@@ -49,6 +52,7 @@ impl Asn1Type {
4952
Asn1Type::VideotexString => quote!(::der::Tag::VideotexString),
5053
Asn1Type::UtcTime => quote!(::der::Tag::UtcTime),
5154
Asn1Type::Utf8String => quote!(::der::Tag::Utf8String),
55+
Asn1Type::BmpString => quote!(::der::Tag::BmpString),
5256
}
5357
}
5458

@@ -82,6 +86,7 @@ impl Asn1Type {
8286
Asn1Type::VideotexString => quote!(::der::asn1::VideotexStringRef),
8387
Asn1Type::UtcTime => quote!(::der::asn1::UtcTime),
8488
Asn1Type::Utf8String => quote!(::der::asn1::Utf8StringRef),
89+
Asn1Type::BmpString => quote!(::der::asn1::BmpString),
8590
}
8691
}
8792
}
@@ -100,6 +105,7 @@ impl FromStr for Asn1Type {
100105
"VideotexString" => Ok(Self::VideotexString),
101106
"UTCTime" => Ok(Self::UtcTime),
102107
"UTF8String" => Ok(Self::Utf8String),
108+
"BMPString" => Ok(Self::BmpString),
103109
_ => Err(ParseError),
104110
}
105111
}
@@ -117,6 +123,7 @@ impl fmt::Display for Asn1Type {
117123
Asn1Type::VideotexString => "VideotexString",
118124
Asn1Type::UtcTime => "UTCTime",
119125
Asn1Type::Utf8String => "UTF8String",
126+
Asn1Type::BmpString => "BMPString",
120127
})
121128
}
122129
}

0 commit comments

Comments
 (0)