fix: ensure snapshot is valid (#48102)
* feat: add support for embedder snapshot validation * fix: cpp lint
This commit is contained in:
parent
a6b0d27bb7
commit
2e5a0b7220
5 changed files with 140 additions and 1 deletions
37
build/checksum_header.py
Normal file
37
build/checksum_header.py
Normal file
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import os
|
||||
import sys
|
||||
import hashlib
|
||||
|
||||
dir_path = os.path.dirname(os.path.realpath(__file__))
|
||||
|
||||
TEMPLATE_H = """
|
||||
#ifndef ELECTRON_SNAPSHOT_CHECKSUM_H_
|
||||
#define ELECTRON_SNAPSHOT_CHECKSUM_H_
|
||||
|
||||
namespace electron::snapshot_checksum {
|
||||
|
||||
const std::string kChecksum = "{checksum}";
|
||||
|
||||
} // namespace electron::snapshot_checksum
|
||||
|
||||
#endif // ELECTRON_SNAPSHOT_CHECKSUM_H_
|
||||
"""
|
||||
|
||||
def calculate_sha256(filepath):
|
||||
sha256_hash = hashlib.sha256()
|
||||
with open(filepath, "rb") as f:
|
||||
for byte_block in iter(lambda: f.read(4096), b""):
|
||||
sha256_hash.update(byte_block)
|
||||
return sha256_hash.hexdigest()
|
||||
|
||||
input_file = sys.argv[1]
|
||||
output_file = sys.argv[2]
|
||||
|
||||
checksum = calculate_sha256(input_file)
|
||||
|
||||
checksum_h = TEMPLATE_H.replace("{checksum}", checksum)
|
||||
|
||||
with open(output_file, 'w') as f:
|
||||
f.write(checksum_h)
|
Loading…
Add table
Add a link
Reference in a new issue