have one implementation of deviceSuffix
Test: atest libkeymint_remote_prov_support_test
Change-Id: I2c9634dea7324a03e34c789f272248ddd720ca84
diff --git a/security/keymint/support/include/remote_prov/remote_prov_utils.h b/security/keymint/support/include/remote_prov/remote_prov_utils.h
index caeb7ff..91c7c48 100644
--- a/security/keymint/support/include/remote_prov/remote_prov_utils.h
+++ b/security/keymint/support/include/remote_prov/remote_prov_utils.h
@@ -99,7 +99,7 @@
* e.g. for "android.hardware.security.keymint.IRemotelyProvisionedComponent/avf",
* it returns "avf".
*/
-std::string deviceSuffix(const std::string& name);
+std::string_view deviceSuffix(std::string_view name);
struct EekChain {
bytevec chain;
diff --git a/security/keymint/support/remote_prov_utils.cpp b/security/keymint/support/remote_prov_utils.cpp
index 464d912..bec9220 100644
--- a/security/keymint/support/remote_prov_utils.cpp
+++ b/security/keymint/support/remote_prov_utils.cpp
@@ -52,8 +52,8 @@
using X509_Ptr = bssl::UniquePtr<X509>;
using CRYPTO_BUFFER_Ptr = bssl::UniquePtr<CRYPTO_BUFFER>;
-std::string deviceSuffix(const std::string& name) {
- size_t pos = name.rfind('/');
+std::string_view deviceSuffix(std::string_view name) {
+ auto pos = name.rfind('/');
if (pos == std::string::npos) {
return name;
}
diff --git a/security/rkp/aidl/vts/functional/VtsRemotelyProvisionedComponentTests.cpp b/security/rkp/aidl/vts/functional/VtsRemotelyProvisionedComponentTests.cpp
index 8f918af..c099907 100644
--- a/security/rkp/aidl/vts/functional/VtsRemotelyProvisionedComponentTests.cpp
+++ b/security/rkp/aidl/vts/functional/VtsRemotelyProvisionedComponentTests.cpp
@@ -35,6 +35,7 @@
#include <remote_prov/remote_prov_utils.h>
#include <optional>
#include <set>
+#include <string_view>
#include <vector>
#include "KeyMintAidlTestBase.h"
@@ -150,22 +151,14 @@
return corruptChain.encode();
}
-string device_suffix(const string& name) {
- size_t pos = name.find('/');
- if (pos == string::npos) {
- return name;
- }
- return name.substr(pos + 1);
-}
-
bool matching_keymint_device(const string& rp_name, std::shared_ptr<IKeyMintDevice>* keyMint) {
- string rp_suffix = device_suffix(rp_name);
+ auto rp_suffix = deviceSuffix(rp_name);
vector<string> km_names = ::android::getAidlHalInstanceNames(IKeyMintDevice::descriptor);
for (const string& km_name : km_names) {
// If the suffix of the KeyMint instance equals the suffix of the
// RemotelyProvisionedComponent instance, assume they match.
- if (device_suffix(km_name) == rp_suffix && AServiceManager_isDeclared(km_name.c_str())) {
+ if (deviceSuffix(km_name) == rp_suffix && AServiceManager_isDeclared(km_name.c_str())) {
::ndk::SpAIBinder binder(AServiceManager_waitForService(km_name.c_str()));
*keyMint = IKeyMintDevice::fromBinder(binder);
return true;
@@ -1002,7 +995,7 @@
ASSERT_TRUE(bootPatchLevel);
ASSERT_TRUE(securityLevel);
- auto kmDeviceName = device_suffix(GetParam());
+ auto kmDeviceName = deviceSuffix(GetParam());
// Compare DeviceInfo against IDs attested by KeyMint.
ASSERT_TRUE((securityLevel->value() == "tee" && kmDeviceName == "default") ||