Skip to content

Commit 8b2755a

Browse files
committed
Only throw S3EncryptionClientException from KMS keyring.
1 parent e37bcf1 commit 8b2755a

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/main/java/software/amazon/encryption/s3/materials/KMSContextKeyring.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package software.amazon.encryption.s3.materials;
22

3-
import java.security.SecureRandom;
43
import java.util.ArrayList;
54
import java.util.List;
65
import java.util.TreeMap;
@@ -12,7 +11,6 @@
1211
import software.amazon.awssdk.services.kms.model.EncryptRequest;
1312
import software.amazon.awssdk.services.kms.model.EncryptResponse;
1413
import software.amazon.encryption.s3.S3EncryptionClientException;
15-
import software.amazon.encryption.s3.materials.AESKeyring.Builder;
1614

1715
/**
1816
* AESKeyring will call to KMS to wrap the data key used to encrypt content.
@@ -47,7 +45,7 @@ public EncryptionMaterials onEncrypt(EncryptionMaterials materials) {
4745
}
4846

4947
if (materials.encryptionContext().containsKey(ENCRYPTION_CONTEXT_ALGORITHM_KEY)) {
50-
throw new IllegalStateException(ENCRYPTION_CONTEXT_ALGORITHM_KEY + " is a reserved key for the S3 encryption client");
48+
throw new S3EncryptionClientException(ENCRYPTION_CONTEXT_ALGORITHM_KEY + " is a reserved key for the S3 encryption client");
5149
}
5250

5351
TreeMap<String, String> encryptionContext = new TreeMap<>(materials.encryptionContext());
@@ -76,7 +74,7 @@ public EncryptionMaterials onEncrypt(EncryptionMaterials materials) {
7674
.encryptedDataKeys(encryptedDataKeys)
7775
.build();
7876
} catch (Exception e) {
79-
throw new UnsupportedOperationException("Unable to " + KEY_PROVIDER_ID + " wrap", e);
77+
throw new S3EncryptionClientException("Unable to " + KEY_PROVIDER_ID + " wrap", e);
8078
}
8179
}
8280

@@ -102,7 +100,7 @@ public DecryptionMaterials onDecrypt(final DecryptionMaterials materials, List<E
102100

103101
return materials.toBuilder().plaintextDataKey(response.plaintext().asByteArray()).build();
104102
} catch (Exception e) {
105-
throw new UnsupportedOperationException("Unable to " + KEY_PROVIDER_ID + " unwrap", e);
103+
throw new S3EncryptionClientException("Unable to " + KEY_PROVIDER_ID + " unwrap", e);
106104
}
107105
}
108106

0 commit comments

Comments
 (0)