Verified Commit 7e05454e authored by Pier Angelo Vendrame's avatar Pier Angelo Vendrame 🎃
Browse files

fixup! Bug 19121: reinstate the update.xml hash check

Bug 41668: Port some updater patches to Base Browser

Modernize the way to compute the hash digest.
parent 6209ee94
Loading
Loading
Loading
Loading
+7 −16
Original line number Diff line number Diff line
@@ -996,21 +996,6 @@ function LOG(string) {
  }
}

/**
 * Convert a string containing binary values to hex.
 */
function binaryToHex(input) {
  var result = "";
  for (var i = 0; i < input.length; ++i) {
    var hex = input.charCodeAt(i).toString(16);
    if (hex.length == 1) {
      hex = "0" + hex;
    }
    result += hex;
  }
  return result;
}

/**
 * Gets the specified directory at the specified hierarchy under the
 * update root directory and creates it if it doesn't exist.
@@ -5204,7 +5189,13 @@ Downloader.prototype = {
      // encoded binary (such as what is typically output by programs like
      // sha1sum).  In the future, this may change to base64 depending on how
      // we choose to compute these hashes.
      digest = binaryToHex(hash.finish(false));
      hash = hash.finish(false);
      digest = Array.from(hash, (c, i) =>
        hash
          .charCodeAt(i)
          .toString(16)
          .padStart(2, "0")
      ).join("");
    } catch (e) {
      LOG(
        "Downloader:_verifyDownload - failed to compute hash of the downloaded update archive"