Search in sources :

Example 21 with CBORParser

use of com.fasterxml.jackson.dataformat.cbor.CBORParser in project jackson-dataformats-binary by FasterXML.

the class BigNumbersTest method _testBigInteger.

private void _testBigInteger(BigInteger expValue) throws Exception {
    final ByteArrayOutputStream sourceBytes = new ByteArrayOutputStream();
    final CBORGenerator sourceGen = cborGenerator(sourceBytes);
    sourceGen.writeNumber(expValue);
    sourceGen.close();
    // but verify that the original content can be parsed
    CBORParser parser = cborParser(sourceBytes.toByteArray());
    assertToken(JsonToken.VALUE_NUMBER_INT, parser.nextToken());
    assertEquals(expValue, parser.getBigIntegerValue());
    // also, coercion to long at least
    long expL = expValue.longValue();
    assertEquals(expL, parser.getLongValue());
    // and int, if feasible
    if (expL >= Integer.MIN_VALUE && expL <= Integer.MAX_VALUE) {
        assertEquals((int) expL, parser.getIntValue());
    }
    assertNull(parser.nextToken());
    parser.close();
}
Also used : CBORParser(com.fasterxml.jackson.dataformat.cbor.CBORParser) ByteArrayOutputStream(java.io.ByteArrayOutputStream) CBORGenerator(com.fasterxml.jackson.dataformat.cbor.CBORGenerator)

Example 22 with CBORParser

use of com.fasterxml.jackson.dataformat.cbor.CBORParser in project jans by JanssenProject.

the class AuthenticatorDataParser method getCborDataSize.

private long getCborDataSize(byte[] cosePublicKeyBuffer) {
    long keySize = 0;
    CBORParser parser = null;
    try {
        parser = dataMapperService.cborCreateParser(cosePublicKeyBuffer);
        while (!parser.isClosed()) {
            JsonToken t = parser.nextToken();
            if (t.isStructEnd()) {
                JsonLocation tocloc = parser.getTokenLocation();
                keySize = tocloc.getByteOffset();
                break;
            }
        }
    } catch (IOException e) {
        throw new Fido2RuntimeException(e.getMessage(), e);
    } finally {
        if (parser != null) {
            try {
                parser.close();
            } catch (IOException e) {
                log.error("Exception when closing a parser {}", e.getMessage());
            }
        }
    }
    return keySize;
}
Also used : JsonLocation(com.fasterxml.jackson.core.JsonLocation) CBORParser(com.fasterxml.jackson.dataformat.cbor.CBORParser) JsonToken(com.fasterxml.jackson.core.JsonToken) IOException(java.io.IOException) Fido2RuntimeException(io.jans.fido2.exception.Fido2RuntimeException)

Aggregations

CBORParser (com.fasterxml.jackson.dataformat.cbor.CBORParser)22 StreamReadException (com.fasterxml.jackson.core.exc.StreamReadException)9 CBORGenerator (com.fasterxml.jackson.dataformat.cbor.CBORGenerator)9 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 JsonGenerator (com.fasterxml.jackson.core.JsonGenerator)1 JsonLocation (com.fasterxml.jackson.core.JsonLocation)1 JsonToken (com.fasterxml.jackson.core.JsonToken)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 PublicKey (com.quorum.tessera.encryption.PublicKey)1 Fido2RuntimeException (io.jans.fido2.exception.Fido2RuntimeException)1 IOException (java.io.IOException)1 BigDecimal (java.math.BigDecimal)1