Skip to content

Commit 9ea13e0

Browse files
committed
Create S3EncryptionClientException for all thrown exceptions.
1 parent 6411a40 commit 9ea13e0

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package software.amazon.encryption.s3;
2+
3+
import software.amazon.awssdk.core.exception.SdkClientException;
4+
5+
public class S3EncryptionClientException extends SdkClientException {
6+
7+
public S3EncryptionClientException(String message) {
8+
super(SdkClientException.builder()
9+
.message(message));
10+
}
11+
12+
public S3EncryptionClientException(String message, Throwable cause) {
13+
super(SdkClientException.builder()
14+
.message(message)
15+
.cause(cause));
16+
}
17+
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import javax.crypto.Cipher;
88
import javax.crypto.SecretKey;
99
import javax.crypto.spec.GCMParameterSpec;
10+
import software.amazon.encryption.s3.S3EncryptionClientException;
1011
import software.amazon.encryption.s3.algorithms.AlgorithmSuite;
1112

1213
/**
@@ -74,7 +75,7 @@ public EncryptionMaterials onEncrypt(EncryptionMaterials materials) {
7475
.encryptedDataKeys(encryptedDataKeys)
7576
.build();
7677
} catch (Exception e) {
77-
throw new UnsupportedOperationException("Unable to " + CIPHER_ALGORITHM + " wrap", e);
78+
throw new S3EncryptionClientException("Unable to " + CIPHER_ALGORITHM + " wrap", e);
7879
}
7980
}
8081

@@ -108,7 +109,7 @@ public DecryptionMaterials onDecrypt(final DecryptionMaterials materials, List<E
108109

109110
return materials.toBuilder().plaintextDataKey(plaintext).build();
110111
} catch (Exception e) {
111-
throw new UnsupportedOperationException("Unable to " + CIPHER_ALGORITHM + " unwrap", e);
112+
throw new S3EncryptionClientException("Unable to " + CIPHER_ALGORITHM + " unwrap", e);
112113
}
113114
}
114115

@@ -123,7 +124,7 @@ private Builder() {}
123124

124125
public Builder wrappingKey(SecretKey wrappingKey) {
125126
if (!wrappingKey.getAlgorithm().equals(KEY_ALGORITHM)) {
126-
throw new IllegalArgumentException("Invalid algorithm '" + wrappingKey.getAlgorithm() + "', expecting " + KEY_ALGORITHM);
127+
throw new S3EncryptionClientException("Invalid algorithm '" + wrappingKey.getAlgorithm() + "', expecting " + KEY_ALGORITHM);
127128
}
128129
_wrappingKey = wrappingKey;
129130
return this;

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.security.NoSuchAlgorithmException;
44
import javax.crypto.KeyGenerator;
55
import javax.crypto.SecretKey;
6+
import software.amazon.encryption.s3.S3EncryptionClientException;
67
import software.amazon.encryption.s3.algorithms.AlgorithmSuite;
78

89
public class DefaultDataKeyGenerator implements DataKeyGenerator {
@@ -12,7 +13,7 @@ public SecretKey generateDataKey(AlgorithmSuite algorithmSuite) {
1213
try {
1314
generator = KeyGenerator.getInstance(algorithmSuite.dataKeyAlgorithm());
1415
} catch (NoSuchAlgorithmException e) {
15-
throw new UnsupportedOperationException("Unable to generate a(n) " + algorithmSuite.dataKeyAlgorithm() + " data key", e);
16+
throw new S3EncryptionClientException("Unable to generate a(n) " + algorithmSuite.dataKeyAlgorithm() + " data key", e);
1617
}
1718

1819
generator.init(algorithmSuite.dataKeyLengthBits());

0 commit comments

Comments
 (0)