com.amazonaws.encryptionsdk.caching.LocalCryptoMaterialsCache Java Examples

The following examples show how to use com.amazonaws.encryptionsdk.caching.LocalCryptoMaterialsCache. 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: AwsCryptoTest.java    From aws-encryption-sdk-java with Apache License 2.0 6 votes vote down vote up
@Test
public void estimateCiphertextSize_usesCachedKeys() throws Exception {
    // Make sure estimateCiphertextSize works with cached CMMs
    CryptoMaterialsManager cmm = spy(new DefaultCryptoMaterialsManager(masterKeyProvider));

    CachingCryptoMaterialsManager cache = CachingCryptoMaterialsManager.newBuilder()
            .withBackingMaterialsManager(cmm)
            .withMaxAge(Long.MAX_VALUE, TimeUnit.SECONDS)
            .withCache(new LocalCryptoMaterialsCache(1))
            .withMessageUseLimit(9999)
            .withByteUseLimit(501)
            .build();

    // These estimates should be cached, and should not consume any bytes from the byte use limit.
    encryptionClient_.estimateCiphertextSize(cache, 500, new HashMap<>());
    encryptionClient_.estimateCiphertextSize(cache, 500, new HashMap<>());

    encryptionClient_.encryptData(cache, new byte[500]);

    verify(cmm, times(1)).getMaterialsForEncrypt(any());
}