public void testEncodeDefault() throws IOException {
//
// Boolean as default
//
ASN1Sequence s = new ASN1Sequence(new ASN1Type[] { ASN1Boolean
.getInstance() }) {
{
setDefault(Boolean.TRUE, 0);
}
protected void getValues(Object object, Object[] values) {
values = (Object[]) object;
}
};
byte[] expectedArray = new byte[] { 0x30, 0x00 };
byte[] encoded = s.encode(new Object[] { Boolean.TRUE });
assertTrue("Encoded boolean:", Arrays.equals(expectedArray, encoded));
//
// Integer as default
//
s = new ASN1Sequence(new ASN1Type[] { ASN1Integer.getInstance() }) {
{
setDefault(new byte[] { 0x01 }, 0);
}
protected void getValues(Object object, Object[] values) {
values = (Object[]) object;
}
};
encoded = s.encode(new Object[] { new byte[] { 0x01 } });
assertTrue("Encoded integer:", Arrays.equals(expectedArray, encoded));
}