Rust
Rust
Subject Alternative Name for ICP Brasil Certs
See more Certificates Examples
Demonstrates how to access the multiple names contained in the Subject Alternative Name of a certificate. This example is for an ICP Brasil certificate.Chilkat Rust Downloads
let cert = chilkat::Cert::new();
if cert.load_from_file("qa_data/certs/testIcpBrasil.cer").is_err() {
println!("{}", cert.last_error_text());
return;
}
// If the cert's Subject Alternative Name contains multiple values, each specified by an OID,
// then the Rfc822Name property returns XML.
let subject_alt_name_xml = cert.rfc822_name();
println!("{}", subject_alt_name_xml);
// Here's a sample of the subjectAltNameXml:
// <SubjectAltName>
// <name type="oid" oid="2.16.76.1.3.4">290999653223955019700000000000000000000150424SRJUXPTS</name>
// <name type="oid" oid="2.16.76.1.3.2">JOAO SILVA</name>
// <name type="oid" oid="2.16.76.1.3.3">02408939000115</name>
// <name type="oid" oid="2.16.76.1.3.7">000000000000</name>
// </SubjectAltName>
// The XML can be parsed like this:
let xml = chilkat::Xml::new();
let _ = xml.load_xml(&subject_alt_name_xml);
let mut oid = String::new();
let mut name = String::new();
let mut i = 0;
let count_i = xml.num_children_having_tag("name");
while i < count_i {
xml.set_i(i);
oid = xml.chilkat_path("name[i]|(oid)").unwrap_or_default();
name = xml.get_child_content("name[i]").unwrap_or_default();
println!("{}: {}", oid, name);
i = i + 1;
}