verdict_parser/x509/
display.rs1use super::*;
4use std::fmt::{self, Display};
5
6impl<'a> Display for DirectoryStringValue<'a> {
7 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
8 match self {
9 DirectoryStringValue::PrintableString(s) => write!(f, "{}", s),
10 DirectoryStringValue::UTF8String(s) => write!(f, "{}", s),
11 DirectoryStringValue::IA5String(s) => write!(f, "{}", s),
12 DirectoryStringValue::TeletexString(..) => write!(f, "<TeletexString>"),
13 DirectoryStringValue::UniversalString(..) => write!(f, "<UniversalString>"),
14 DirectoryStringValue::BMPString(..) => write!(f, "<BMPString>"),
15 DirectoryStringValue::Unreachable => write!(f, "<Unreachable>"),
16 }
17 }
18}
19
20impl<'a> Display for AttributeTypeAndValueValue<'a> {
21 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
22 if self.typ.polyfill_eq(&oid!(COMMON_NAME)) {
23 write!(f, "CN={}", self.value)
24 } else if self.typ.polyfill_eq(&oid!(COUNTRY_NAME)) {
25 write!(f, "C={}", self.value)
26 } else if self.typ.polyfill_eq(&oid!(LOCALITY_NAME)) {
27 write!(f, "L={}", self.value)
28 } else if self.typ.polyfill_eq(&oid!(STATE_NAME)) {
29 write!(f, "ST={}", self.value)
30 } else if self.typ.polyfill_eq(&oid!(ORGANIZATION_NAME)) {
31 write!(f, "O={}", self.value)
32 } else if self.typ.polyfill_eq(&oid!(ORGANIZATIONAL_UNIT)) {
33 write!(f, "OU={}", self.value)
34 } else if self.typ.polyfill_eq(&oid!(STREET_ADDRESS)) {
35 write!(f, "STREET={}", self.value)
36 } else if self.typ.polyfill_eq(&oid!(SERIAL_NUMBER)) {
37 write!(f, "SERIALNUMBER={}", self.value)
38 } else if self.typ.polyfill_eq(&oid!(EMAIL_ADDRESS)) {
39 write!(f, "EMAILADDRESS={}", self.value)
40 } else {
41 write!(f, "{:?}={}", self.typ, self.value)
42 }
43 }
44}
45
46impl<'a> Display for RDNValue<'a> {
47 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
48 for (i, attr) in self.0.iter().enumerate() {
49 if i == 0 {
50 write!(f, "{}", attr)?;
51 } else {
52 write!(f, " {}", attr)?;
53 }
54 }
55 Ok(())
56 }
57}
58
59impl<'a> Display for NameValue<'a> {
60 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
61 for (i, rdn) in self.0.iter().enumerate() {
62 if i == 0 {
63 write!(f, "{}", rdn)?;
64 } else {
65 write!(f, ", {}", rdn)?;
66 }
67 }
68 Ok(())
69 }
70}