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