|
14 | 14 | package com.amazonaws.encryptionsdk.keyrings;
|
15 | 15 |
|
16 | 16 | import com.amazonaws.encryptionsdk.EncryptedDataKey;
|
| 17 | +import com.amazonaws.encryptionsdk.exception.AwsCryptoException; |
17 | 18 | import com.amazonaws.encryptionsdk.keyrings.RawRsaKeyringBuilder.RsaPaddingScheme;
|
18 | 19 | import com.amazonaws.encryptionsdk.model.DecryptionMaterials;
|
19 | 20 | import com.amazonaws.encryptionsdk.model.EncryptionMaterials;
|
|
34 | 35 | import static org.junit.jupiter.api.Assertions.assertArrayEquals;
|
35 | 36 | import static org.junit.jupiter.api.Assertions.assertEquals;
|
36 | 37 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
| 38 | +import static org.junit.jupiter.api.Assertions.assertThrows; |
37 | 39 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
38 | 40 |
|
39 | 41 | class RawRsaKeyringTest {
|
@@ -134,4 +136,21 @@ void testEncryptDecryptGenerateDataKey() {
|
134 | 136 | assertTrue(decryptionMaterials.getKeyringTrace().getEntries().get(0).getFlags().contains(KeyringTraceFlag.DECRYPTED_DATA_KEY));
|
135 | 137 | }
|
136 | 138 |
|
| 139 | + @Test |
| 140 | + void testEncryptWithNoPublicKey() throws Exception { |
| 141 | + final KeyPairGenerator keyPairGenerator = KeyPairGenerator.getInstance("RSA"); |
| 142 | + keyPairGenerator.initialize(2048); |
| 143 | + final KeyPair keyPair = keyPairGenerator.generateKeyPair(); |
| 144 | + |
| 145 | + Keyring noPublicKey = new RawRsaKeyring(KEYNAMESPACE, KEYNAME, null, keyPair.getPrivate(), PADDING_SCHEME); |
| 146 | + |
| 147 | + EncryptionMaterials encryptionMaterials = EncryptionMaterials.newBuilder() |
| 148 | + .setAlgorithm(ALGORITHM) |
| 149 | + .setCleartextDataKey(DATA_KEY) |
| 150 | + .setEncryptionContext(ENCRYPTION_CONTEXT) |
| 151 | + .build(); |
| 152 | + |
| 153 | + assertThrows(AwsCryptoException.class, () -> noPublicKey.onEncrypt(encryptionMaterials)); |
| 154 | + } |
| 155 | + |
137 | 156 | }
|
0 commit comments