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
This commit is contained in:
Kenny Root 2020-02-01 11:29:20 -08:00
parent 2801b037cd
commit 08018dd925

View file

@ -55,13 +55,12 @@ ndk::ScopedAStatus RebootEscrow::retrieveKey(std::vector<int8_t>* _aidl_return)
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());