@Test public void toByteArray() throws ReflectiveOperationException { final byte[] expected = new byte[]{0, 1, 2, 3, 4, 5}; assertToByteArray("Wrap", expected, ByteBuffer.wrap(expected)); assertToByteArray("Wrap-RO", expected, ByteBuffer.wrap(expected).asReadOnlyBuffer()); assertToByteArray("Wrap-Truncated-Sliced", expected, ByteBuffer.wrap(new byte[]{0, 1, 2, 3, 4, 5, 6}, 0, 6).slice()); assertToByteArray("Wrap-Offset-Sliced", expected, ByteBuffer.wrap(new byte[]{6, 0, 1, 2, 3, 4, 5, 6}, 1, 6).slice()); assertToByteArray("Wrap-Truncated", expected, ByteBuffer.wrap(new byte[]{0, 1, 2, 3, 4, 5, 6}, 0, 6)); assertToByteArray("Wrap-Offset", expected, ByteBuffer.wrap(new byte[]{6, 0, 1, 2, 3, 4, 5, 6}, 1, 6)); ByteBuffer buff = ByteBuffer.allocate(expected.length + 10); buff.put(expected); buff.flip(); assertToByteArray("Normal", expected, buff); buff = ByteBuffer.allocateDirect(expected.length + 10); buff.put(expected); buff.flip(); assertToByteArray("Direct", expected, buff); }
private static byte[] toByteArray(ByteBuffer buffer) { buffer = buffer.duplicate(); if (buffer.hasArray() && buffer.arrayOffset() == 0) { byte[] result = buffer.array(); if (buffer.remaining() == result.length) { return result; } } byte[] result = new byte[buffer.remaining()]; buffer.get(result); return result; }
DynamoDBEncryptor { private static byte[] toByteArray(ByteBuffer buffer) { buffer = buffer.duplicate(); if (buffer.hasArray() && buffer.arrayOffset() == 0) { byte[] result = buffer.array(); if (buffer.remaining() == result.length) { return result; } } byte[] result = new byte[buffer.remaining()]; buffer.get(result); return result; } }
DynamoDBEncryptor { private static byte[] toByteArray(ByteBuffer buffer) { buffer = buffer.duplicate(); if (buffer.hasArray() && buffer.arrayOffset() == 0) { byte[] result = buffer.array(); if (buffer.remaining() == result.length) { return result; } } byte[] result = new byte[buffer.remaining()]; buffer.get(result); return result; } protected  DynamoDBEncryptor(EncryptionMaterialsProvider provider, String descriptionBase); }
DynamoDBEncryptor { private static byte[] toByteArray(ByteBuffer buffer) { buffer = buffer.duplicate(); if (buffer.hasArray() && buffer.arrayOffset() == 0) { byte[] result = buffer.array(); if (buffer.remaining() == result.length) { return result; } } byte[] result = new byte[buffer.remaining()]; buffer.get(result); return result; } protected  DynamoDBEncryptor(EncryptionMaterialsProvider provider, String descriptionBase); static DynamoDBEncryptor getInstance(EncryptionMaterialsProvider provider, String descriptionbase); static DynamoDBEncryptor getInstance(EncryptionMaterialsProvider provider); Map<String, AttributeValue> decryptAllFieldsExcept(Map<String, AttributeValue> itemAttributes,
            EncryptionContext context, String... doNotDecrypt); Map<String, AttributeValue> decryptAllFieldsExcept(
            Map<String, AttributeValue> itemAttributes,
            EncryptionContext context, Collection<String> doNotDecrypt); Map<String, Set<EncryptionFlags>> allDecryptionFlagsExcept(
            Map<String, AttributeValue> itemAttributes,
            String ... doNotDecrypt); Map<String, Set<EncryptionFlags>> allDecryptionFlagsExcept(
            Map<String, AttributeValue> itemAttributes,
            Collection<String> doNotDecrypt); Map<String, AttributeValue> encryptAllFieldsExcept(Map<String, AttributeValue> itemAttributes,
            EncryptionContext context, String... doNotEncrypt); Map<String, AttributeValue> encryptAllFieldsExcept(
            Map<String, AttributeValue> itemAttributes,
            EncryptionContext context, 
            Collection<String> doNotEncrypt); Map<String, Set<EncryptionFlags>> allEncryptionFlagsExcept(
            Map<String, AttributeValue> itemAttributes,
            String ...doNotEncrypt); Map<String, Set<EncryptionFlags>> allEncryptionFlagsExcept(
            Map<String, AttributeValue> itemAttributes,
            Collection<String> doNotEncrypt); Map<String, AttributeValue> decryptRecord(
            Map<String, AttributeValue> itemAttributes,
            Map<String, Set<EncryptionFlags>> attributeFlags,
            EncryptionContext context); Map<String, AttributeValue> encryptRecord(
            Map<String, AttributeValue> itemAttributes,
            Map<String, Set<EncryptionFlags>> attributeFlags,
            EncryptionContext context); String getSignatureFieldName(); void setSignatureFieldName(final String signatureFieldName); String getMaterialDescriptionFieldName(); void setMaterialDescriptionFieldName(final String materialDescriptionFieldName); String getSigningAlgorithmHeader(); final void setEncryptionContextOverrideOperator(
            Function<EncryptionContext, EncryptionContext> encryptionContextOverrideOperator); final Function<EncryptionContext, EncryptionContext> getEncryptionContextOverrideOperator(); }
DynamoDBEncryptor { private static byte[] toByteArray(ByteBuffer buffer) { buffer = buffer.duplicate(); if (buffer.hasArray() && buffer.arrayOffset() == 0) { byte[] result = buffer.array(); if (buffer.remaining() == result.length) { return result; } } byte[] result = new byte[buffer.remaining()]; buffer.get(result); return result; } protected  DynamoDBEncryptor(EncryptionMaterialsProvider provider, String descriptionBase); static DynamoDBEncryptor getInstance(EncryptionMaterialsProvider provider, String descriptionbase); static DynamoDBEncryptor getInstance(EncryptionMaterialsProvider provider); Map<String, AttributeValue> decryptAllFieldsExcept(Map<String, AttributeValue> itemAttributes,
            EncryptionContext context, String... doNotDecrypt); Map<String, AttributeValue> decryptAllFieldsExcept(
            Map<String, AttributeValue> itemAttributes,
            EncryptionContext context, Collection<String> doNotDecrypt); Map<String, Set<EncryptionFlags>> allDecryptionFlagsExcept(
            Map<String, AttributeValue> itemAttributes,
            String ... doNotDecrypt); Map<String, Set<EncryptionFlags>> allDecryptionFlagsExcept(
            Map<String, AttributeValue> itemAttributes,
            Collection<String> doNotDecrypt); Map<String, AttributeValue> encryptAllFieldsExcept(Map<String, AttributeValue> itemAttributes,
            EncryptionContext context, String... doNotEncrypt); Map<String, AttributeValue> encryptAllFieldsExcept(
            Map<String, AttributeValue> itemAttributes,
            EncryptionContext context, 
            Collection<String> doNotEncrypt); Map<String, Set<EncryptionFlags>> allEncryptionFlagsExcept(
            Map<String, AttributeValue> itemAttributes,
            String ...doNotEncrypt); Map<String, Set<EncryptionFlags>> allEncryptionFlagsExcept(
            Map<String, AttributeValue> itemAttributes,
            Collection<String> doNotEncrypt); Map<String, AttributeValue> decryptRecord(
            Map<String, AttributeValue> itemAttributes,
            Map<String, Set<EncryptionFlags>> attributeFlags,
            EncryptionContext context); Map<String, AttributeValue> encryptRecord(
            Map<String, AttributeValue> itemAttributes,
            Map<String, Set<EncryptionFlags>> attributeFlags,
            EncryptionContext context); String getSignatureFieldName(); void setSignatureFieldName(final String signatureFieldName); String getMaterialDescriptionFieldName(); void setMaterialDescriptionFieldName(final String materialDescriptionFieldName); String getSigningAlgorithmHeader(); final void setEncryptionContextOverrideOperator(
            Function<EncryptionContext, EncryptionContext> encryptionContextOverrideOperator); final Function<EncryptionContext, EncryptionContext> getEncryptionContextOverrideOperator(); static final String DEFAULT_SIGNING_ALGORITHM_HEADER; }