diff options
author | Peter Dettman <peter.dettman@bouncycastle.org> | 2015-12-28 17:50:36 +0700 |
---|---|---|
committer | Peter Dettman <peter.dettman@bouncycastle.org> | 2015-12-28 17:50:36 +0700 |
commit | 5cf99df42f7ee75979a0d7243b79eff844fdbcfd (patch) | |
tree | f4c8f4fb227ee1ce056541f14270652941794313 /crypto/test | |
parent | Clean up a few warnings (diff) | |
download | BouncyCastle.NET-ed25519-5cf99df42f7ee75979a0d7243b79eff844fdbcfd.tar.xz |
Various ASN.1 updates from Java API
Diffstat (limited to 'crypto/test')
-rw-r--r-- | crypto/test/src/asn1/test/DERApplicationSpecificTest.cs | 67 | ||||
-rw-r--r-- | crypto/test/src/asn1/test/EqualsAndHashCodeTest.cs | 6 |
2 files changed, 67 insertions, 6 deletions
diff --git a/crypto/test/src/asn1/test/DERApplicationSpecificTest.cs b/crypto/test/src/asn1/test/DERApplicationSpecificTest.cs index a61ae87e8..e505acd9d 100644 --- a/crypto/test/src/asn1/test/DERApplicationSpecificTest.cs +++ b/crypto/test/src/asn1/test/DERApplicationSpecificTest.cs @@ -30,14 +30,73 @@ namespace Org.BouncyCastle.Asn1.Tests + "75F6C5F2E2D21F0395683B532A26E4C189B71EFE659C3F26E0EB9AEAE9986310" + "7F9B0DADA16414FFA204516AEE2B"); - public override string Name + private static readonly byte[] sampleData = Hex.Decode( + "613280020780a106060456000104a203020101a305a103020101be80288006025101020109a080b2800a01000000000000000000"); + + public override string Name { get { return "DerApplicationSpecific"; } } - public override void PerformTest() + private void TestTaggedObject() + { + // boolean explicit, int tagNo, ASN1Encodable obj + bool isExplicit = false; + + // Type1 ::= VisibleString + DerVisibleString type1 = new DerVisibleString("Jones"); + if (!Arrays.AreEqual(Hex.Decode("1A054A6F6E6573"), type1.GetEncoded())) + { + Fail("ERROR: expected value doesn't match!"); + } + + // Type2 ::= [APPLICATION 3] IMPLICIT Type1 + isExplicit = false; + DerApplicationSpecific type2 = new DerApplicationSpecific(isExplicit, 3, type1); + // type2.isConstructed() + if (!Arrays.AreEqual(Hex.Decode("43054A6F6E6573"), type2.GetEncoded())) + { + Fail("ERROR: expected value doesn't match!"); + } + + // Type3 ::= [2] Type2 + isExplicit = true; + DerTaggedObject type3 = new DerTaggedObject(isExplicit, 2, type2); + if (!Arrays.AreEqual(Hex.Decode("A20743054A6F6E6573"), type3.GetEncoded())) + { + Fail("ERROR: expected value doesn't match!"); + } + + // Type4 ::= [APPLICATION 7] IMPLICIT Type3 + isExplicit = false; + DerApplicationSpecific type4 = new DerApplicationSpecific(isExplicit, 7, type3); + if (!Arrays.AreEqual(Hex.Decode("670743054A6F6E6573"), type4.GetEncoded())) + { + Fail("ERROR: expected value doesn't match!"); + } + + // Type5 ::= [2] IMPLICIT Type2 + isExplicit = false; + DerTaggedObject type5 = new DerTaggedObject(isExplicit, 2, type2); + // type5.isConstructed() + if (!Arrays.AreEqual(Hex.Decode("82054A6F6E6573"), type5.GetEncoded())) + { + Fail("ERROR: expected value doesn't match!"); + } + } + + public override void PerformTest() { - DerInteger val = new DerInteger(9); + TestTaggedObject(); + + DerApplicationSpecific appSpec = (DerApplicationSpecific)Asn1Object.FromByteArray(sampleData); + + if (1 != appSpec.ApplicationTag) + { + Fail("wrong tag detected"); + } + + DerInteger val = new DerInteger(9); DerApplicationSpecific tagged = new DerApplicationSpecific(false, 3, val); @@ -65,8 +124,6 @@ namespace Org.BouncyCastle.Asn1.Tests if (!Arrays.AreEqual(certData, encoded)) { - Console.WriteLine(Encoding.ASCII.GetString(certData, 0, certData.Length).Substring(0, 20)); - Console.WriteLine(Encoding.ASCII.GetString(encoded, 0, encoded.Length).Substring(0, 20)); Fail("re-encoding of certificate data failed"); } } diff --git a/crypto/test/src/asn1/test/EqualsAndHashCodeTest.cs b/crypto/test/src/asn1/test/EqualsAndHashCodeTest.cs index 7e0695341..91329fbd5 100644 --- a/crypto/test/src/asn1/test/EqualsAndHashCodeTest.cs +++ b/crypto/test/src/asn1/test/EqualsAndHashCodeTest.cs @@ -3,6 +3,8 @@ using System.IO; using NUnit.Framework; +using Org.BouncyCastle.Utilities; +using Org.BouncyCastle.Utilities.Encoders; using Org.BouncyCastle.Utilities.Test; namespace Org.BouncyCastle.Asn1.Tests @@ -43,7 +45,9 @@ namespace Org.BouncyCastle.Asn1.Tests new DerUniversalString(data), new DerUtcTime(new DateTime()), new DerUtf8String("hello world"), - new DerVisibleString("hello world") + new DerVisibleString("hello world"), + new DerGraphicString(Hex.Decode("deadbeef")), + new DerVideotexString(Strings.ToByteArray("Hello World")) }; MemoryStream bOut = new MemoryStream(); |