summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--crypto/src/asn1/DerBitString.cs11
-rw-r--r--crypto/test/src/asn1/test/BitStringTest.cs16
2 files changed, 27 insertions, 0 deletions
diff --git a/crypto/src/asn1/DerBitString.cs b/crypto/src/asn1/DerBitString.cs
index a3c2cee01..26adc575b 100644
--- a/crypto/src/asn1/DerBitString.cs
+++ b/crypto/src/asn1/DerBitString.cs
@@ -28,6 +28,17 @@ namespace Org.BouncyCastle.Asn1
 			{
 				return (DerBitString) obj;
 			}
+            if (obj is byte[])
+            {
+                try
+                {
+                    return (DerBitString)FromByteArray((byte[])obj);
+                }
+                catch (Exception e)
+                {
+                    throw new ArgumentException("encoding error in GetInstance: " + e.ToString());
+                }
+            }
 
             throw new ArgumentException("illegal object in GetInstance: " + Platform.GetTypeName(obj));
 		}
diff --git a/crypto/test/src/asn1/test/BitStringTest.cs b/crypto/test/src/asn1/test/BitStringTest.cs
index f2ae3de97..35b7811bc 100644
--- a/crypto/test/src/asn1/test/BitStringTest.cs
+++ b/crypto/test/src/asn1/test/BitStringTest.cs
@@ -86,10 +86,26 @@ namespace Org.BouncyCastle.Asn1.Tests
                 //Fail("failed DL check");
                 Fail("failed BER check");
             }
+            IAsn1String dl = BerBitString.GetInstance(dlData);
+
+            //IsTrue("DL test failed", dl is DLBitString);
+            IsTrue("BER test failed", dl is BerBitString);
             if (!Arrays.AreEqual(derData, Asn1Object.FromByteArray(dlData).GetDerEncoded()))
             {
                 Fail("failed DER check");
             }
+            // TODO This test isn't applicable until we get the DL variants
+            //try
+            //{
+            //    DerBitString.GetInstance(dlData);
+            //    Fail("no exception");
+            //}
+            //catch (ArgumentException e)
+            //{
+            //    // ignore
+            //}
+            IAsn1String der = DerBitString.GetInstance(derData);
+            IsTrue("DER test failed", der is DerBitString);
         }
 
         public override void PerformTest()