Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 08018dd9 authored by Kenny Root's avatar Kenny Root
Browse files

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
parent 2801b037
Loading
Loading
Loading
Loading
+3 −4
Original line number Original line Diff line number Diff line
@@ -55,13 +55,12 @@ ndk::ScopedAStatus RebootEscrow::retrieveKey(std::vector<int8_t>* _aidl_return)
        return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
        return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
    }
    }


    std::string encodedString;
    std::vector<uint8_t> encodedBytes(hadamard::OUTPUT_SIZE_BYTES);
    if (!::android::base::ReadFdToString(fd, &encodedString)) {
    if (!::android::base::ReadFully(fd, &encodedBytes[0], encodedBytes.size())) {
        LOG(WARNING) << "Could not read device to string";
        LOG(WARNING) << "Could not read device";
        return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
        return ndk::ScopedAStatus(AStatus_fromExceptionCode(EX_UNSUPPORTED_OPERATION));
    }
    }


    std::vector<uint8_t> encodedBytes(encodedString.begin(), encodedString.end());
    auto keyBytes = hadamard::DecodeKey(encodedBytes);
    auto keyBytes = hadamard::DecodeKey(encodedBytes);


    std::vector<int8_t> signedKeyBytes(keyBytes.begin(), keyBytes.end());
    std::vector<int8_t> signedKeyBytes(keyBytes.begin(), keyBytes.end());