rebootescrow: eliminate copy during read
Instead of reading into a std::string, read directly into the std::vector of bytes
This saves a copy and reduces memory overhead slightly.
Test: atest VtsHalRebootEscrowTargetTest
Bug: 148177693
Change-Id: I4dfe552f21394fb0891858b34a481b489dc3c684
diff --git a/rebootescrow/aidl/default/RebootEscrow.cpp b/rebootescrow/aidl/default/RebootEscrow.cpp
index 5ae96f6..dbc0921 100644
--- a/rebootescrow/aidl/default/RebootEscrow.cpp
+++ b/rebootescrow/aidl/default/RebootEscrow.cpp
@@ -55,13 +55,12 @@
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
}
- std::string encodedString;
- if (!::android::base::ReadFdToString(fd, &encodedString)) {
- LOG(WARNING) << "Could not read device to string";
+ std::vector<uint8_t> encodedBytes(hadamard::OUTPUT_SIZE_BYTES);
+ if (!::android::base::ReadFully(fd, &encodedBytes[0], encodedBytes.size())) {
+ LOG(WARNING) << "Could not read device";
return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
}
- std::vector<uint8_t> encodedBytes(encodedString.begin(), encodedString.end());
auto keyBytes = hadamard::DecodeKey(encodedBytes);
std::vector<int8_t> signedKeyBytes(keyBytes.begin(), keyBytes.end());