Reintroduce Subresource Integrity hashes in the previews and as a separate option in the README

This commit is contained in:
Nathan Downs
2019-09-25 14:50:07 -07:00
parent 2538ae039c
commit 4c21f09d6b
5 changed files with 31 additions and 2 deletions

View File

@ -1,3 +1,5 @@
const { spawnSync } = require('child_process');
function fromCodePoint(codepoint) {
var code = typeof codepoint === 'string' ?
parseInt(codepoint, 16) : codepoint;
@ -26,3 +28,13 @@ function UTF162JSON(text) {
return r.join('');
}
module.exports.UTF162JSON = UTF162JSON;
function getIntegrityHash(filename) {
const algorithm = 'sha384';
const digest = spawnSync('openssl', ['dgst', `-${algorithm}`, '-binary', filename]);
if (digest.status || digest.signal){
throw new Error(digest.stderr.toString('utf8'));
}
return `${algorithm}-${digest.stdout.toString('base64')}`;
}
module.exports.getIntegrityHash = getIntegrityHash;