2424import javax .crypto .spec .SecretKeySpec ;
2525
2626import com .amazonaws .AmazonServiceException ;
27- import com .amazonaws .AmazonWebServiceRequest ;
2827import com .amazonaws .auth .AWSCredentials ;
2928import com .amazonaws .auth .AWSCredentialsProvider ;
3029import com .amazonaws .encryptionsdk .AwsCrypto ;
3534import com .amazonaws .encryptionsdk .MasterKeyProvider ;
3635import com .amazonaws .encryptionsdk .exception .AwsCryptoException ;
3736import com .amazonaws .encryptionsdk .exception .UnsupportedProviderException ;
38- import com .amazonaws .encryptionsdk .internal .VersionInfo ;
3937import com .amazonaws .services .kms .AWSKMS ;
4038import com .amazonaws .services .kms .model .DecryptRequest ;
4139import com .amazonaws .services .kms .model .DecryptResult ;
@@ -92,12 +90,12 @@ public String getKeyId() {
9290 @ Override
9391 public DataKey <KmsMasterKey > generateDataKey (final CryptoAlgorithm algorithm ,
9492 final Map <String , String > encryptionContext ) {
95- final GenerateDataKeyResult gdkResult = kms_ .generateDataKey (appendUserAgent (
93+ final GenerateDataKeyResult gdkResult = kms_ .generateDataKey (
9694 new GenerateDataKeyRequest ()
9795 .withKeyId (getKeyId ())
9896 .withNumberOfBytes (algorithm .getDataKeyLength ())
9997 .withEncryptionContext (encryptionContext )
100- .withGrantTokens (grantTokens_ ))
98+ .withGrantTokens (grantTokens_ )
10199 );
102100 final byte [] rawKey = new byte [algorithm .getDataKeyLength ()];
103101 gdkResult .getPlaintext ().get (rawKey );
@@ -136,12 +134,12 @@ public DataKey<KmsMasterKey> encryptDataKey(final CryptoAlgorithm algorithm,
136134 throw new IllegalArgumentException ("Only RAW encoded keys are supported" );
137135 }
138136 try {
139- final EncryptResult encryptResult = kms_ .encrypt (appendUserAgent (
137+ final EncryptResult encryptResult = kms_ .encrypt (
140138 new EncryptRequest ()
141139 .withKeyId (id_ )
142140 .withPlaintext (ByteBuffer .wrap (key .getEncoded ()))
143141 .withEncryptionContext (encryptionContext )
144- .withGrantTokens (grantTokens_ ))) ;
142+ .withGrantTokens (grantTokens_ ));
145143 final byte [] edk = new byte [encryptResult .getCiphertextBlob ().remaining ()];
146144 encryptResult .getCiphertextBlob ().get (edk );
147145 return new DataKey <>(dataKey .getKey (), edk , encryptResult .getKeyId ().getBytes (StandardCharsets .UTF_8 ), this );
@@ -158,11 +156,11 @@ public DataKey<KmsMasterKey> decryptDataKey(final CryptoAlgorithm algorithm,
158156 final List <Exception > exceptions = new ArrayList <>();
159157 for (final EncryptedDataKey edk : encryptedDataKeys ) {
160158 try {
161- final DecryptResult decryptResult = kms_ .decrypt (appendUserAgent (
159+ final DecryptResult decryptResult = kms_ .decrypt (
162160 new DecryptRequest ()
163161 .withCiphertextBlob (ByteBuffer .wrap (edk .getEncryptedDataKey ()))
164162 .withEncryptionContext (encryptionContext )
165- .withGrantTokens (grantTokens_ ))) ;
163+ .withGrantTokens (grantTokens_ ));
166164 if (decryptResult .getKeyId ().equals (id_ )) {
167165 final byte [] rawKey = new byte [algorithm .getDataKeyLength ()];
168166 decryptResult .getPlaintext ().get (rawKey );
@@ -181,9 +179,4 @@ public DataKey<KmsMasterKey> decryptDataKey(final CryptoAlgorithm algorithm,
181179
182180 throw buildCannotDecryptDksException (exceptions );
183181 }
184-
185- private static <R extends AmazonWebServiceRequest > R appendUserAgent (final R request ) {
186- request .getRequestClientOptions ().appendUserAgent (VersionInfo .USER_AGENT );
187- return request ;
188- }
189182}
0 commit comments