verityutils: s/vector/span/
while writing I8fe9dc047af729b0f5730ec1844b3902225fa73e, i noticed that
we're making a temp vector just to call toHex.
since toHex only iterates over and inspects its argument, it can take
a `span` instead, which allows us to avoid making a copy.
Bug: None
Test: TreeHugger
Change-Id: Ide87b7ab7a10e68e895338fb61a41af6c1ab6e77
diff --git a/ondevice-signing/VerityUtils.cpp b/ondevice-signing/VerityUtils.cpp
index a8d72fc..ff7de7e 100644
--- a/ondevice-signing/VerityUtils.cpp
+++ b/ondevice-signing/VerityUtils.cpp
@@ -16,6 +16,7 @@
#include <filesystem>
#include <map>
+#include <span>
#include <string>
#include <fcntl.h>
@@ -56,7 +57,7 @@
__u8 digest[];
};
-static std::string toHex(const std::vector<uint8_t>& data) {
+static std::string toHex(std::span<uint8_t> data) {
std::stringstream ss;
for (auto it = data.begin(); it != data.end(); ++it) {
ss << std::setfill('0') << std::setw(2) << std::hex << static_cast<unsigned>(*it);
@@ -204,9 +205,7 @@
if (ret < 0) {
return ErrnoError() << "Failed to FS_IOC_MEASURE_VERITY for " << path;
}
- std::vector<uint8_t> digest_vector(&d->digest[0], &d->digest[d->digest_size]);
-
- return toHex(digest_vector);
+ return toHex({&d->digest[0], &d->digest[d->digest_size]});
}
Result<std::map<std::string, std::string>> verifyAllFilesInVerity(const std::string& path) {