summary refs log tree commit diff
path: root/crypto/test
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2024-03-19 15:36:02 +0700
committerPeter Dettman <peter.dettman@bouncycastle.org>2024-03-19 15:36:02 +0700
commitb5a304895fa39de0f714332e04fb42223874a2f0 (patch)
tree403b879c6401d6509855f3fb26cde6bec4b31aa2 /crypto/test
parentEdDSA: Explicit guard against infinite looping (diff)
downloadBouncyCastle.NET-ed25519-b5a304895fa39de0f714332e04fb42223874a2f0.tar.xz
Sanity checks and refactoring in Bcpg.Sig
Diffstat (limited to 'crypto/test')
-rw-r--r--crypto/test/src/openpgp/test/BytesBooleansTest.cs68
1 files changed, 68 insertions, 0 deletions
diff --git a/crypto/test/src/openpgp/test/BytesBooleansTest.cs b/crypto/test/src/openpgp/test/BytesBooleansTest.cs
new file mode 100644

index 000000000..3b6c8a577 --- /dev/null +++ b/crypto/test/src/openpgp/test/BytesBooleansTest.cs
@@ -0,0 +1,68 @@ +using System; + +using NUnit.Framework; + +using Org.BouncyCastle.Bcpg.Sig; + +namespace Org.BouncyCastle.Bcpg.OpenPgp.Tests +{ + [TestFixture] + public class BytesBooleansTest + { + [Test] + public void TestParseFalse() + { + PrimaryUserId primaryUserID = new PrimaryUserId(true, false); + byte[] bFalse = primaryUserID.GetData(); + + Assert.AreEqual(1, bFalse.Length); + Assert.AreEqual(0, bFalse[0]); + Assert.False(primaryUserID.IsPrimaryUserId()); + } + + [Test] + public void TestParseTrue() + { + PrimaryUserId primaryUserID = new PrimaryUserId(true, true); + byte[] bTrue = primaryUserID.GetData(); + + Assert.AreEqual(1, bTrue.Length); + Assert.AreEqual(1, bTrue[0]); + Assert.True(primaryUserID.IsPrimaryUserId()); + } + + [Test] + public void TestParseTooShort() + { + PrimaryUserId primaryUserID = new PrimaryUserId(true, false, new byte[0]); + byte[] bTooShort = primaryUserID.GetData(); + + try + { + primaryUserID.IsPrimaryUserId(); + Assert.Fail("Should throw."); + } + catch (InvalidOperationException) + { + // expected. + } + } + + [Test] + public void TestParseTooLong() + { + PrimaryUserId primaryUserID = new PrimaryUserId(true, false, new byte[42]); + byte[] bTooLong = primaryUserID.GetData(); + + try + { + primaryUserID.IsPrimaryUserId(); + Assert.Fail("Should throw."); + } + catch (InvalidOperationException) + { + // expected. + } + } + } +}