Skip to content

Commit c182cd5

Browse files
Add withKeyring to CachingCMM builder
1 parent 6af9b02 commit c182cd5

File tree

1 file changed

+25
-4
lines changed

1 file changed

+25
-4
lines changed

src/main/java/com/amazonaws/encryptionsdk/caching/CachingCryptoMaterialsManager.java

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.amazonaws.encryptionsdk.exception.AwsCryptoException;
1515
import com.amazonaws.encryptionsdk.internal.EncryptionContextSerializer;
1616
import com.amazonaws.encryptionsdk.internal.Utils;
17+
import com.amazonaws.encryptionsdk.keyrings.Keyring;
1718
import com.amazonaws.encryptionsdk.model.DecryptionMaterialsRequest;
1819
import com.amazonaws.encryptionsdk.model.DecryptionMaterials;
1920
import com.amazonaws.encryptionsdk.model.EncryptionMaterials;
@@ -22,16 +23,16 @@
2223

2324
/**
2425
* The CachingCryptoMaterialsManager wraps another {@link CryptoMaterialsManager}, and caches its results. This helps reduce
25-
* the number of calls made to the underlying {@link CryptoMaterialsManager} and/or {@link MasterKeyProvider}, which may
26-
* help reduce cost and/or improve performance.
26+
* the number of calls made to the underlying {@link CryptoMaterialsManager}, {@link MasterKeyProvider} and/or
27+
* {@link Keyring}, which may help reduce cost and/or improve performance.
2728
*
2829
* The CachingCryptoMaterialsManager helps enforce a number of usage limits on encrypt. Specifically, it limits the number of
2930
* individual messages encrypted with a particular data key, and the number of plaintext bytes encrypted with the same
3031
* data key. It also allows you to configure a maximum time-to-live for cache entries.
3132
*
3233
* Note that when performing streaming encryption operations, unless you set the stream size before writing any data
33-
* using {@link com.amazonaws.encryptionsdk.CryptoOutputStream#setMaxInputLength(long)} or
34-
* {@link com.amazonaws.encryptionsdk.CryptoInputStream#setMaxInputLength(long)}, the size of the message will not be
34+
* using {@link com.amazonaws.encryptionsdk.AwsCryptoOutputStream#setMaxInputLength(long)} or
35+
* {@link com.amazonaws.encryptionsdk.AwsCryptoInputStream#setMaxInputLength(long)}, the size of the message will not be
3536
* known, and to avoid exceeding byte use limits, caching will not be performed.
3637
*
3738
* By default, two different {@link CachingCryptoMaterialsManager}s will not share cached entries, even when using the same
@@ -100,13 +101,33 @@ public Builder withBackingMaterialsManager(CryptoMaterialsManager backingCMM) {
100101
* This method is equivalent to calling {@link #withBackingMaterialsManager(CryptoMaterialsManager)} passing a
101102
* {@link DefaultCryptoMaterialsManager} constructed using your {@link MasterKeyProvider}.
102103
*
104+
* @deprecated {@link MasterKeyProvider}s have been deprecated in favor of {@link Keyring}s.
105+
*
103106
* @param mkp The MasterKeyProvider to invoke on cache misses
104107
* @return this builder
105108
*/
109+
@Deprecated
106110
public Builder withMasterKeyProvider(MasterKeyProvider mkp) {
107111
return withBackingMaterialsManager(new DefaultCryptoMaterialsManager(mkp));
108112
}
109113

114+
/**
115+
* Sets the {@link Keyring} that should be queried when the {@link CachingCryptoMaterialsManager}
116+
* incurs a cache miss.
117+
*
118+
* You can set either a Keyring or a CryptoMaterialsManager to back the CCMM - the last value set will
119+
* be used.
120+
*
121+
* This method is equivalent to calling {@link #withBackingMaterialsManager(CryptoMaterialsManager)} passing a
122+
* {@link DefaultCryptoMaterialsManager} constructed using your {@link Keyring}.
123+
*
124+
* @param keyring The Keyring to invoke on cache misses
125+
* @return this builder
126+
*/
127+
public Builder withKeyring(Keyring keyring) {
128+
return withBackingMaterialsManager(new DefaultCryptoMaterialsManager(keyring));
129+
}
130+
110131
/**
111132
* Sets the cache to which this {@link CryptoMaterialsManager} will be bound.
112133
* @param cache The cache to associate with the CMM

0 commit comments

Comments
 (0)