summary refs log tree commit diff
path: root/crypto/src
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2021-02-08 19:26:46 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2021-02-08 19:26:46 +0700
commit50335415dd4d1809782181874e38a275734b76f5 (patch)
tree36ce4b945cf1326487e168cda480ed7fd3e2d9d9 /crypto/src
parentEnv. var. to enforce correct X.509 cert encoding (diff)
downloadBouncyCastle.NET-ed25519-50335415dd4d1809782181874e38a275734b76f5.tar.xz
New HasValue methods
Diffstat (limited to 'crypto/src')
-rw-r--r--crypto/src/asn1/DerEnumerated.cs6
-rw-r--r--crypto/src/asn1/DerInteger.cs12
-rw-r--r--crypto/src/asn1/cms/AuthEnvelopedData.cs2
-rw-r--r--crypto/src/asn1/cms/AuthEnvelopedDataParser.cs2
-rw-r--r--crypto/src/asn1/cms/EnvelopedData.cs2
-rw-r--r--crypto/src/asn1/cms/SignedData.cs2
-rw-r--r--crypto/src/asn1/icao/LDSSecurityObject.cs3
-rw-r--r--crypto/src/asn1/pkcs/EncryptedData.cs6
-rw-r--r--crypto/src/asn1/pkcs/Pfx.cs2
-rw-r--r--crypto/src/asn1/x509/AttributeCertificateInfo.cs2
-rw-r--r--crypto/src/asn1/x509/GeneralSubtree.cs2
-rw-r--r--crypto/src/asn1/x509/TBSCertificateStructure.cs11
-rw-r--r--crypto/src/asn1/x9/X9ECParameters.cs2
13 files changed, 34 insertions, 20 deletions
diff --git a/crypto/src/asn1/DerEnumerated.cs b/crypto/src/asn1/DerEnumerated.cs
index 8654a3bfd..eb0555745 100644
--- a/crypto/src/asn1/DerEnumerated.cs
+++ b/crypto/src/asn1/DerEnumerated.cs
@@ -93,6 +93,12 @@ namespace Org.BouncyCastle.Asn1
             get { return new BigInteger(bytes); }
         }
 
+        public bool HasValue(int x)
+        {
+            return (bytes.Length - start) <= 4
+                && DerInteger.IntValue(bytes, start, DerInteger.SignExtSigned) == x;
+        }
+
         public bool HasValue(BigInteger x)
         {
             return null != x
diff --git a/crypto/src/asn1/DerInteger.cs b/crypto/src/asn1/DerInteger.cs
index 4f7b68d35..67916538b 100644
--- a/crypto/src/asn1/DerInteger.cs
+++ b/crypto/src/asn1/DerInteger.cs
@@ -113,6 +113,18 @@ namespace Org.BouncyCastle.Asn1
             get { return new BigInteger(bytes); }
         }
 
+        public bool HasValue(int x)
+        {
+            return (bytes.Length - start) <= 4
+                && IntValue(bytes, start, SignExtSigned) == x;
+        }
+
+        public bool HasValue(long x)
+        {
+            return (bytes.Length - start) <= 8
+                && LongValue(bytes, start, SignExtSigned) == x;
+        }
+
         public bool HasValue(BigInteger x)
         {
             return null != x
diff --git a/crypto/src/asn1/cms/AuthEnvelopedData.cs b/crypto/src/asn1/cms/AuthEnvelopedData.cs
index c6e1e3bb5..4ca86e9df 100644
--- a/crypto/src/asn1/cms/AuthEnvelopedData.cs
+++ b/crypto/src/asn1/cms/AuthEnvelopedData.cs
@@ -57,7 +57,7 @@ namespace Org.BouncyCastle.Asn1.Cms
 			// "It MUST be set to 0."
 			Asn1Object tmp = seq[index++].ToAsn1Object();
 			version = DerInteger.GetInstance(tmp);
-			if (version.IntValueExact != 0)
+			if (!version.HasValue(0))
 				throw new ArgumentException("AuthEnvelopedData version number must be 0");
 
 			tmp = seq[index++].ToAsn1Object();
diff --git a/crypto/src/asn1/cms/AuthEnvelopedDataParser.cs b/crypto/src/asn1/cms/AuthEnvelopedDataParser.cs
index 52f0bf720..950040b26 100644
--- a/crypto/src/asn1/cms/AuthEnvelopedDataParser.cs
+++ b/crypto/src/asn1/cms/AuthEnvelopedDataParser.cs
@@ -31,7 +31,7 @@ namespace Org.BouncyCastle.Asn1.Cms
 
 			// "It MUST be set to 0."
 			this.version = (DerInteger)seq.ReadObject();
-			if (version.IntValueExact != 0)
+			if (!version.HasValue(0))
 				throw new Asn1ParsingException("AuthEnvelopedData version number must be 0");
 		}
 
diff --git a/crypto/src/asn1/cms/EnvelopedData.cs b/crypto/src/asn1/cms/EnvelopedData.cs
index fbde00b28..8897fe380 100644
--- a/crypto/src/asn1/cms/EnvelopedData.cs
+++ b/crypto/src/asn1/cms/EnvelopedData.cs
@@ -154,7 +154,7 @@ namespace Org.BouncyCastle.Asn1.Cms
             {
                 RecipientInfo ri = RecipientInfo.GetInstance(o);
 
-                if (ri.Version.IntValueExact != 0)
+                if (!ri.Version.HasValue(0))
                 {
                     return 2;
                 }
diff --git a/crypto/src/asn1/cms/SignedData.cs b/crypto/src/asn1/cms/SignedData.cs
index 5eba8390d..1e97346e6 100644
--- a/crypto/src/asn1/cms/SignedData.cs
+++ b/crypto/src/asn1/cms/SignedData.cs
@@ -147,7 +147,7 @@ namespace Org.BouncyCastle.Asn1.Cms
             {
                 SignerInfo s = SignerInfo.GetInstance(obj);
 
-                if (s.Version.IntValueExact == 3)
+                if (s.Version.HasValue(3))
                 {
                     return true;
                 }
diff --git a/crypto/src/asn1/icao/LDSSecurityObject.cs b/crypto/src/asn1/icao/LDSSecurityObject.cs
index cda4aaa37..5d7331a4f 100644
--- a/crypto/src/asn1/icao/LDSSecurityObject.cs
+++ b/crypto/src/asn1/icao/LDSSecurityObject.cs
@@ -1,7 +1,6 @@
 using System;
 using System.Collections;
 
-using Org.BouncyCastle.Asn1;
 using Org.BouncyCastle.Asn1.X509;
 using Org.BouncyCastle.Math;
 
@@ -62,7 +61,7 @@ namespace Org.BouncyCastle.Asn1.Icao
 			e.MoveNext();
 			Asn1Sequence datagroupHashSeq = Asn1Sequence.GetInstance(e.Current);
 
-			if (version.Value.Equals(BigInteger.One))
+			if (version.HasValue(1))
 			{
 				e.MoveNext();
 				versionInfo = LdsVersionInfo.GetInstance(e.Current);
diff --git a/crypto/src/asn1/pkcs/EncryptedData.cs b/crypto/src/asn1/pkcs/EncryptedData.cs
index 6a4c04f25..cb04f343c 100644
--- a/crypto/src/asn1/pkcs/EncryptedData.cs
+++ b/crypto/src/asn1/pkcs/EncryptedData.cs
@@ -52,11 +52,9 @@ namespace Org.BouncyCastle.Asn1.Pkcs
 			if (seq.Count != 2)
 				throw new ArgumentException("Wrong number of elements in sequence", "seq");
 
-            int version = ((DerInteger)seq[0]).IntValueExact;
-			if (version != 0)
-            {
+            DerInteger version = (DerInteger)seq[0];
+			if (!version.HasValue(0))
                 throw new ArgumentException("sequence not version 0");
-            }
 
 			this.data = (Asn1Sequence) seq[1];
         }
diff --git a/crypto/src/asn1/pkcs/Pfx.cs b/crypto/src/asn1/pkcs/Pfx.cs
index 3aec8ed0f..e73701342 100644
--- a/crypto/src/asn1/pkcs/Pfx.cs
+++ b/crypto/src/asn1/pkcs/Pfx.cs
@@ -28,7 +28,7 @@ namespace Org.BouncyCastle.Asn1.Pkcs
             Asn1Sequence seq)
         {
             DerInteger version = DerInteger.GetInstance(seq[0]);
-            if (version.IntValueExact != 3)
+            if (!version.HasValue(3))
                 throw new ArgumentException("wrong version for PFX PDU");
 
             this.contentInfo = ContentInfo.GetInstance(seq[1]);
diff --git a/crypto/src/asn1/x509/AttributeCertificateInfo.cs b/crypto/src/asn1/x509/AttributeCertificateInfo.cs
index 29abaa6e4..d466bbd14 100644
--- a/crypto/src/asn1/x509/AttributeCertificateInfo.cs
+++ b/crypto/src/asn1/x509/AttributeCertificateInfo.cs
@@ -149,7 +149,7 @@ namespace Org.BouncyCastle.Asn1.X509
         {
             Asn1EncodableVector v = new Asn1EncodableVector(9);
 
-            if (version.IntValueExact != 0)
+            if (!version.HasValue(0))
             {
                 v.Add(version);
             }
diff --git a/crypto/src/asn1/x509/GeneralSubtree.cs b/crypto/src/asn1/x509/GeneralSubtree.cs
index a42ec4643..7dbacd229 100644
--- a/crypto/src/asn1/x509/GeneralSubtree.cs
+++ b/crypto/src/asn1/x509/GeneralSubtree.cs
@@ -173,7 +173,7 @@ namespace Org.BouncyCastle.Asn1.X509
 		{
 			Asn1EncodableVector v = new Asn1EncodableVector(baseName);
 
-			if (minimum != null && minimum.Value.SignValue != 0)
+			if (minimum != null && !minimum.HasValue(0))
 			{
 				v.Add(new DerTaggedObject(false, 0, minimum));
 			}
diff --git a/crypto/src/asn1/x509/TBSCertificateStructure.cs b/crypto/src/asn1/x509/TBSCertificateStructure.cs
index e600685f0..bd08d8bb8 100644
--- a/crypto/src/asn1/x509/TBSCertificateStructure.cs
+++ b/crypto/src/asn1/x509/TBSCertificateStructure.cs
@@ -1,6 +1,5 @@
 using System;
 
-using Org.BouncyCastle.Math;
 using Org.BouncyCastle.Utilities;
 
 namespace Org.BouncyCastle.Asn1.X509
@@ -82,15 +81,15 @@ namespace Org.BouncyCastle.Asn1.X509
             bool isV1 = false;
             bool isV2 = false;
 
-            if (version.Value.Equals(BigInteger.Zero))
+            if (version.HasValue(0))
             {
                 isV1 = true;
             }
-            else if (version.Value.Equals(BigInteger.One))
+            else if (version.HasValue(1))
             {
                 isV2 = true;
             }
-            else if (!version.Value.Equals(BigInteger.Two))
+            else if (!version.HasValue(2))
             {
                 throw new ArgumentException("version number not recognised");
             }
@@ -220,7 +219,7 @@ namespace Org.BouncyCastle.Asn1.X509
             Asn1EncodableVector v = new Asn1EncodableVector();
 
             // DEFAULT Zero
-            if (!version.HasValue(BigIntegers.Zero))
+            if (!version.HasValue(0))
             {
                 v.Add(new DerTaggedObject(true, 0, version));
             }
@@ -238,7 +237,7 @@ namespace Org.BouncyCastle.Asn1.X509
             }
             else
             {
-                v.Add(new DerSequence());
+                v.Add(DerSequence.Empty);
             }
 
             v.Add(subjectPublicKeyInfo);
diff --git a/crypto/src/asn1/x9/X9ECParameters.cs b/crypto/src/asn1/x9/X9ECParameters.cs
index e1b29ca13..aa84063b8 100644
--- a/crypto/src/asn1/x9/X9ECParameters.cs
+++ b/crypto/src/asn1/x9/X9ECParameters.cs
@@ -35,7 +35,7 @@ namespace Org.BouncyCastle.Asn1.X9
             Asn1Sequence seq)
         {
             if (!(seq[0] is DerInteger)
-                || !((DerInteger)seq[0]).Value.Equals(BigInteger.One))
+                || !((DerInteger)seq[0]).HasValue(1))
             {
                 throw new ArgumentException("bad version in X9ECParameters");
             }