mirror of
https://github.com/nodejs/node.git
synced 2026-11-26 21:58:26 -05:00
policy: fix integrity when DEFAULT_ENCODING is set
PR-URL: https://github.com/nodejs/node/pull/39750 Reviewed-By: Bradley Farias <bradley.meck@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
e660892f1a
commit
0ff520cf02
6 files changed
+60
-2
No files matched your search
@@ -501,8 +501,10 @@ class Manifest {
|
||||
value: expected
|
||||
} = integrityEntries[i];
|
||||
const hash = createHash(algorithm);
|
||||
HashUpdate(hash, content);
|
||||
const digest = HashDigest(hash);
|
||||
// TODO(tniessen): the content should not be passed as a string in the
|
||||
// first place, see https://github.com/nodejs/node/issues/39707
|
||||
HashUpdate(hash, content, 'utf8');
|
||||
const digest = HashDigest(hash, 'buffer');
|
||||
if (digest.length === expected.length &&
|
||||
timingSafeEqual(digest, expected)) {
|
||||
return true;
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
*.js text eol=lf
|
||||
@@ -0,0 +1,3 @@
|
||||
'use strict';
|
||||
|
||||
// No code.
|
||||
@@ -0,0 +1,4 @@
|
||||
'use strict';
|
||||
|
||||
require('crypto').DEFAULT_ENCODING = process.env.DEFAULT_ENCODING;
|
||||
require('./dep.js');
|
||||
@@ -0,0 +1,14 @@
|
||||
{
|
||||
"resources": {
|
||||
"./parent.js": {
|
||||
"integrity": "sha384-j4pMdq83q5Bq9+idcHuGKzi89FrYm1PhZYrEw3irbNob6g4i3vKBjfYiRNYwmoGr",
|
||||
"dependencies": {
|
||||
"crypto": true,
|
||||
"./dep.js": true
|
||||
}
|
||||
},
|
||||
"./dep.js": {
|
||||
"integrity": "sha384-VU7GIrTix/HFLhUb4yqsV4n1xXqjPcWw6kLvjuKXtR1+9nmufJu5vZLajBs8brIW"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
'use strict';
|
||||
|
||||
const common = require('../common');
|
||||
if (!common.hasCrypto)
|
||||
common.skip('missing crypto');
|
||||
common.requireNoPackageJSONAbove();
|
||||
|
||||
const fixtures = require('../common/fixtures');
|
||||
|
||||
const assert = require('assert');
|
||||
const { spawnSync } = require('child_process');
|
||||
|
||||
const encodings = ['buffer', 'utf8', 'utf16le', 'latin1', 'base64', 'hex'];
|
||||
|
||||
for (const encoding of encodings) {
|
||||
const dep = fixtures.path('policy', 'crypto-default-encoding', 'parent.js');
|
||||
const depPolicy = fixtures.path(
|
||||
'policy',
|
||||
'crypto-default-encoding',
|
||||
'policy.json');
|
||||
const { status } = spawnSync(
|
||||
process.execPath,
|
||||
[
|
||||
'--experimental-policy', depPolicy, dep,
|
||||
],
|
||||
{
|
||||
env: {
|
||||
...process.env,
|
||||
DEFAULT_ENCODING: encoding
|
||||
}
|
||||
}
|
||||
);
|
||||
assert.strictEqual(status, 0);
|
||||
}
|
||||
Reference in new issue
Block a user