public override void PerformTest() { byte[] data = { 0, 1, 0, 1, 0, 0, 1 }; Asn1Object[] values = { new BerOctetString(data), new BerSequence(new DerPrintableString("hello world")), new BerSet(new DerPrintableString("hello world")), new BerTaggedObject(0, new DerPrintableString("hello world")), new DerApplicationSpecific(0, data), new DerBitString(data), new DerBmpString("hello world"), DerBoolean.True, DerBoolean.False, new DerEnumerated(100), new DerGeneralizedTime("20070315173729Z"), new DerGeneralString("hello world"), new DerIA5String("hello"), new DerInteger(1000), DerNull.Instance, new DerNumericString("123456"), new DerObjectIdentifier("1.1.1.10000.1"), new DerOctetString(data), new DerPrintableString("hello world"), new DerSequence(new DerPrintableString("hello world")), new DerSet(new DerPrintableString("hello world")), new DerT61String("hello world"), new DerTaggedObject(0, new DerPrintableString("hello world")), new DerUniversalString(data), new DerUnknownTag(true, 500,data), new DerUtcTime(new DateTime()), new DerUtf8String("hello world"), new DerVisibleString("hello world") }; MemoryStream bOut = new MemoryStream(); Asn1OutputStream aOut = new Asn1OutputStream(bOut); for (int i = 0; i != values.Length; i++) { aOut.WriteObject(values[i]); } Asn1InputStream aIn = new Asn1InputStream(bOut.ToArray()); for (int i = 0; i != values.Length; i++) { Asn1Object o = aIn.ReadObject(); if (!o.Equals(values[i])) { Fail("Failed equality test for " + o.GetType().Name); } if (o.GetHashCode() != values[i].GetHashCode()) { Fail("Failed hashCode test for " + o.GetType().Name); } } }
public ITestResult Perform() { byte[] testIv = { 1, 2, 3, 4, 5, 6, 7, 8 }; Asn1Encodable[] values = { new Cast5CbcParameters(testIv, 128), new NetscapeCertType(NetscapeCertType.Smime), new VerisignCzagExtension(new DerIA5String("hello")), #if INCLUDE_IDEA new IdeaCbcPar(testIv), #endif new NetscapeRevocationUrl(new DerIA5String("http://test")) }; #if INCLUDE_IDEA byte[] data = Base64.Decode("MA4ECAECAwQFBgcIAgIAgAMCBSAWBWhlbGxvMAoECAECAwQFBgcIFgtodHRwOi8vdGVzdA=="); #else byte[] data = Base64.Decode("MA4ECAECAwQFBgcIAgIAgAMCBSAWBWhlbGxvFgtodHRwOi8vdGVzdA=="); #endif try { MemoryStream bOut = new MemoryStream(); Asn1OutputStream aOut = new Asn1OutputStream(bOut); for (int i = 0; i != values.Length; i++) { aOut.WriteObject(values[i]); } if (!Arrays.AreEqual(bOut.ToArray(), data)) { return(new SimpleTestResult(false, Name + ": Failed data check")); } Asn1InputStream aIn = new Asn1InputStream(bOut.ToArray()); for (int i = 0; i != values.Length; i++) { Asn1Object o = aIn.ReadObject(); if (!values[i].Equals(o)) { return(new SimpleTestResult(false, Name + ": Failed equality test for " + o)); } if (o.GetHashCode() != values[i].GetHashCode()) { return(new SimpleTestResult(false, Name + ": Failed hashCode test for " + o)); } } return(new SimpleTestResult(true, Name + ": Okay")); } catch (Exception e) { return(new SimpleTestResult(false, Name + ": Failed - exception " + e.ToString(), e)); } }
public override void PerformTest() { byte[] testIv = { 1, 2, 3, 4, 5, 6, 7, 8 }; Asn1Encodable[] values = { new Cast5CbcParameters(testIv, 128), new NetscapeCertType(NetscapeCertType.Smime), new VerisignCzagExtension(new DerIA5String("hello")), new IdeaCbcPar(testIv), new NetscapeRevocationUrl(new DerIA5String("http://test")) }; byte[] data = Base64.Decode("MA4ECAECAwQFBgcIAgIAgAMCBSAWBWhlbGxvMAoECAECAwQFBgcIFgtodHRwOi8vdGVzdA=="); MemoryStream bOut = new MemoryStream(); Asn1OutputStream aOut = new Asn1OutputStream(bOut); for (int i = 0; i != values.Length; i++) { aOut.WriteObject(values[i]); } if (!Arrays.AreEqual(bOut.ToArray(), data)) { Fail("Failed data check"); } Asn1InputStream aIn = new Asn1InputStream(bOut.ToArray()); for (int i = 0; i != values.Length; i++) { Asn1Object o = aIn.ReadObject(); if (!values[i].Equals(o)) { Fail("Failed equality test for " + o); } if (o.GetHashCode() != values[i].GetHashCode()) { Fail("Failed hashCode test for " + o); } } DoShouldFailOnExtraData(); DoDerIntegerTest(); }
protected override int Asn1GetHashCode() { int num = externalContent.GetHashCode(); if (directReference != null) { num ^= directReference.GetHashCode(); } if (indirectReference != null) { num ^= indirectReference.GetHashCode(); } if (dataValueDescriptor != null) { num ^= dataValueDescriptor.GetHashCode(); } return(num); }