mirror of
https://github.com/google/nomulus
synced 2026-02-03 11:32:24 +00:00
Update KMS method signatures to standardize on KeyringException
It came up during the review of [] that it doesn't make a lot of sense for encrypt() and decrypt() to not throw the same kinds of Exceptions, especially not for the same kind of problem, just because one happens to use a Retrier in its internal implementation and the other doesn't. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=201054057
This commit is contained in:
@@ -57,11 +57,20 @@ class KmsConnectionImpl implements KmsConnection {
|
||||
}
|
||||
|
||||
@Override
|
||||
public EncryptResponse encrypt(String cryptoKeyName, byte[] value) throws IOException {
|
||||
public EncryptResponse encrypt(String cryptoKeyName, byte[] value) {
|
||||
checkArgument(
|
||||
value.length <= MAX_SECRET_SIZE_BYTES,
|
||||
"Value to encrypt was larger than %s bytes",
|
||||
MAX_SECRET_SIZE_BYTES);
|
||||
try {
|
||||
return attemptEncrypt(cryptoKeyName, value);
|
||||
} catch (IOException e) {
|
||||
throw new KeyringException(
|
||||
String.format("CloudKMS encrypt operation failed for secret %s", cryptoKeyName), e);
|
||||
}
|
||||
}
|
||||
|
||||
private EncryptResponse attemptEncrypt(String cryptoKeyName, byte[] value) throws IOException {
|
||||
String fullKeyRingName = getKeyRingName(projectId, kmsKeyRingName);
|
||||
try {
|
||||
kms.projects().locations().keyRings().get(fullKeyRingName).execute();
|
||||
@@ -143,7 +152,7 @@ class KmsConnectionImpl implements KmsConnection {
|
||||
}
|
||||
}
|
||||
|
||||
private byte[] attemptDecrypt(String cryptoKeyName, String encodedCiphertext) throws IOException{
|
||||
private byte[] attemptDecrypt(String cryptoKeyName, String encodedCiphertext) throws IOException {
|
||||
return kms.projects()
|
||||
.locations()
|
||||
.keyRings()
|
||||
|
||||
Reference in New Issue
Block a user