Java Code Examples for co.nstant.in.cbor.model.Array#add()

The following examples show how to use co.nstant.in.cbor.model.Array#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PackedAttestationStatement.java    From webauthndemo with Apache License 2.0 6 votes vote down vote up
@Override
DataItem encode() throws CborException {
  Map result = new Map();
  if (attestnCert != null) {
    Array x5c = new Array();
    x5c.add(new ByteString(attestnCert));
    for (byte[] cert : this.caCert) {
      x5c.add(new ByteString(cert));
    }
    result.put(new UnicodeString("x5c"), x5c);
  }
  if (ecdaaKeyId != null) {
    result.put(new UnicodeString("ecdaaKeyId"), new ByteString(ecdaaKeyId));
  }
  result.put(new UnicodeString("sig"), new ByteString(sig));
  result.put(new UnicodeString("alg"), new UnicodeString(alg.toString()));

  return result;
}
 
Example 2
Source File: ArrayDecoder.java    From cbor-java with Apache License 2.0 6 votes vote down vote up
private Array decodeInfinitiveLength() throws CborException {
    Array array = new Array();
    array.setChunked(true);
    if (decoder.isAutoDecodeInfinitiveArrays()) {
        DataItem dataItem;
        for (;;) {
            dataItem = decoder.decodeNext();
            if (dataItem == null) {
                throw new CborException("Unexpected end of stream");
            }
            if (Special.BREAK.equals(dataItem)) {
                array.add(Special.BREAK);
                break;
            }
            array.add(dataItem);
        }
    }
    return array;
}
 
Example 3
Source File: RationalNumberEncoderTest.java    From cbor-java with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldEncode() throws CborException {
    encoder.encode(new RationalNumber(ONE, TWO));
    ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
    CborDecoder decoder = new CborDecoder(inputStream);

    Array expected = new Array();
    expected.setTag(11);
    expected.add(ONE);
    expected.add(TWO);

    Object object = decoder.decodeNext();
    assertTrue(object instanceof Array);
    Array decoded = (Array) object;

    assertEquals(new Tag(30), decoded.getTag());
    assertEquals(2, decoded.getDataItems().size());
    assertEquals(ONE, decoded.getDataItems().get(0));
    assertEquals(TWO, decoded.getDataItems().get(1));
}
 
Example 4
Source File: FidoU2fAttestationStatement.java    From webauthndemo with Apache License 2.0 5 votes vote down vote up
@Override
DataItem encode() throws CborException {
  Map result = new Map();
  Array x5c = new Array();
  x5c.add(new ByteString(attestnCert));
  for (byte[] cert : this.caCert) {
    x5c.add(new ByteString(cert));
  }
  result.put(new UnicodeString("x5c"), x5c);
  result.put(new UnicodeString("sig"), new ByteString(sig));

  return result;
}
 
Example 5
Source File: ArrayDecoder.java    From cbor-java with Apache License 2.0 5 votes vote down vote up
private Array decodeFixedLength(long length) throws CborException {
    Array array = new Array(getPreallocationSize(length));
    for (long i = 0; i < length; i++) {
        DataItem dataItem = decoder.decodeNext();
        if (dataItem == null) {
            throw new CborException("Unexpected end of stream");
        }
        array.add(dataItem);
    }
    return array;
}