diff options
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/crypto.csproj | 5 | ||||
-rw-r--r-- | crypto/crypto.mdp | 1 | ||||
-rw-r--r-- | crypto/test/src/asn1/test/EnumeratedTest.cs | 113 |
3 files changed, 119 insertions, 0 deletions
diff --git a/crypto/crypto.csproj b/crypto/crypto.csproj index 6f4ba1500..875b1f1b4 100644 --- a/crypto/crypto.csproj +++ b/crypto/crypto.csproj @@ -9202,6 +9202,11 @@ BuildAction = "Compile" /> <File + RelPath = "test\src\asn1\test\EnumeratedTest.cs" + SubType = "Code" + BuildAction = "Compile" + /> + <File RelPath = "test\src\asn1\test\EssCertIDv2UnitTest.cs" SubType = "Code" BuildAction = "Compile" diff --git a/crypto/crypto.mdp b/crypto/crypto.mdp index 83992ae81..f263c7eb2 100644 --- a/crypto/crypto.mdp +++ b/crypto/crypto.mdp @@ -851,6 +851,7 @@ <File subtype="Code" buildaction="Compile" name="test/src/asn1/test/DERUTF8StringTest.cs" /> <File subtype="Code" buildaction="Compile" name="test/src/asn1/test/EncryptedPrivateKeyInfoTest.cs" /> <File subtype="Code" buildaction="Compile" name="test/src/asn1/test/EqualsAndHashCodeTest.cs" /> + <File subtype="Code" buildaction="Compile" name="test/src/asn1/test/EnumeratedTest.cs" /> <File subtype="Code" buildaction="Compile" name="test/src/asn1/test/GeneralizedTimeTest.cs" /> <File subtype="Code" buildaction="Compile" name="test/src/asn1/test/GenerationTest.cs" /> <File subtype="Code" buildaction="Compile" name="test/src/asn1/test/InputStreamTest.cs" /> diff --git a/crypto/test/src/asn1/test/EnumeratedTest.cs b/crypto/test/src/asn1/test/EnumeratedTest.cs new file mode 100644 index 000000000..d881e4c3e --- /dev/null +++ b/crypto/test/src/asn1/test/EnumeratedTest.cs @@ -0,0 +1,113 @@ +namespace crypto.test.src.asn1.test +{ + using NUnit.Framework; + + using Org.BouncyCastle.Asn1; + using Org.BouncyCastle.Utilities.Encoders; + + /// <summary> + /// Tests used to verify correct decoding of the ENUMERATED type. + /// </summary> + [TestFixture] + public class EnumeratedTest + { + /// <summary> + /// Test vector used to test decoding of multiple items. + /// </summary> + /// <remarks>This sample uses an ENUMERATED and a BOOLEAN.</remarks> + private static readonly byte[] MultipleSingleByteItems = Hex.Decode("30060a01010101ff"); + + /// <summary> + /// Test vector used to test decoding of multiple items. + /// </summary> + /// <remarks>This sample uses two ENUMERATEDs.</remarks> + private static readonly byte[] MultipleDoubleByteItems = Hex.Decode("30080a0201010a020202"); + + /// <summary> + /// Test vector used to test decoding of multiple items. + /// </summary> + /// <remarks>This sample uses an ENUMERATED and an OBJECT IDENTIFIER.</remarks> + private static readonly byte[] MultipleTripleByteItems = Hex.Decode("300a0a0301010106032b0601"); + + /// <summary> + /// Makes sure multiple identically sized values are parsed correctly. + /// </summary> + [Test] + public void TestReadingMultipleSingleByteItems() + { + Asn1Object obj = Asn1Object.FromByteArray(MultipleSingleByteItems); + + Assert.IsTrue(obj is DerSequence, "Null ASN.1 SEQUENCE"); + + DerSequence sequence = (DerSequence)obj; + + Assert.AreEqual(2, sequence.Count, "2 items expected"); + + DerEnumerated enumerated = sequence[0] as DerEnumerated; + + Assert.IsNotNull(enumerated, "ENUMERATED expected"); + + Assert.AreEqual(1, enumerated.Value.IntValue, "Unexpected ENUMERATED value"); + + DerBoolean boolean = sequence[1] as DerBoolean; + + Assert.IsNotNull(boolean, "BOOLEAN expected"); + + Assert.IsTrue(boolean.IsTrue, "Unexpected BOOLEAN value"); + } + + /// <summary> + /// Makes sure multiple identically sized values are parsed correctly. + /// </summary> + [Test] + public void TestReadingMultipleDoubleByteItems() + { + Asn1Object obj = Asn1Object.FromByteArray(MultipleDoubleByteItems); + + Assert.IsTrue(obj is DerSequence, "Null ASN.1 SEQUENCE"); + + DerSequence sequence = (DerSequence)obj; + + Assert.AreEqual(2, sequence.Count, "2 items expected"); + + DerEnumerated enumerated1 = sequence[0] as DerEnumerated; + + Assert.IsNotNull(enumerated1, "ENUMERATED expected"); + + Assert.AreEqual(257, enumerated1.Value.IntValue, "Unexpected ENUMERATED value"); + + DerEnumerated enumerated2 = sequence[1] as DerEnumerated; + + Assert.IsNotNull(enumerated2, "ENUMERATED expected"); + + Assert.AreEqual(514, enumerated2.Value.IntValue, "Unexpected ENUMERATED value"); + } + + /// <summary> + /// Makes sure multiple identically sized values are parsed correctly. + /// </summary> + [Test] + public void TestReadingMultipleTripleByteItems() + { + Asn1Object obj = Asn1Object.FromByteArray(MultipleTripleByteItems); + + Assert.IsTrue(obj is DerSequence, "Null ASN.1 SEQUENCE"); + + DerSequence sequence = (DerSequence)obj; + + Assert.AreEqual(2, sequence.Count, "2 items expected"); + + DerEnumerated enumerated = sequence[0] as DerEnumerated; + + Assert.IsNotNull(enumerated, "ENUMERATED expected"); + + Assert.AreEqual(65793, enumerated.Value.IntValue, "Unexpected ENUMERATED value"); + + DerObjectIdentifier objectId = sequence[1] as DerObjectIdentifier; + + Assert.IsNotNull(objectId, "OBJECT IDENTIFIER expected"); + + Assert.AreEqual("1.3.6.1", objectId.Id, "Unexpected OBJECT IDENTIFIER value"); + } + } +} |