11package software .amazon .encryption .s3 .materials ;
22
3- import java .security .SecureRandom ;
43import java .util .ArrayList ;
54import java .util .List ;
65import java .util .TreeMap ;
1211import software .amazon .awssdk .services .kms .model .EncryptRequest ;
1312import software .amazon .awssdk .services .kms .model .EncryptResponse ;
1413import 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