Small refactor to clarify auth token ownership.
The Operation interface confused me. It looked like it was holding a
pointer to an auth token from the AuthTokenTable. In fact it made a
copy, but that wasn't clear from the interface. Ths CL changes
Operation::setOperationAuthtoken to take the token by value, making
clear that it copies (unless std::move is used).
Test: runtest --path cts/tests/tests/keystore/src/android/keystore/cts
Change-Id: I1d1b6983f421f5be9f56c60aaf56dda8fc4aa207
diff --git a/keystore/operation.cpp b/keystore/operation.cpp
index 8c39716..e1ba713 100644
--- a/keystore/operation.cpp
+++ b/keystore/operation.cpp
@@ -126,14 +126,12 @@
return true;
}
-bool OperationMap::setOperationAuthToken(const sp<IBinder>& token,
- const HardwareAuthToken* authToken) {
+bool OperationMap::setOperationAuthToken(const sp<IBinder>& token, HardwareAuthToken authToken) {
auto entry = mMap.find(token);
if (entry == mMap.end()) {
return false;
}
- entry->second.authToken.reset(new HardwareAuthToken);
- *entry->second.authToken = *authToken;
+ entry->second.authToken = std::make_unique<HardwareAuthToken>(std::move(authToken));
return true;
}