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

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.
This commit is contained in:
Charles Kerr 2024-09-06 20:22:44 -05:00 committed by GitHub
parent 18b1b33adc
commit 44a4328ea8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 11 additions and 20 deletions

View file

@ -251,9 +251,8 @@ bool Archive::Init() {
// Currently we only support the sha256 algorithm, we can add support for
// more below ensure we read them in preference order from most secure to
// least
if (integrity.value().algorithm != HashAlgorithm::kNone) {
ValidateIntegrityOrDie(header.c_str(), header.length(),
integrity.value());
if (integrity->algorithm != HashAlgorithm::kNone) {
ValidateIntegrityOrDie(base::as_byte_span(header), *integrity);
} else {
LOG(FATAL) << "No eligible hash for validatable asar archive: "
<< RelativePath().value();