Skip to content

chore: deprecate getMasterKeyIds() in CryptoResult #1976

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public List<K> getMasterKeys() {
}

/** Convenience method for retrieving the keyIds in the results from {@link #getMasterKeys()}. */
@Deprecated
public List<String> getMasterKeyIds() {
final List<String> result = new ArrayList<>(masterKeys_.size());
for (final MasterKey<K> mk : masterKeys_) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,9 @@ public CiphertextHeaders getHeaders() {

@Override
public List<K> getMasterKeys() {
return Collections.singletonList(dataKey_.getMasterKey());
return dataKey_.getMasterKey() == null
? Collections.emptyList()
: Collections.singletonList(dataKey_.getMasterKey());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,21 +113,21 @@ public void AwsKmsEncryptDecryptKeyring() {
crypto.encryptData(kmsKeyring, EXAMPLE_DATA, encryptionContext);

List<?> masterKeys = encryptResult.getMasterKeys();
List<String> masterKeyIds = encryptResult.getMasterKeyIds();
// Assert CryptoResult returns empty list if keyrings are used.
assert masterKeys.size() == 0;
assert masterKeys.isEmpty();
assert masterKeyIds.isEmpty();

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

// Decrypt the data
final CryptoResult<byte[], ?> decryptResult = crypto.decryptData(kmsKeyring, ciphertext);
assert masterKeys.size() == 0;

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

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