crypto: throw proper errors if out enc is UTF-16 · nodejs/node@1d50980 · GitHub
Skip to content

Commit 1d50980

Browse files
addaleaxMylesBorins
authored andcommitted
crypto: throw proper errors if out enc is UTF-16
Throw `Error`s instead of hard crashing when the `.digest()` output encoding is UTF-16. Fixes: #9817 PR-URL: #12752 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com>
1 parent eefa840 commit 1d50980

3 files changed

Lines changed: 18 additions & 4 deletions

File tree

src/node_crypto.cc

Lines changed: 8 additions & 0 deletions

test/parallel/test-crypto-hash.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,12 @@ const h3 = crypto.createHash('sha256');
108108
h3.digest();
109109
assert.throws(function() {
110110
h3.digest();
111-
},
112-
/Digest already called/);
111+
}, /Digest already called/);
113112

114113
assert.throws(function() {
115114
h3.update('foo');
116-
},
117-
/Digest already called/);
115+
}, /Digest already called/);
116+
117+
assert.throws(function() {
118+
crypto.createHash('sha256').digest('ucs2');
119+
}, /^Error: hash\.digest\(\) does not support UTF-16$/);

test/parallel/test-crypto-hmac.js

Lines changed: 4 additions & 0 deletions

0 commit comments

Comments
 (0)