1 use alloc::string::String; 2 use der::asn1::{PrintableString, TeletexString}; 3 use der::{Choice, ValueOrd}; 4 5 /// DirectoryString as defined in [RFC 5280 Section 4.2.1.4]. 6 /// 7 /// ASN.1 structure for DirectoryString is below. 8 /// 9 /// ```text 10 /// DirectoryString ::= CHOICE { 11 /// teletexString TeletexString (SIZE (1..MAX)), 12 /// printableString PrintableString (SIZE (1..MAX)), 13 /// universalString UniversalString (SIZE (1..MAX)), 14 /// utf8String UTF8String (SIZE (1..MAX)), 15 /// bmpString BMPString (SIZE (1..MAX)) 16 /// } 17 /// ``` 18 /// 19 /// Further, [RFC 5280 Section 4.2.1.4] states: 20 /// 21 /// ```text 22 /// The DirectoryString type is defined as a choice of PrintableString, 23 /// TeletexString, BMPString, UTF8String, and UniversalString. CAs 24 /// conforming to this profile MUST use either the PrintableString or 25 /// UTF8String encoding of DirectoryString, with two exceptions. When 26 /// CAs have previously issued certificates with issuer fields with 27 /// attributes encoded using TeletexString, BMPString, or 28 /// UniversalString, then the CA MAY continue to use these encodings of 29 /// the DirectoryString to preserve backward compatibility. Also, new 30 /// CAs that are added to a domain where existing CAs issue certificates 31 /// with issuer fields with attributes encoded using TeletexString, 32 /// BMPString, or UniversalString MAY encode attributes that they share 33 /// with the existing CAs using the same encodings as the existing CAs 34 /// use. 35 /// ``` 36 /// 37 /// The implication of the above paragraph is that `PrintableString` and 38 /// `UTF8String` are the new types and the other types are legacy. Until 39 /// the need arises, we only support `PrintableString` and `UTF8String`. 40 /// 41 /// [RFC 5280 Section 4.2.1.4]: https://datatracker.ietf.org/doc/html/rfc5280#section-4.2.1.4 42 #[derive(Clone, Debug, Eq, PartialEq, Choice, ValueOrd)] 43 #[allow(missing_docs)] 44 pub enum DirectoryString { 45 #[asn1(type = "PrintableString")] 46 PrintableString(PrintableString), 47 48 #[asn1(type = "TeletexString")] 49 TeletexString(TeletexString), 50 51 #[asn1(type = "UTF8String")] 52 Utf8String(String), 53 } 54