summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crypto/test/src/asn1/test/X509NameTest.cs56
1 files changed, 42 insertions, 14 deletions
diff --git a/crypto/test/src/asn1/test/X509NameTest.cs b/crypto/test/src/asn1/test/X509NameTest.cs
index 9eab25952..204f7f18b 100644
--- a/crypto/test/src/asn1/test/X509NameTest.cs
+++ b/crypto/test/src/asn1/test/X509NameTest.cs
@@ -14,6 +14,7 @@ namespace Org.BouncyCastle.Asn1.Tests
     public class X509NameTest
         : SimpleTest
     {
+        // TODO Fix commented cases
         private static readonly string[] subjects =
         {
             "C=AU,ST=Victoria,L=South Melbourne,O=Connect 4 Pty Ltd,OU=Webserver Team,CN=www2.connect4.com.au,E=webmaster@connect4.com.au",
@@ -22,19 +23,29 @@ namespace Org.BouncyCastle.Asn1.Tests
             "C=US,O=National Aeronautics and Space Administration,SERIALNUMBER=16+CN=Steve Schoch",
             "E=cooke@issl.atl.hp.com,C=US,OU=Hewlett Packard Company (ISSL),CN=Paul A. Cooke",
             "O=Sun Microsystems Inc,CN=store.sun.com",
-            "unstructuredAddress=192.168.1.33,unstructuredName=pixfirewall.ciscopix.com,CN=pixfirewall.ciscopix.com"
+            "unstructuredAddress=192.168.1.33,unstructuredName=pixfirewall.ciscopix.com,CN=pixfirewall.ciscopix.com",
+            //"CN=*.canal-plus.com,OU=Provided by TBS INTERNET https://www.tbs-certificats.com/,OU=\\ CANAL \\+,O=CANAL\\+DISTRIBUTION,L=issy les moulineaux,ST=Hauts de Seine,C=FR",
+            //"O=Bouncy Castle,CN=www.bouncycastle.org\\ ",
+            //"O=Bouncy Castle,CN=c:\\\\fred\\\\bob",
+            //"C=0,O=1,OU=2,T=3,CN=4,SERIALNUMBER=5,STREET=6,SERIALNUMBER=7,L=8,ST=9,SURNAME=10,GIVENNAME=11,INITIALS=12," +
+            //"GENERATION=13,UniqueIdentifier=14,BusinessCategory=15,PostalCode=16,DN=17,Pseudonym=18,PlaceOfBirth=19," +
+            //"Gender=20,CountryOfCitizenship=21,CountryOfResidence=22,NameAtBirth=23,PostalAddress=24,2.5.4.54=25," +
+            //"TelephoneNumber=26,Name=27,E=28,unstructuredName=29,unstructuredAddress=30,E=31,DC=32,UID=33",
+            "C=DE,L=Berlin,O=Wohnungsbaugenossenschaft \\\"Humboldt-Universität\\\" eG,CN=transfer.wbg-hub.de",
         };
 
-        public override string Name
+        // TODO Fix commented cases
+        private static readonly string[] hexSubjects =
         {
-            get { return "X509Name"; }
-        }
+            //"CN=\\20Test\\20X,O=\\20Test,C=GB",         // input
+            //"CN=\\ Test X,O=\\ Test,C=GB",              // expected
+            //"CN=\\20Test\\20X\\20,O=\\20Test,C=GB",     // input
+            //"CN=\\ Test X\\ ,O=\\ Test,C=GB",           // expected
+        };
 
-        private static X509Name FromBytes(
-            byte[] bytes)
-        {
-            return X509Name.GetInstance(Asn1Object.FromByteArray(bytes));
-        }
+        public override string Name => "X509Name";
+
+        private static X509Name FromBytes(byte[] bytes) => X509Name.GetInstance(bytes);
 
         private IAsn1Convertible createEntryValue(
             DerObjectIdentifier	oid,
@@ -288,13 +299,30 @@ namespace Org.BouncyCastle.Asn1.Tests
             //
             for (int i = 0; i != subjects.Length; i++)
             {
-                X509Name name = new X509Name(subjects[i]);
-                byte[] encodedName = name.GetEncoded();
-                name = X509Name.GetInstance(Asn1Object.FromByteArray(encodedName));
+                var subject = subjects[i];
+                var name = new X509Name(subject);
+
+                var decodedName = FromBytes(name.GetEncoded());
+                var decodedSubject = decodedName.ToString();
+
+                if (!subject.Equals(decodedSubject))
+                {
+                    Fail("Failed regeneration test " + i + " got: " + decodedSubject + " expected " + subject);
+                }
+            }
+
+            for (int i = 0; i < hexSubjects.Length; i += 2)
+            {
+                var subject = hexSubjects[i];
+                var name = new X509Name(subject);
+
+                var decodedName = FromBytes(name.GetEncoded());
+                var decodedSubject = decodedName.ToString();
 
-                if (!name.ToString().Equals(subjects[i]))
+                string expected = hexSubjects[i + 1];
+                if (!expected.Equals(decodedSubject))
                 {
-                    Fail("Failed regeneration test " + i);
+                    Fail("Failed hex regeneration test " + i + " got: " + decodedSubject + " expected " + expected);
                 }
             }