https://gitlab.synchro.net/main/sbbs/-/commit/0750a147931c1a0a4bf841fe
Added Files:
exec/load/sha256.js
Modified Files:
exec/load/xtrn_mirror.js xtrn/betrayedalliance/getdata.js xtrn/cascadequest/getdata.js xtrn/spacequest0/getdata.js xtrn/syncbass/getdata.js xtrn/syncdoom/getwads.js xtrn/syncdrascula/getdata.js xtrn/syncduke/download.js xtrn/synclure/getdata.js xtrn/syncqueen/getdata.js xtrn/syncrpg/getdata.js
Log Message:
xtrn: hoist sha256_of_file() into exec/load/sha256.js
Ten fetchers had each grown their own copy of hexify() +
sha256_of_file() -- byte-identical apart from a comment, and two copies
this batch added. They share one now.
The helper is shaped as a polyfill. Synchronet hashes files natively via File.md5_hex (3.11) and File.sha1_hex (3.19), both streaming, but has no SHA-256 at either level -- and the md5_calc()/sha1_calc() globals take a string, so they would need a 600 MB disc image in memory. If a build
grows File.sha256_hex, sha256.js uses it and the CryptContext path falls
away with no call site touched.
It returns null rather than throwing when a file cannot be opened. The
eight pre-existing copies threw, which was fine while callers invoked
them directly, but they are now called from xtrn_mirror_download()'s
verify callback -- and an exception there escaped a function documented
never to throw, aborting an install instead of falling back to the other source. xtrn_mirror.js now also catches anything a verify callback
throws and treats it as a failed verification.
Two comments corrected along the way: the empty cc.encrypt("") does not finalize the digest -- reading .hashvalue does, its getter calling cryptEncrypt(ctx, p, 0) first -- and CryptContext.ALGO.SHA2 is SHA-256 outright, not a family selector.
Verified: NIST vectors for "abc" and "", a binary file spanning every
byte value plus embedded NULs and 0x1A against sha256sum, identical
digests at 64 KB and 7 byte chunk sizes, and synclure installing from
both the official source and the mirror.
---
þ Synchronet þ Vertrauen þ Home of Synchronet þ [vert/cvs/bbs].synchro.net