diff options
author | Peter Dettman <peter.dettman@gmail.com> | 2022-06-16 21:01:50 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@gmail.com> | 2022-06-16 21:01:50 +0700 |
commit | ce32ad9ba2df136dceafdc1053c9847cfa7d3424 (patch) | |
tree | 4da962b98ecec59a0e4df8add3ea2dccf63320bb | |
parent | NUnit tweaks (diff) | |
download | BouncyCastle.NET-ed25519-ce32ad9ba2df136dceafdc1053c9847cfa7d3424.tar.xz |
Improve MiscTest
-rw-r--r-- | crypto/test/src/asn1/test/MiscTest.cs | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/crypto/test/src/asn1/test/MiscTest.cs b/crypto/test/src/asn1/test/MiscTest.cs index 2d005a187..3a7eb5af6 100644 --- a/crypto/test/src/asn1/test/MiscTest.cs +++ b/crypto/test/src/asn1/test/MiscTest.cs @@ -40,43 +40,58 @@ namespace Org.BouncyCastle.Asn1.Tests private void DoDerIntegerTest() { + SetAllowUnsafeProperty(false); + try { - new DerInteger(new byte[] { 0, 0, 0, 1}); + new DerInteger(new byte[]{ 0x00, 0x00, 0x00, 0x01}); + Fail("expected ArgumentException"); } catch (ArgumentException e) { - IsTrue("wrong exc", e.Message.StartsWith("malformed integer")); + IsTrue("wrong exc 1: " + e.Message, e.Message.StartsWith("malformed integer")); } try { - new DerInteger(new byte[] {(byte)0xff, (byte)0x80, 0, 1}); + new DerInteger(new byte[]{ 0xFF, 0x80, 0x00, 0x01}); + Fail("expected ArgumentException"); } catch (ArgumentException e) { - IsTrue("wrong exc", e.Message.StartsWith("malformed integer")); + IsTrue("wrong exc 2: " + e.Message, e.Message.StartsWith("malformed integer")); } try { - new DerEnumerated(new byte[] { 0, 0, 0, 1}); + new DerEnumerated(new byte[]{ 0x00, 0x00, 0x00, 0x01}); + Fail("expected ArgumentException"); } catch (ArgumentException e) { - IsTrue("wrong exc", e.Message.StartsWith("malformed enumerated")); + IsTrue("wrong exc 3: " + e.Message, e.Message.StartsWith("malformed enumerated")); } try { - new DerEnumerated(new byte[] {(byte)0xff, (byte)0x80, 0, 1}); + new DerEnumerated(new byte[]{ 0xFF, 0x80, 0x00, 0x01}); + Fail("expected ArgumentException"); } catch (ArgumentException e) { - IsTrue("wrong exc", e.Message.StartsWith("malformed enumerated")); + IsTrue("wrong exc 4: " + e.Message, e.Message.StartsWith("malformed enumerated")); } } + private void SetAllowUnsafeProperty(bool allowUnsafe) + { +#if NETCF_1_0 || NETCF_2_0 || SILVERLIGHT || (PORTABLE && !DOTNET) || NET_1_1 + // Can't SetEnvironmentVariable ! +#else + Environment.SetEnvironmentVariable(DerInteger.AllowUnsafeProperty, allowUnsafe ? "true" : "false"); +#endif + } + public override void PerformTest() { byte[] testIv = { 1, 2, 3, 4, 5, 6, 7, 8 }; |