2121import java .util .Collection ;
2222import java .util .List ;
2323import java .util .Map ;
24+ import java .util .function .Supplier ;
2425
2526import com .amazonaws .AmazonServiceException ;
2627import com .amazonaws .AmazonWebServiceRequest ;
4849 * {@link AwsCrypto}.
4950 */
5051public final class KmsMasterKey extends MasterKey <KmsMasterKey > implements KmsMethods {
51- private final AWSKMS kms_ ;
52+ private final Supplier < AWSKMS > kms_ ;
5253 private final MasterKeyProvider <KmsMasterKey > sourceProvider_ ;
5354 private final String id_ ;
5455 private final List <String > grantTokens_ = new ArrayList <>();
@@ -77,12 +78,12 @@ public static KmsMasterKey getInstance(final AWSCredentialsProvider creds, final
7778 return new KmsMasterKeyProvider (creds , keyId ).getMasterKey (keyId );
7879 }
7980
80- static KmsMasterKey getInstance (final AWSKMS kms , final String id ,
81+ static KmsMasterKey getInstance (final Supplier < AWSKMS > kms , final String id ,
8182 final MasterKeyProvider <KmsMasterKey > provider ) {
8283 return new KmsMasterKey (kms , id , provider );
8384 }
8485
85- private KmsMasterKey (final AWSKMS kms , final String id , final MasterKeyProvider <KmsMasterKey > provider ) {
86+ private KmsMasterKey (final Supplier < AWSKMS > kms , final String id , final MasterKeyProvider <KmsMasterKey > provider ) {
8687 kms_ = kms ;
8788 id_ = id ;
8889 sourceProvider_ = provider ;
@@ -101,7 +102,7 @@ public String getKeyId() {
101102 @ Override
102103 public DataKey <KmsMasterKey > generateDataKey (final CryptoAlgorithm algorithm ,
103104 final Map <String , String > encryptionContext ) {
104- final GenerateDataKeyResult gdkResult = kms_ .generateDataKey (updateUserAgent (
105+ final GenerateDataKeyResult gdkResult = kms_ .get (). generateDataKey (updateUserAgent (
105106 new GenerateDataKeyRequest ()
106107 .withKeyId (getKeyId ())
107108 .withNumberOfBytes (algorithm .getDataKeyLength ())
@@ -145,7 +146,7 @@ public DataKey<KmsMasterKey> encryptDataKey(final CryptoAlgorithm algorithm,
145146 throw new IllegalArgumentException ("Only RAW encoded keys are supported" );
146147 }
147148 try {
148- final EncryptResult encryptResult = kms_ .encrypt (updateUserAgent (
149+ final EncryptResult encryptResult = kms_ .get (). encrypt (updateUserAgent (
149150 new EncryptRequest ()
150151 .withKeyId (id_ )
151152 .withPlaintext (ByteBuffer .wrap (key .getEncoded ()))
@@ -167,7 +168,7 @@ public DataKey<KmsMasterKey> decryptDataKey(final CryptoAlgorithm algorithm,
167168 final List <Exception > exceptions = new ArrayList <>();
168169 for (final EncryptedDataKey edk : encryptedDataKeys ) {
169170 try {
170- final DecryptResult decryptResult = kms_ .decrypt (updateUserAgent (
171+ final DecryptResult decryptResult = kms_ .get (). decrypt (updateUserAgent (
171172 new DecryptRequest ()
172173 .withCiphertextBlob (ByteBuffer .wrap (edk .getEncryptedDataKey ()))
173174 .withEncryptionContext (encryptionContext )
0 commit comments