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