diff --git a/crypto/test/src/asn1/test/ASN1IntegerTest.cs b/crypto/test/src/asn1/test/ASN1IntegerTest.cs
index 689a60ac5..3d0c6fcd0 100644
--- a/crypto/test/src/asn1/test/ASN1IntegerTest.cs
+++ b/crypto/test/src/asn1/test/ASN1IntegerTest.cs
@@ -3,6 +3,7 @@
using NUnit.Framework;
using Org.BouncyCastle.Math;
+using Org.BouncyCastle.Utilities;
using Org.BouncyCastle.Utilities.Encoders;
using Org.BouncyCastle.Utilities.Test;
@@ -128,7 +129,7 @@ namespace Org.BouncyCastle.Asn1.Tests
//
byte[] rawInt = Hex.Decode("10");
DerInteger i = new DerInteger(rawInt);
- IsEquals(i.Value.IntValue, 16);
+ CheckIntValue(i, 16);
//
// With property set.
@@ -137,7 +138,7 @@ namespace Org.BouncyCastle.Asn1.Tests
rawInt = Hex.Decode("10");
i = new DerInteger(rawInt);
- IsEquals(i.Value.IntValue, 16);
+ CheckIntValue(i, 16);
}
public void DoTestValidEncodingMultiByte()
@@ -149,7 +150,7 @@ namespace Org.BouncyCastle.Asn1.Tests
//
byte[] rawInt = Hex.Decode("10FF");
DerInteger i = new DerInteger(rawInt);
- IsEquals(i.Value.IntValue, 4351);
+ CheckIntValue(i, 4351);
//
// With property set.
@@ -158,7 +159,7 @@ namespace Org.BouncyCastle.Asn1.Tests
rawInt = Hex.Decode("10FF");
i = new DerInteger(rawInt);
- IsEquals(i.Value.IntValue, 4351);
+ CheckIntValue(i, 4351);
}
public void DoTestInvalidEncoding_00()
@@ -203,8 +204,7 @@ namespace Org.BouncyCastle.Asn1.Tests
try
{
byte[] rawInt = Hex.Decode("0000000010FF");
- DerInteger i = new DerInteger(rawInt);
- IsEquals(i.Value.IntValue, 4351);
+ new DerInteger(rawInt);
Fail("Expecting illegal argument exception.");
}
catch (ArgumentException e)
@@ -283,7 +283,7 @@ namespace Org.BouncyCastle.Asn1.Tests
SetAllowUnsafeProperty(true);
byte[] rawInt = Hex.Decode("00000010FF000000");
DerInteger i = new DerInteger(rawInt);
- IsEquals(72997666816L, i.Value.LongValue);
+ CheckLongValue(i, 72997666816L);
}
public void DoTestLooseValidEncoding_FF_32BAligned()
@@ -294,7 +294,7 @@ namespace Org.BouncyCastle.Asn1.Tests
SetAllowUnsafeProperty(true);
byte[] rawInt = Hex.Decode("FFFFFF10FF000000");
DerInteger i = new DerInteger(rawInt);
- IsEquals(-1026513960960L, i.Value.LongValue);
+ CheckLongValue(i, -1026513960960L);
}
public void DoTestLooseValidEncoding_FF_32BAligned_1not0()
@@ -305,7 +305,7 @@ namespace Org.BouncyCastle.Asn1.Tests
SetAllowUnsafeProperty(true);
byte[] rawInt = Hex.Decode("FFFEFF10FF000000");
DerInteger i = new DerInteger(rawInt);
- IsEquals(-282501490671616L, i.Value.LongValue);
+ CheckLongValue(i, -282501490671616L);
}
public void DoTestLooseValidEncoding_FF_32BAligned_2not0()
@@ -316,7 +316,7 @@ namespace Org.BouncyCastle.Asn1.Tests
SetAllowUnsafeProperty(true);
byte[] rawInt = Hex.Decode("FFFFFE10FF000000");
DerInteger i = new DerInteger(rawInt);
- IsEquals(-2126025588736L, i.Value.LongValue);
+ CheckLongValue(i, -2126025588736L);
}
public void DoTestOversizedEncoding()
@@ -358,6 +358,24 @@ namespace Org.BouncyCastle.Asn1.Tests
#endif
}
+ private void CheckIntValue(DerInteger i, int n)
+ {
+ BigInteger val = i.Value;
+ IsEquals(val.IntValue, n);
+ IsEquals(val.IntValueExact, n);
+ IsEquals(i.IntValueExact, n);
+ IsTrue(i.HasValue(n));
+ }
+
+ private void CheckLongValue(DerInteger i, long n)
+ {
+ BigInteger val = i.Value;
+ IsEquals(val.LongValue, n);
+ IsEquals(val.LongValueExact, n);
+ IsEquals(i.LongValueExact, n);
+ IsTrue(i.HasValue(n));
+ }
+
public static void Main(
string[] args)
{
diff --git a/crypto/test/src/asn1/test/CertificateTest.cs b/crypto/test/src/asn1/test/CertificateTest.cs
index c2593fad2..62ae6799c 100644
--- a/crypto/test/src/asn1/test/CertificateTest.cs
+++ b/crypto/test/src/asn1/test/CertificateTest.cs
@@ -360,8 +360,8 @@ namespace Org.BouncyCastle.Asn1.Tests
AttributeCertificateInfo acInfo = obj.ACInfo;
// Version
- if (!(acInfo.Version.Equals(new DerInteger(1)))
- && (!(acInfo.Version.Equals(new DerInteger(2)))))
+ DerInteger version = acInfo.Version;
+ if (!version.HasValue(1) && !version.HasValue(2))
{
Fail("failed AC Version test for id " + id);
}
@@ -427,7 +427,7 @@ namespace Org.BouncyCastle.Asn1.Tests
AttributeCertificateInfo acInfo = obj.ACInfo;
// Version
- if (acInfo.Version.IntValueExact != 0)
+ if (!acInfo.Version.HasValue(0))
{
Fail("failed AC Version test for id " + id);
}
diff --git a/crypto/test/src/asn1/test/EnumeratedTest.cs b/crypto/test/src/asn1/test/EnumeratedTest.cs
index 29e90326b..31ff133be 100644
--- a/crypto/test/src/asn1/test/EnumeratedTest.cs
+++ b/crypto/test/src/asn1/test/EnumeratedTest.cs
@@ -49,7 +49,8 @@ namespace Org.BouncyCastle.Asn1.Tests
Assert.IsNotNull(enumerated, "ENUMERATED expected");
- Assert.AreEqual(1, enumerated.Value.IntValue, "Unexpected ENUMERATED value");
+ Assert.AreEqual(1, enumerated.IntValueExact, "Unexpected ENUMERATED value");
+ Assert.IsTrue(enumerated.HasValue(1), "Unexpected ENUMERATED value");
DerBoolean boolean = sequence[1] as DerBoolean;
@@ -76,13 +77,15 @@ namespace Org.BouncyCastle.Asn1.Tests
Assert.IsNotNull(enumerated1, "ENUMERATED expected");
- Assert.AreEqual(257, enumerated1.Value.IntValue, "Unexpected ENUMERATED value");
+ Assert.AreEqual(257, enumerated1.IntValueExact, "Unexpected ENUMERATED value");
+ Assert.IsTrue(enumerated1.HasValue(257), "Unexpected ENUMERATED value");
DerEnumerated enumerated2 = sequence[1] as DerEnumerated;
Assert.IsNotNull(enumerated2, "ENUMERATED expected");
- Assert.AreEqual(514, enumerated2.Value.IntValue, "Unexpected ENUMERATED value");
+ Assert.AreEqual(514, enumerated2.IntValueExact, "Unexpected ENUMERATED value");
+ Assert.IsTrue(enumerated2.HasValue(514), "Unexpected ENUMERATED value");
}
/// <summary>
@@ -103,7 +106,8 @@ namespace Org.BouncyCastle.Asn1.Tests
Assert.IsNotNull(enumerated, "ENUMERATED expected");
- Assert.AreEqual(65793, enumerated.Value.IntValue, "Unexpected ENUMERATED value");
+ Assert.AreEqual(65793, enumerated.IntValueExact, "Unexpected ENUMERATED value");
+ Assert.IsTrue(enumerated.HasValue(65793), "Unexpected ENUMERATED value");
DerObjectIdentifier objectId = sequence[1] as DerObjectIdentifier;
diff --git a/crypto/test/src/test/CertTest.cs b/crypto/test/src/test/CertTest.cs
index 46276a75b..d83b67f8c 100644
--- a/crypto/test/src/test/CertTest.cs
+++ b/crypto/test/src/test/CertTest.cs
@@ -1719,7 +1719,7 @@ namespace Org.BouncyCastle.Tests
{
DerEnumerated reasonCode = (DerEnumerated)X509ExtensionUtilities.FromExtensionValue(ext);
- if (reasonCode.Value.IntValue != CrlReason.PrivilegeWithdrawn)
+ if (!reasonCode.HasValue(CrlReason.PrivilegeWithdrawn))
{
Fail("CRL entry reasonCode wrong");
}
@@ -1807,7 +1807,7 @@ namespace Org.BouncyCastle.Tests
{
DerEnumerated reasonCode = (DerEnumerated)X509ExtensionUtilities.FromExtensionValue(ext);
- if (reasonCode.Value.IntValue != CrlReason.PrivilegeWithdrawn)
+ if (!reasonCode.HasValue(CrlReason.PrivilegeWithdrawn))
{
Fail("CRL entry reasonCode wrong");
}
@@ -1895,7 +1895,7 @@ namespace Org.BouncyCastle.Tests
{
DerEnumerated reasonCode = (DerEnumerated)X509ExtensionUtilities.FromExtensionValue(ext);
- if (reasonCode.Value.IntValue != CrlReason.PrivilegeWithdrawn)
+ if (!reasonCode.HasValue(CrlReason.PrivilegeWithdrawn))
{
Fail("CRL entry reasonCode wrong");
}
@@ -1934,6 +1934,21 @@ namespace Org.BouncyCastle.Tests
if (crlEnt.SerialNumber.IntValue == 1)
{
oneFound = true;
+ Asn1OctetString extn = entry.GetExtensionValue(X509Extensions.ReasonCode);
+
+ if (extn != null)
+ {
+ DerEnumerated reasonCode = (DerEnumerated)X509ExtensionUtilities.FromExtensionValue(extn);
+
+ if (!reasonCode.HasValue(CrlReason.PrivilegeWithdrawn))
+ {
+ Fail("CRL entry reasonCode wrong");
+ }
+ }
+ else
+ {
+ Fail("CRL entry reasonCode not found");
+ }
}
else if (crlEnt.SerialNumber.IntValue == 2)
{
|