|
14 | 14 | import com.amazonaws.encryptionsdk.exception.AwsCryptoException;
|
15 | 15 | import com.amazonaws.encryptionsdk.internal.EncryptionContextSerializer;
|
16 | 16 | import com.amazonaws.encryptionsdk.internal.Utils;
|
| 17 | +import com.amazonaws.encryptionsdk.keyrings.Keyring; |
17 | 18 | import com.amazonaws.encryptionsdk.model.DecryptionMaterialsRequest;
|
18 | 19 | import com.amazonaws.encryptionsdk.model.DecryptionMaterials;
|
19 | 20 | import com.amazonaws.encryptionsdk.model.EncryptionMaterials;
|
|
22 | 23 |
|
23 | 24 | /**
|
24 | 25 | * 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. |
27 | 28 | *
|
28 | 29 | * The CachingCryptoMaterialsManager helps enforce a number of usage limits on encrypt. Specifically, it limits the number of
|
29 | 30 | * individual messages encrypted with a particular data key, and the number of plaintext bytes encrypted with the same
|
30 | 31 | * data key. It also allows you to configure a maximum time-to-live for cache entries.
|
31 | 32 | *
|
32 | 33 | * 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 |
35 | 36 | * known, and to avoid exceeding byte use limits, caching will not be performed.
|
36 | 37 | *
|
37 | 38 | * 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) {
|
100 | 101 | * This method is equivalent to calling {@link #withBackingMaterialsManager(CryptoMaterialsManager)} passing a
|
101 | 102 | * {@link DefaultCryptoMaterialsManager} constructed using your {@link MasterKeyProvider}.
|
102 | 103 | *
|
| 104 | + * @deprecated {@link MasterKeyProvider}s have been deprecated in favor of {@link Keyring}s. |
| 105 | + * |
103 | 106 | * @param mkp The MasterKeyProvider to invoke on cache misses
|
104 | 107 | * @return this builder
|
105 | 108 | */
|
| 109 | + @Deprecated |
106 | 110 | public Builder withMasterKeyProvider(MasterKeyProvider mkp) {
|
107 | 111 | return withBackingMaterialsManager(new DefaultCryptoMaterialsManager(mkp));
|
108 | 112 | }
|
109 | 113 |
|
| 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 | + |
110 | 131 | /**
|
111 | 132 | * Sets the cache to which this {@link CryptoMaterialsManager} will be bound.
|
112 | 133 | * @param cache The cache to associate with the CMM
|
|
0 commit comments