aboutsummaryrefslogtreecommitdiff
path: root/tests/trust_anchor_format.rs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/trust_anchor_format.rs')
-rw-r--r--tests/trust_anchor_format.rs126
1 files changed, 95 insertions, 31 deletions
diff --git a/tests/trust_anchor_format.rs b/tests/trust_anchor_format.rs
index bcc3e69..a1bdc69 100644
--- a/tests/trust_anchor_format.rs
+++ b/tests/trust_anchor_format.rs
@@ -1,4 +1,7 @@
-use der::{Decode, Encode, SliceReader};
+use der::{
+ asn1::{Ia5StringRef, PrintableStringRef},
+ Decode, Encode, SliceReader,
+};
use hex_literal::hex;
use x509_cert::anchor::{CertPolicies, TrustAnchorChoice};
use x509_cert::ext::pkix::name::GeneralName;
@@ -12,7 +15,7 @@ fn decode_ta1() {
let mut decoder = SliceReader::new(der_encoded_tac).unwrap();
let tac = TrustAnchorChoice::decode(&mut decoder).unwrap();
- let reencoded_tac = tac.to_vec().unwrap();
+ let reencoded_tac = tac.to_der().unwrap();
println!("Original : {:02X?}", der_encoded_cert);
println!("Reencoded: {:02X?}", reencoded_tac);
assert_eq!(der_encoded_tac, reencoded_tac.as_slice());
@@ -90,20 +93,34 @@ fn decode_ta1() {
for atav in i1 {
if 0 == counter {
assert_eq!(atav.oid.to_string(), "2.5.4.6");
- assert_eq!(atav.value.printable_string().unwrap().to_string(), "US");
+ assert_eq!(
+ PrintableStringRef::try_from(&atav.value)
+ .unwrap()
+ .to_string(),
+ "US"
+ );
} else if 1 == counter {
assert_eq!(atav.oid.to_string(), "2.5.4.10");
assert_eq!(
- atav.value.printable_string().unwrap().to_string(),
+ PrintableStringRef::try_from(&atav.value)
+ .unwrap()
+ .to_string(),
"U.S. Government"
);
} else if 2 == counter {
assert_eq!(atav.oid.to_string(), "2.5.4.11");
- assert_eq!(atav.value.printable_string().unwrap().to_string(), "ECA");
+ assert_eq!(
+ PrintableStringRef::try_from(&atav.value)
+ .unwrap()
+ .to_string(),
+ "ECA"
+ );
} else if 3 == counter {
assert_eq!(atav.oid.to_string(), "2.5.4.3");
assert_eq!(
- atav.value.printable_string().unwrap().to_string(),
+ PrintableStringRef::try_from(&atav.value)
+ .unwrap()
+ .to_string(),
"ECA Root CA 4"
);
}
@@ -111,7 +128,7 @@ fn decode_ta1() {
}
}
- let reencoded_cert = cert_path.certificate.to_vec().unwrap();
+ let reencoded_cert = cert_path.certificate.to_der().unwrap();
assert_eq!(der_encoded_cert, reencoded_cert.as_slice());
}
_ => panic!("Unexpected TrustAnchorChoice contents"),
@@ -127,7 +144,7 @@ fn decode_ta2() {
let mut decoder = SliceReader::new(der_encoded_tac).unwrap();
let tac = TrustAnchorChoice::decode(&mut decoder).unwrap();
- let reencoded_tac = tac.to_vec().unwrap();
+ let reencoded_tac = tac.to_der().unwrap();
println!("Original : {:02X?}", der_encoded_cert);
println!("Reencoded: {:02X?}", reencoded_tac);
assert_eq!(der_encoded_tac, reencoded_tac.as_slice());
@@ -153,23 +170,34 @@ fn decode_ta2() {
for atav in i1 {
if 0 == counter {
assert_eq!(atav.oid.to_string(), "2.5.4.6");
- assert_eq!(atav.value.printable_string().unwrap().to_string(), "US");
+ assert_eq!(
+ PrintableStringRef::try_from(&atav.value)
+ .unwrap()
+ .to_string(),
+ "US"
+ );
} else if 1 == counter {
assert_eq!(atav.oid.to_string(), "2.5.4.10");
assert_eq!(
- atav.value.printable_string().unwrap().to_string(),
+ PrintableStringRef::try_from(&atav.value)
+ .unwrap()
+ .to_string(),
"Entrust"
);
} else if 2 == counter {
assert_eq!(atav.oid.to_string(), "2.5.4.11");
assert_eq!(
- atav.value.printable_string().unwrap().to_string(),
+ PrintableStringRef::try_from(&atav.value)
+ .unwrap()
+ .to_string(),
"Certification Authorities"
);
} else if 3 == counter {
assert_eq!(atav.oid.to_string(), "2.5.4.11");
assert_eq!(
- atav.value.printable_string().unwrap().to_string(),
+ PrintableStringRef::try_from(&atav.value)
+ .unwrap()
+ .to_string(),
"Entrust Managed Services NFI Root CA"
);
}
@@ -190,19 +218,25 @@ fn decode_ta2() {
if 0 == counter {
assert_eq!(atav.oid.to_string(), "2.5.4.6");
assert_eq!(
- atav.value.printable_string().unwrap().to_string(),
+ PrintableStringRef::try_from(&atav.value)
+ .unwrap()
+ .to_string(),
"US"
);
} else if 1 == counter {
assert_eq!(atav.oid.to_string(), "2.5.4.10");
assert_eq!(
- atav.value.printable_string().unwrap().to_string(),
+ PrintableStringRef::try_from(&atav.value)
+ .unwrap()
+ .to_string(),
"U.S. Government"
);
} else if 2 == counter {
assert_eq!(atav.oid.to_string(), "2.5.4.11");
assert_eq!(
- atav.value.printable_string().unwrap().to_string(),
+ PrintableStringRef::try_from(&atav.value)
+ .unwrap()
+ .to_string(),
"DoD"
);
}
@@ -214,7 +248,7 @@ fn decode_ta2() {
}
}
- let reencoded_cert = cert_path.certificate.to_vec().unwrap();
+ let reencoded_cert = cert_path.certificate.to_der().unwrap();
assert_eq!(der_encoded_cert, reencoded_cert.as_slice());
}
_ => panic!("Unexpected TrustAnchorChoice contents"),
@@ -230,7 +264,7 @@ fn decode_ta3() {
let mut decoder = SliceReader::new(der_encoded_tac).unwrap();
let tac = TrustAnchorChoice::decode(&mut decoder).unwrap();
- let reencoded_tac = tac.to_vec().unwrap();
+ let reencoded_tac = tac.to_der().unwrap();
println!("Original : {:02X?}", der_encoded_cert);
println!("Reencoded: {:02X?}", reencoded_tac);
assert_eq!(der_encoded_tac, reencoded_tac.as_slice());
@@ -263,23 +297,34 @@ fn decode_ta3() {
for atav in i1 {
if 0 == counter {
assert_eq!(atav.oid.to_string(), "2.5.4.6");
- assert_eq!(atav.value.printable_string().unwrap().to_string(), "US");
+ assert_eq!(
+ PrintableStringRef::try_from(&atav.value)
+ .unwrap()
+ .to_string(),
+ "US"
+ );
} else if 1 == counter {
assert_eq!(atav.oid.to_string(), "2.5.4.10");
assert_eq!(
- atav.value.printable_string().unwrap().to_string(),
+ PrintableStringRef::try_from(&atav.value)
+ .unwrap()
+ .to_string(),
"Exostar LLC"
);
} else if 2 == counter {
assert_eq!(atav.oid.to_string(), "2.5.4.11");
assert_eq!(
- atav.value.printable_string().unwrap().to_string(),
+ PrintableStringRef::try_from(&atav.value)
+ .unwrap()
+ .to_string(),
"Certification Authorities"
);
} else if 3 == counter {
assert_eq!(atav.oid.to_string(), "2.5.4.3");
assert_eq!(
- atav.value.printable_string().unwrap().to_string(),
+ PrintableStringRef::try_from(&atav.value)
+ .unwrap()
+ .to_string(),
"Exostar Federated Identity Service Root CA 1"
);
}
@@ -300,19 +345,25 @@ fn decode_ta3() {
if 0 == counter {
assert_eq!(atav.oid.to_string(), "2.5.4.6");
assert_eq!(
- atav.value.printable_string().unwrap().to_string(),
+ PrintableStringRef::try_from(&atav.value)
+ .unwrap()
+ .to_string(),
"US"
);
} else if 1 == counter {
assert_eq!(atav.oid.to_string(), "2.5.4.10");
assert_eq!(
- atav.value.printable_string().unwrap().to_string(),
+ PrintableStringRef::try_from(&atav.value)
+ .unwrap()
+ .to_string(),
"U.S. Government"
);
} else if 2 == counter {
assert_eq!(atav.oid.to_string(), "2.5.4.11");
assert_eq!(
- atav.value.printable_string().unwrap().to_string(),
+ PrintableStringRef::try_from(&atav.value)
+ .unwrap()
+ .to_string(),
"DoD"
);
}
@@ -324,7 +375,7 @@ fn decode_ta3() {
}
}
- let reencoded_cert = cert_path.certificate.to_vec().unwrap();
+ let reencoded_cert = cert_path.certificate.to_der().unwrap();
assert_eq!(der_encoded_cert, reencoded_cert.as_slice());
}
_ => panic!("Unexpected TrustAnchorChoice contents"),
@@ -340,7 +391,7 @@ fn decode_ta4() {
let mut decoder = SliceReader::new(der_encoded_tac).unwrap();
let tac = TrustAnchorChoice::decode(&mut decoder).unwrap();
- let reencoded_tac = tac.to_vec().unwrap();
+ let reencoded_tac = tac.to_der().unwrap();
println!("Original : {:02X?}", der_encoded_cert);
println!("Reencoded: {:02X?}", reencoded_tac);
assert_eq!(der_encoded_tac, reencoded_tac.as_slice());
@@ -366,17 +417,30 @@ fn decode_ta4() {
for atav in i1 {
if 0 == counter {
assert_eq!(atav.oid.to_string(), "0.9.2342.19200300.100.1.25");
- assert_eq!(atav.value.ia5_string().unwrap().to_string(), "com");
+ assert_eq!(
+ Ia5StringRef::try_from(&atav.value).unwrap().to_string(),
+ "com"
+ );
} else if 1 == counter {
assert_eq!(atav.oid.to_string(), "0.9.2342.19200300.100.1.25");
- assert_eq!(atav.value.ia5_string().unwrap().to_string(), "raytheon");
+ assert_eq!(
+ Ia5StringRef::try_from(&atav.value).unwrap().to_string(),
+ "raytheon"
+ );
} else if 2 == counter {
assert_eq!(atav.oid.to_string(), "2.5.4.10");
- assert_eq!(atav.value.printable_string().unwrap().to_string(), "CAs");
+ assert_eq!(
+ PrintableStringRef::try_from(&atav.value)
+ .unwrap()
+ .to_string(),
+ "CAs"
+ );
} else if 3 == counter {
assert_eq!(atav.oid.to_string(), "2.5.4.11");
assert_eq!(
- atav.value.printable_string().unwrap().to_string(),
+ PrintableStringRef::try_from(&atav.value)
+ .unwrap()
+ .to_string(),
"RaytheonRoot"
);
}
@@ -389,7 +453,7 @@ fn decode_ta4() {
panic!("Wrong path length constraint");
}
- let reencoded_cert = cert_path.certificate.to_vec().unwrap();
+ let reencoded_cert = cert_path.certificate.to_der().unwrap();
assert_eq!(der_encoded_cert, reencoded_cert.as_slice());
}
_ => panic!("Unexpected TrustAnchorChoice contents"),