@@ -1493,4 +1493,47 @@ PITGdT9dgN88nHPCle0B1+OY+OZ5
14931493 ) ;
14941494 }
14951495 }
1496+
1497+ #[ cfg( feature = "x509-parser" ) ]
1498+ #[ test]
1499+ fn test_certificate_with_multiple_domain_components_roundtrip ( ) {
1500+ use std:: str:: FromStr ;
1501+
1502+ use crate :: string:: Ia5String ;
1503+
1504+ let domain_component_dn_type = DnType :: CustomDnType ( vec ! [ 0 , 9 , 2342 , 19200300 , 100 , 1 , 25 ] ) ; // Domain Component (DC)
1505+
1506+ let dc_value_1 = DnValue :: Ia5String ( Ia5String :: from_str ( "example" ) . unwrap ( ) ) ;
1507+ let dc_value_2 = DnValue :: Ia5String ( Ia5String :: from_str ( "com" ) . unwrap ( ) ) ;
1508+
1509+ let mut params = CertificateParams :: new ( vec ! [ "crabs" . to_owned( ) ] ) . unwrap ( ) ;
1510+ params. distinguished_name = DistinguishedName :: new ( ) ;
1511+ params
1512+ . distinguished_name
1513+ . push ( domain_component_dn_type. clone ( ) , dc_value_1. clone ( ) ) ;
1514+
1515+ params
1516+ . distinguished_name
1517+ . push ( domain_component_dn_type. clone ( ) , dc_value_2. clone ( ) ) ;
1518+
1519+ let key_pair = KeyPair :: generate ( ) . unwrap ( ) ;
1520+ let cert = params. self_signed ( & key_pair) . unwrap ( ) ;
1521+
1522+ // We should be able to parse the certificate with x509-parser.
1523+ assert ! ( x509_parser:: parse_x509_certificate( cert. der( ) ) . is_ok( ) ) ;
1524+
1525+ // We should be able to reconstitute params from the DER using x509-parser.
1526+ let params_from_cert = CertificateParams :: from_ca_cert_der ( cert. der ( ) ) . unwrap ( ) ;
1527+
1528+ // We should find the expected distinguished name in the reconstituted params.
1529+ let expected_names = & [
1530+ ( & domain_component_dn_type, & dc_value_1) ,
1531+ ( & domain_component_dn_type, & dc_value_2) ,
1532+ ] ;
1533+ let names = params_from_cert
1534+ . distinguished_name
1535+ . iter ( )
1536+ . collect :: < Vec < ( _ , _ ) > > ( ) ;
1537+ assert_eq ! ( names, expected_names) ;
1538+ }
14961539}
0 commit comments