verdict_parser/x509/
dir_string.rs1use super::*;
2use vstd::prelude::*;
3
4verus! {
5
6asn1! {
15 choice DirectoryString {
16 PrintableString(ASN1(PrintableString)): ASN1<PrintableString>,
17 UTF8String(ASN1(UTF8String)): ASN1<UTF8String>,
18 IA5String(ASN1(IA5String)): ASN1<IA5String>,
19 TeletexString(placeholder!(TELETEX_STRING)): placeholder_type!(),
20 UniversalString(placeholder!(UNIVERSAL_STRING)): placeholder_type!(),
21 BMPString(placeholder!(BMP_STRING)): placeholder_type!(),
22 }
23}
24
25}
26
27#[cfg(test)]
28mod test {
29 use super::*;
30
31 verus! {
32 #[test]
34 fn is_combinator() {
35 let _ = DirectoryString.parse(&[]);
36 }
37 }
38
39 #[test]
40 fn utf8() {
41 assert_eq!(
42 DirectoryString
43 .parse(&[0x0C, 0x07, 0x52, 0x75, 0x62, 0x79, 0x20, 0x43, 0x41,])
44 .unwrap()
45 .1,
46 DirectoryStringValue::UTF8String("Ruby CA")
47 );
48 }
49
50 #[test]
51 fn ia5_string() {
52 let parsed = DirectoryString
53 .parse(&[
54 0x16, 0x09, 0x72, 0x75, 0x62, 0x79, 0x2D, 0x6C, 0x61, 0x6E, 0x67,
55 ])
56 .unwrap()
57 .1;
58
59 match parsed {
60 DirectoryStringValue::IA5String(s) => {
61 assert_eq!(s, "ruby-lang");
62 }
63 _ => panic!("{:?}", parsed),
64 }
65 }
66
67 #[test]
68 fn printable_string() {
69 let parsed = DirectoryString
70 .parse(&[
71 0x13, 0x19, 0x47, 0x6F, 0x6F, 0x67, 0x6C, 0x65, 0x20, 0x54, 0x72, 0x75, 0x73, 0x74,
72 0x20, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x73, 0x20, 0x4C, 0x4C, 0x43,
73 ])
74 .unwrap()
75 .1;
76
77 match parsed {
78 DirectoryStringValue::PrintableString(s) => {
79 assert_eq!(s, "Google Trust Services LLC");
80 }
81 _ => panic!("{:?}", parsed),
82 }
83 }
84}