From 08018dd92565e74c46e58aae91895edad761cc84 Mon Sep 17 00:00:00 2001 From: Kenny Root Date: Sat, 1 Feb 2020 11:29:20 -0800 Subject: [PATCH] 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 --- rebootescrow/aidl/default/RebootEscrow.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/rebootescrow/aidl/default/RebootEscrow.cpp b/rebootescrow/aidl/default/RebootEscrow.cpp index 5ae96f6086..dbc09215b3 100644 --- a/rebootescrow/aidl/default/RebootEscrow.cpp +++ b/rebootescrow/aidl/default/RebootEscrow.cpp @@ -55,13 +55,12 @@ ndk::ScopedAStatus RebootEscrow::retrieveKey(std::vector* _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 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 encodedBytes(encodedString.begin(), encodedString.end()); auto keyBytes = hadamard::DecodeKey(encodedBytes); std::vector signedKeyBytes(keyBytes.begin(), keyBytes.end());