From 70c83d60e17de5b9290eceb892ceb03a53b6f027 Mon Sep 17 00:00:00 2001 From: dishmaker <141624503+dishmaker@users.noreply.github.com> Date: Fri, 2 May 2025 21:46:09 +0200 Subject: [PATCH] der: fix BMPString compatibility in derive macros --- der/src/asn1/bmp_string.rs | 14 +++++++++++++- der_derive/src/asn1_type.rs | 7 +++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/der/src/asn1/bmp_string.rs b/der/src/asn1/bmp_string.rs index fa42d1ae4..9c8da0f8d 100644 --- a/der/src/asn1/bmp_string.rs +++ b/der/src/asn1/bmp_string.rs @@ -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}; @@ -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) diff --git a/der_derive/src/asn1_type.rs b/der_derive/src/asn1_type.rs index 2acee3fc8..8fe8b31c5 100644 --- a/der_derive/src/asn1_type.rs +++ b/der_derive/src/asn1_type.rs @@ -34,6 +34,9 @@ pub(crate) enum Asn1Type { /// ASN.1 `UTF8String`. Utf8String, + + /// ASN.1 `BMPString`. + BmpString, } impl Asn1Type { @@ -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), } } @@ -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), } } } @@ -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), } } @@ -117,6 +123,7 @@ impl fmt::Display for Asn1Type { Asn1Type::VideotexString => "VideotexString", Asn1Type::UtcTime => "UTCTime", Asn1Type::Utf8String => "UTF8String", + Asn1Type::BmpString => "BMPString", }) } }