summary refs log tree commit diff
path: root/crypto/src/asn1/DerEnumerated.cs
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2018-10-18 18:15:32 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2018-10-18 18:15:32 +0700
commita3ffd09890cd48bbd21040a49a2399a24f204918 (patch)
tree73baa1e3b656b83b90bfb90cc34ed96c055a62f4 /crypto/src/asn1/DerEnumerated.cs
parentMove generic "...withRSA" handler after PSSwithRSA (diff)
downloadBouncyCastle.NET-ed25519-a3ffd09890cd48bbd21040a49a2399a24f204918.tar.xz
Env. prop.: Org.BouncyCastle.Asn1.AllowUnsafeInteger
- set to "true" to weaken ASN.1 INTEGER checks
- see https://github.com/bcgit/bc-csharp/issues/156
Diffstat (limited to 'crypto/src/asn1/DerEnumerated.cs')
-rw-r--r--crypto/src/asn1/DerEnumerated.cs13
1 files changed, 6 insertions, 7 deletions
diff --git a/crypto/src/asn1/DerEnumerated.cs b/crypto/src/asn1/DerEnumerated.cs
index db27065bb..6690feceb 100644
--- a/crypto/src/asn1/DerEnumerated.cs
+++ b/crypto/src/asn1/DerEnumerated.cs
@@ -62,19 +62,18 @@ namespace Org.BouncyCastle.Asn1
         }
 
         public DerEnumerated(
-            byte[]   bytes)
+            byte[] bytes)
         {
             if (bytes.Length > 1)
             {
-                if (bytes[0] == 0 && (bytes[1] & 0x80) == 0)
+                if ((bytes[0] == 0 && (bytes[1] & 0x80) == 0)
+                    || (bytes[0] == (byte)0xff && (bytes[1] & 0x80) != 0))
                 {
-                    throw new ArgumentException("malformed enumerated");
-                }
-                if (bytes[0] == (byte)0xff && (bytes[1] & 0x80) != 0)
-                {
-                    throw new ArgumentException("malformed enumerated");
+                    if (!DerInteger.AllowUnsafe())
+                        throw new ArgumentException("malformed enumerated");
                 }
             }
+
             this.bytes = Arrays.Clone(bytes);
         }