Replace cast operator with getValue() for key store return codes
The value of the error code is not intended to be used
in checks, and instead isOk() should be used. A few places
were found which used the error codes directly via the
cast operator. To make it less likely this will happen
in the future unintentionally, the cast operator is being
removed. Some code still wants to access the error code
directly, such as when logging, so getValue() is added
for these cases.
Bug: 119771891
Test: Built for walleye successfully, basic operations with
keystore_cli_v2 tool work correctly.
Change-Id: I46e82d66dc4932472d8a5b2749ece08e398e7c88
diff --git a/keystore/keystore_client_impl.cpp b/keystore/keystore_client_impl.cpp
index 18e9eb1..140931b 100644
--- a/keystore/keystore_client_impl.cpp
+++ b/keystore/keystore_client_impl.cpp
@@ -161,7 +161,7 @@
uint64_t handle;
auto result = beginOperation(purpose, key_name, input_parameters, output_parameters, &handle);
if (!result.isOk()) {
- ALOGE("BeginOperation failed: %d", int32_t(result));
+ ALOGE("BeginOperation failed: %d", result.getErrorCode());
return false;
}
AuthorizationSet empty_params;
@@ -170,13 +170,13 @@
result = updateOperation(handle, empty_params, input_data, &num_input_bytes_consumed,
&ignored_params, output_data);
if (!result.isOk()) {
- ALOGE("UpdateOperation failed: %d", int32_t(result));
+ ALOGE("UpdateOperation failed: %d", result.getErrorCode());
return false;
}
result =
finishOperation(handle, empty_params, signature_to_verify, &ignored_params, output_data);
if (!result.isOk()) {
- ALOGE("FinishOperation failed: %d", int32_t(result));
+ ALOGE("FinishOperation failed: %d", result.getErrorCode());
return false;
}
return true;
@@ -467,7 +467,7 @@
if (!verified) {
auto result = deleteKey(key_name);
if (!result.isOk()) {
- ALOGE("Failed to delete invalid encryption key: %d", int32_t(result));
+ ALOGE("Failed to delete invalid encryption key: %d", result.getErrorCode());
return false;
}
key_exists = false;
@@ -485,7 +485,7 @@
generateKey(key_name, key_parameters, flags, &hardware_enforced_characteristics,
&software_enforced_characteristics);
if (!result.isOk()) {
- ALOGE("Failed to generate encryption key: %d", int32_t(result));
+ ALOGE("Failed to generate encryption key: %d", result.getErrorCode());
return false;
}
if (hardware_enforced_characteristics.size() == 0) {
@@ -506,7 +506,7 @@
if (!verified) {
auto result = deleteKey(key_name);
if (!result.isOk()) {
- ALOGE("Failed to delete invalid authentication key: %d", int32_t(result));
+ ALOGE("Failed to delete invalid authentication key: %d", result.getErrorCode());
return false;
}
key_exists = false;
@@ -524,7 +524,7 @@
generateKey(key_name, key_parameters, flags, &hardware_enforced_characteristics,
&software_enforced_characteristics);
if (!result.isOk()) {
- ALOGE("Failed to generate authentication key: %d", int32_t(result));
+ ALOGE("Failed to generate authentication key: %d", result.getErrorCode());
return false;
}
if (hardware_enforced_characteristics.size() == 0) {
@@ -541,7 +541,7 @@
auto result = getKeyCharacteristics(key_name, &hardware_enforced_characteristics,
&software_enforced_characteristics);
if (!result.isOk()) {
- ALOGE("Failed to query encryption key: %d", int32_t(result));
+ ALOGE("Failed to query encryption key: %d", result.getErrorCode());
return false;
}
*verified = true;
@@ -582,7 +582,7 @@
auto result = getKeyCharacteristics(key_name, &hardware_enforced_characteristics,
&software_enforced_characteristics);
if (!result.isOk()) {
- ALOGE("Failed to query authentication key: %d", int32_t(result));
+ ALOGE("Failed to query authentication key: %d", result.getErrorCode());
return false;
}
*verified = true;