use of co.nstant.in.cbor.CborEncoder in project identity-credential by google.
the class UtilTests method cborCalendarForeign.
@Test
public void cborCalendarForeign() throws CborException {
ByteArrayOutputStream baos;
byte[] data;
// milliseconds, non-standard format
baos = new ByteArrayOutputStream();
new CborEncoder(baos).encode(new CborBuilder().addTag(0).add("2019-07-08T11:51:42.25Z").build());
data = baos.toByteArray();
assertEquals("tag 0 '2019-07-08T11:51:42.250Z'", Util.cborPrettyPrint(Util.cborEncodeDateTime(Util.cborDecodeDateTime(data))));
// milliseconds set to 0
baos = new ByteArrayOutputStream();
new CborEncoder(baos).encode(new CborBuilder().addTag(0).add("2019-07-08T11:51:42.0Z").build());
data = baos.toByteArray();
assertEquals("tag 0 '2019-07-08T11:51:42Z'", Util.cborPrettyPrint(Util.cborEncodeDateTime(Util.cborDecodeDateTime(data))));
// we only support millisecond-precision
baos = new ByteArrayOutputStream();
new CborEncoder(baos).encode(new CborBuilder().addTag(0).add("2019-07-08T11:51:42.9876Z").build());
data = baos.toByteArray();
assertEquals("tag 0 '2019-07-08T11:51:42.987Z'", Util.cborPrettyPrint(Util.cborEncodeDateTime(Util.cborDecodeDateTime(data))));
// milliseconds and timezone
baos = new ByteArrayOutputStream();
new CborEncoder(baos).encode(new CborBuilder().addTag(0).add("2019-07-08T11:51:42.26-11:30").build());
data = baos.toByteArray();
assertEquals("tag 0 '2019-07-08T11:51:42.260-11:30'", Util.cborPrettyPrint(Util.cborEncodeDateTime(Util.cborDecodeDateTime(data))));
}
use of co.nstant.in.cbor.CborEncoder in project identity-credential by google.
the class UtilTests method prettyPrintTag.
@Test
public void prettyPrintTag() throws CborException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new CborEncoder(baos).encode(new CborBuilder().addTag(0).add("ABC").build());
byte[] data = baos.toByteArray();
assertEquals("tag 0 'ABC'", Util.cborPrettyPrint(data));
}
use of co.nstant.in.cbor.CborEncoder in project identity-credential by google.
the class UtilTests method prettyPrintNull.
@Test
public void prettyPrintNull() throws CborException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new CborEncoder(baos).encode(new SimpleValue(SimpleValueType.NULL));
assertEquals("null", Util.cborPrettyPrint(baos.toByteArray()));
}
use of co.nstant.in.cbor.CborEncoder in project identity-credential by google.
the class UtilTests method prettyPrintString.
@Test
public void prettyPrintString() throws CborException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new CborEncoder(baos).encode(new UnicodeString("foobar"));
assertEquals("'foobar'", Util.cborPrettyPrint(baos.toByteArray()));
}
use of co.nstant.in.cbor.CborEncoder in project identity-credential by google.
the class UtilTests method prettyPrintMultipleCompleteTypes.
@Test
public void prettyPrintMultipleCompleteTypes() throws CborException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
new CborEncoder(baos).encode(new CborBuilder().add(// add string
"text").add(// add integer
1234).add(// add byte array
new byte[] { 0x10 }).addArray().add(1).add("text").end().build());
assertEquals("'text',\n" + "1234,\n" + "[0x10],\n" + "[1, 'text']", Util.cborPrettyPrint(baos.toByteArray()));
}
Aggregations