{
public TestResult perform()
{
byte[] data = { 0, 1, 0, 1, 0, 0, 1 };
DERObject values[] = {
new BERConstructedOctetString(data),
new BERSequence(new DERPrintableString("hello world")),
new BERSet(new DERPrintableString("hello world")),
new BERTaggedObject(0, new DERPrintableString("hello world")),
new DERApplicationSpecific(0 | DERTags.APPLICATION, data),
new DERBitString(data),
new DERBMPString("hello world"),
new DERBoolean(true),
new DERBoolean(false),
new DEREnumerated(100),
new DERGeneralizedTime(new Date()),
new DERGeneralString("hello world"),
new DERIA5String("hello"),
new DERInteger(1000),
new DERNull(),
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(0xff & (~(DERTags.TAGGED | DERTags.APPLICATION)), data),
new DERUTCTime(new Date()),
new DERUTF8String("hello world"),
new DERVisibleString("hello world")
};
try
{
ByteArrayOutputStream bOut = new ByteArrayOutputStream();
ASN1OutputStream aOut = new ASN1OutputStream(bOut);
for (int i = 0; i != values.length; i++)
{
aOut.writeObject(values[i]);
}
DERObject[] readValues = new DERObject[values.length];
ByteArrayInputStream bIn = new ByteArrayInputStream(bOut.toByteArray());
ASN1InputStream aIn = new ASN1InputStream(bIn);
for (int i = 0; i != values.length; i++)
{
DERObject o = aIn.readObject();
if (!o.equals(values[i]))
{
return new SimpleTestResult(false, getName() + ": Failed equality test for " + o);
}
if (o.hashCode() != values[i].hashCode())
{
return new SimpleTestResult(false, getName() + ": Failed hashCode test for " + o);
}
}
}