refactor: take a uint8_t span in ValidateIntegrityOrDie() (#43612)

refactor: take a uint8_t span in ValidateIntegrityOrDie()

Doing some groundwork for fixing unsafe base::File() APIs:

- Change ValidateIntegrityOrDie() to take a span<const uint8_t> arg.
  We'll need this to migrate asar's base::File API calls away from the
  ones tagged `UNSAFE_BUFFER_USAGE` because the safe counterparts use
  span<uint8_t> too.

- Simplify ValidateIntegrityOrDie()'s implementation by using
  crypto::SHA256Hash() instead of reinventing the wheel.

Co-authored-by: trop[bot] <37223003+trop[bot]@users.noreply.github.com>
Co-authored-by: Charles Kerr <charles@charleskerr.com>
This commit is contained in:
trop[bot] 2024-09-06 21:56:27 -05:00 committed by GitHub
parent 6f68a40430
commit 8d76b8dba9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 11 additions and 20 deletions

View file

@ -8,6 +8,8 @@
#include <memory>
#include <string>
#include "base/containers/span.h"
namespace base {
class FilePath;
}
@ -29,8 +31,7 @@ bool GetAsarArchivePath(const base::FilePath& full_path,
// Same with base::ReadFileToString but supports asar Archive.
bool ReadFileToString(const base::FilePath& path, std::string* contents);
void ValidateIntegrityOrDie(const char* data,
size_t size,
void ValidateIntegrityOrDie(base::span<const uint8_t> input,
const IntegrityPayload& integrity);
} // namespace asar