1
1
use crate :: { Error , InvalidAsn1String } ;
2
- use std:: str:: FromStr ;
2
+ use std:: { fmt , str:: FromStr } ;
3
3
4
4
/// ASN.1 `PrintableString` type.
5
5
///
@@ -118,6 +118,36 @@ impl AsRef<str> for PrintableString {
118
118
}
119
119
}
120
120
121
+ impl fmt:: Display for PrintableString {
122
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
123
+ fmt:: Display :: fmt ( self . as_str ( ) , f)
124
+ }
125
+ }
126
+
127
+ impl PartialEq < str > for PrintableString {
128
+ fn eq ( & self , other : & str ) -> bool {
129
+ self . as_str ( ) == other
130
+ }
131
+ }
132
+
133
+ impl PartialEq < String > for PrintableString {
134
+ fn eq ( & self , other : & String ) -> bool {
135
+ self . as_str ( ) == other. as_str ( )
136
+ }
137
+ }
138
+
139
+ impl PartialEq < & str > for PrintableString {
140
+ fn eq ( & self , other : & & str ) -> bool {
141
+ self . as_str ( ) == * other
142
+ }
143
+ }
144
+
145
+ impl PartialEq < & String > for PrintableString {
146
+ fn eq ( & self , other : & & String ) -> bool {
147
+ self . as_str ( ) == other. as_str ( )
148
+ }
149
+ }
150
+
121
151
/// ASN.1 `IA5String` type.
122
152
///
123
153
/// # Examples
@@ -194,6 +224,36 @@ impl AsRef<str> for Ia5String {
194
224
}
195
225
}
196
226
227
+ impl fmt:: Display for Ia5String {
228
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
229
+ fmt:: Display :: fmt ( self . as_str ( ) , f)
230
+ }
231
+ }
232
+
233
+ impl PartialEq < str > for Ia5String {
234
+ fn eq ( & self , other : & str ) -> bool {
235
+ self . as_str ( ) == other
236
+ }
237
+ }
238
+
239
+ impl PartialEq < String > for Ia5String {
240
+ fn eq ( & self , other : & String ) -> bool {
241
+ self . as_str ( ) == other. as_str ( )
242
+ }
243
+ }
244
+
245
+ impl PartialEq < & str > for Ia5String {
246
+ fn eq ( & self , other : & & str ) -> bool {
247
+ self . as_str ( ) == * other
248
+ }
249
+ }
250
+
251
+ impl PartialEq < & String > for Ia5String {
252
+ fn eq ( & self , other : & & String ) -> bool {
253
+ self . as_str ( ) == other. as_str ( )
254
+ }
255
+ }
256
+
197
257
/// ASN.1 `TeletexString` type.
198
258
///
199
259
/// # Examples
@@ -279,6 +339,36 @@ impl AsRef<str> for TeletexString {
279
339
}
280
340
}
281
341
342
+ impl fmt:: Display for TeletexString {
343
+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
344
+ fmt:: Display :: fmt ( self . as_str ( ) , f)
345
+ }
346
+ }
347
+
348
+ impl PartialEq < str > for TeletexString {
349
+ fn eq ( & self , other : & str ) -> bool {
350
+ self . as_str ( ) == other
351
+ }
352
+ }
353
+
354
+ impl PartialEq < String > for TeletexString {
355
+ fn eq ( & self , other : & String ) -> bool {
356
+ self . as_str ( ) == other. as_str ( )
357
+ }
358
+ }
359
+
360
+ impl PartialEq < & str > for TeletexString {
361
+ fn eq ( & self , other : & & str ) -> bool {
362
+ self . as_str ( ) == * other
363
+ }
364
+ }
365
+
366
+ impl PartialEq < & String > for TeletexString {
367
+ fn eq ( & self , other : & & String ) -> bool {
368
+ self . as_str ( ) == other. as_str ( )
369
+ }
370
+ }
371
+
282
372
/// ASN.1 `BMPString` type.
283
373
///
284
374
/// # Examples
@@ -518,7 +608,7 @@ mod tests {
518
608
fn printable_string ( ) {
519
609
const EXAMPLE_UTF8 : & str = "CertificateTemplate" ;
520
610
let printable_string = PrintableString :: try_from ( EXAMPLE_UTF8 ) . unwrap ( ) ;
521
- assert_eq ! ( printable_string. as_str ( ) , EXAMPLE_UTF8 ) ;
611
+ assert_eq ! ( printable_string, EXAMPLE_UTF8 ) ;
522
612
assert ! ( PrintableString :: try_from( "@" ) . is_err( ) ) ;
523
613
assert ! ( PrintableString :: try_from( "*" ) . is_err( ) ) ;
524
614
}
@@ -527,8 +617,7 @@ mod tests {
527
617
fn ia5_string ( ) {
528
618
const EXAMPLE_UTF8 : & str = "CertificateTemplate" ;
529
619
let ia5_string = Ia5String :: try_from ( EXAMPLE_UTF8 ) . unwrap ( ) ;
530
- assert_eq ! ( ia5_string. as_str( ) , EXAMPLE_UTF8 ) ;
531
- // TODO use an invalid ascii character
620
+ assert_eq ! ( ia5_string, EXAMPLE_UTF8 ) ;
532
621
assert ! ( Ia5String :: try_from( String :: from( '\u{7F}' ) ) . is_ok( ) ) ;
533
622
assert ! ( Ia5String :: try_from( String :: from( '\u{8F}' ) ) . is_err( ) ) ;
534
623
}
@@ -537,7 +626,7 @@ mod tests {
537
626
fn teletext_string ( ) {
538
627
const EXAMPLE_UTF8 : & str = "CertificateTemplate" ;
539
628
let teletext_string = TeletexString :: try_from ( EXAMPLE_UTF8 ) . unwrap ( ) ;
540
- assert_eq ! ( teletext_string. as_str ( ) , EXAMPLE_UTF8 ) ;
629
+ assert_eq ! ( teletext_string, EXAMPLE_UTF8 ) ;
541
630
assert ! ( Ia5String :: try_from( String :: from( '\u{7F}' ) ) . is_ok( ) ) ;
542
631
assert ! ( Ia5String :: try_from( String :: from( '\u{8F}' ) ) . is_err( ) ) ;
543
632
}
0 commit comments