format_serial

Function format_serial 

Source
pub fn format_serial(i: &[u8]) -> String
Expand description

Formats a slice to a colon-separated hex string (for ex 01:02:ff:ff)

Examples found in repository?
examples/print-crl.rs (line 31)
23fn print_authority_key_identifier(aki: &AuthorityKeyIdentifier, level: usize) {
24    if let Some(id) = &aki.key_identifier {
25        println!("{:indent$}keyid: {:x}", "", id, indent = level);
26    }
27    if aki.authority_cert_issuer.is_some() {
28        unimplemented!();
29    }
30    if let Some(serial) = aki.authority_cert_serial {
31        let s = format_serial(serial);
32        println!("{:indent$}serial: {}", "", &s, indent = level);
33    }
34}
More examples
Hide additional examples
examples/print-cert.rs (line 66)
47fn print_x509_extension(oid: &Oid, ext: &X509Extension) {
48    println!(
49        "    [crit:{} l:{}] {}: ",
50        ext.critical,
51        ext.value.len(),
52        format_oid(oid)
53    );
54    match ext.parsed_extension() {
55        ParsedExtension::AuthorityKeyIdentifier(aki) => {
56            println!("      X509v3 Authority Key Identifier");
57            if let Some(key_id) = &aki.key_identifier {
58                println!("        Key Identifier: {key_id:x}");
59            }
60            if let Some(issuer) = &aki.authority_cert_issuer {
61                for name in issuer {
62                    println!("        Cert Issuer: {name}");
63                }
64            }
65            if let Some(serial) = aki.authority_cert_serial {
66                println!("        Cert Serial: {}", format_serial(serial));
67            }
68        }
69        ParsedExtension::BasicConstraints(bc) => {
70            println!("      X509v3 CA: {}", bc.ca);
71        }
72        ParsedExtension::CRLDistributionPoints(points) => {
73            println!("      X509v3 CRL Distribution Points:");
74            for point in points.iter() {
75                if let Some(name) = &point.distribution_point {
76                    println!("        Full Name: {name:?}");
77                }
78                if let Some(reasons) = &point.reasons {
79                    println!("        Reasons: {reasons}");
80                }
81                if let Some(crl_issuer) = &point.crl_issuer {
82                    print!("        CRL Issuer: ");
83                    for gn in crl_issuer {
84                        print!("{} ", generalname_to_string(gn));
85                    }
86                    println!();
87                }
88                println!();
89            }
90        }
91        ParsedExtension::KeyUsage(ku) => {
92            println!("      X509v3 Key Usage: {ku}");
93        }
94        ParsedExtension::NSCertType(ty) => {
95            println!("      Netscape Cert Type: {ty}");
96        }
97        ParsedExtension::SubjectAlternativeName(san) => {
98            for name in &san.general_names {
99                let s = match name {
100                    GeneralName::DNSName(s) => {
101                        format!("DNS:{s}")
102                    }
103                    GeneralName::IPAddress(b) => {
104                        let ip = match b.len() {
105                            4 => {
106                                let b = <[u8; 4]>::try_from(*b).unwrap();
107                                let ip = Ipv4Addr::from(b);
108                                format!("{ip}")
109                            }
110                            16 => {
111                                let b = <[u8; 16]>::try_from(*b).unwrap();
112                                let ip = Ipv6Addr::from(b);
113                                format!("{ip}")
114                            }
115                            l => format!("invalid (len={l})"),
116                        };
117                        format!("IP Address:{ip}")
118                    }
119                    _ => {
120                        format!("{name:?}")
121                    }
122                };
123                println!("      X509v3 SAN: {s}");
124            }
125        }
126        ParsedExtension::SubjectKeyIdentifier(id) => {
127            println!("      X509v3 Subject Key Identifier: {id:x}");
128        }
129        x => println!("      {x:?}"),
130    }
131}