ByteArrayOutputStream collector = new ByteArrayOutputStream();
DEROutputStream der = new DEROutputStream(collector);
ASN1EncodableVector fields = new ASN1EncodableVector();
int result = getResult();
if (result != UNSPECIFIED_RESULT) {
fields.add(new DERTaggedObject(true, 0,
new DEREnumerated(result)));
}
String mechanism = getMechanism();
if (mechanism != null) {
fields.add(new DERTaggedObject(true, 1,
new DERObjectIdentifier(mechanism)));
}
byte[] mechanismToken = getMechanismToken();
if (mechanismToken != null) {
fields.add(new DERTaggedObject(true, 2,
new DEROctetString(mechanismToken)));
}
byte[] mechanismListMIC = getMechanismListMIC();
if (mechanismListMIC != null) {
fields.add(new DERTaggedObject(true, 3,
new DEROctetString(mechanismListMIC)));
}
der.writeObject(new DERTaggedObject(true, 1,
new DERSequence(fields)));
return collector.toByteArray();
} catch (IOException ex) {
throw new IllegalStateException(ex.getMessage());
}