diff options
Diffstat (limited to 'crypto/src/asn1/DerBitString.cs')
-rw-r--r-- | crypto/src/asn1/DerBitString.cs | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/crypto/src/asn1/DerBitString.cs b/crypto/src/asn1/DerBitString.cs index 3f3697d99..9cf84db1e 100644 --- a/crypto/src/asn1/DerBitString.cs +++ b/crypto/src/asn1/DerBitString.cs @@ -1,5 +1,6 @@ using System; using System.Diagnostics; +using System.IO; using System.Text; using Org.BouncyCastle.Math; @@ -22,17 +23,24 @@ namespace Org.BouncyCastle.Asn1 { if (obj == null || obj is DerBitString) { - return (DerBitString) obj; + return (DerBitString)obj; } - if (obj is byte[]) + //else if (obj is Asn1BitStringParser) + else if (obj is IAsn1Convertible) + { + Asn1Object asn1Object = ((IAsn1Convertible)obj).ToAsn1Object(); + if (asn1Object is DerBitString) + return (DerBitString)asn1Object; + } + else if (obj is byte[]) { try { - return (DerBitString)FromByteArray((byte[])obj); + return GetInstance(FromByteArray((byte[])obj)); } - catch (Exception e) + catch (IOException e) { - throw new ArgumentException("encoding error in GetInstance: " + e.ToString()); + throw new ArgumentException("failed to construct BIT STRING from byte[]: " + e.Message); } } |