Skip to content

Commit 1890ebb

Browse files
authored
chore: deprecate getMasterKeyIds() in CryptoResult (#1976)
1 parent 800bd01 commit 1890ebb

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

src/main/java/com/amazonaws/encryptionsdk/CryptoResult.java

+1
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public List<K> getMasterKeys() {
6969
}
7070

7171
/** Convenience method for retrieving the keyIds in the results from {@link #getMasterKeys()}. */
72+
@Deprecated
7273
public List<String> getMasterKeyIds() {
7374
final List<String> result = new ArrayList<>(masterKeys_.size());
7475
for (final MasterKey<K> mk : masterKeys_) {

src/main/java/com/amazonaws/encryptionsdk/internal/DecryptionHandler.java

+3-1
Original file line numberDiff line numberDiff line change
@@ -890,7 +890,9 @@ public CiphertextHeaders getHeaders() {
890890

891891
@Override
892892
public List<K> getMasterKeys() {
893-
return Collections.singletonList(dataKey_.getMasterKey());
893+
return dataKey_.getMasterKey() == null
894+
? Collections.emptyList()
895+
: Collections.singletonList(dataKey_.getMasterKey());
894896
}
895897

896898
@Override

src/test/java/com/amazonaws/encryptionsdk/AwsCryptoIntegrationTest.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -113,21 +113,21 @@ public void AwsKmsEncryptDecryptKeyring() {
113113
crypto.encryptData(kmsKeyring, EXAMPLE_DATA, encryptionContext);
114114

115115
List<?> masterKeys = encryptResult.getMasterKeys();
116+
List<String> masterKeyIds = encryptResult.getMasterKeyIds();
116117
// Assert CryptoResult returns empty list if keyrings are used.
117-
assert masterKeys.size() == 0;
118+
assert masterKeys.isEmpty();
119+
assert masterKeyIds.isEmpty();
118120

119121
final byte[] ciphertext = encryptResult.getResult();
120122

121123
// Decrypt the data
122-
final CryptoResult<byte[], ?> decryptResult = crypto.decryptData(kmsKeyring, ciphertext);
123-
assert masterKeys.size() == 0;
124-
125-
// Verify that the encryption context in the result contains the
126-
// encryption context supplied to the encryptData method.
127-
if (!encryptionContext.entrySet().stream()
128-
.allMatch(e -> e.getValue().equals(decryptResult.getEncryptionContext().get(e.getKey())))) {
129-
throw new IllegalStateException("Wrong Encryption Context!");
130-
}
124+
final CryptoResult<byte[], ?> decryptResult =
125+
crypto.decryptData(kmsKeyring, ciphertext, encryptionContext);
126+
masterKeys = decryptResult.getMasterKeys();
127+
masterKeyIds = decryptResult.getMasterKeyIds();
128+
// Assert CryptoResult returns empty list if keyrings are used.
129+
assert masterKeys.isEmpty();
130+
assert masterKeyIds.isEmpty();
131131

132132
// Verify that the decrypted plaintext matches the original plaintext
133133
assert Arrays.equals(decryptResult.getResult(), EXAMPLE_DATA);

0 commit comments

Comments
 (0)