summaryrefslogtreecommitdiff
path: root/lib/crypto.js
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2017-03-22 07:34:55 +0100
committerAnna Henningsen <anna@addaleax.net>2017-03-27 02:13:02 +0200
commit0db49fef4152e3642c2a0686c30bf59813e7ce1c (patch)
treef131e08dcb9124107c37d80ab3485d1e43a0a6e0 /lib/crypto.js
parentc3efe726694907ce0b2e41546d84a9a94547383e (diff)
downloadandroid-node-v8-0db49fef4152e3642c2a0686c30bf59813e7ce1c.tar.gz
android-node-v8-0db49fef4152e3642c2a0686c30bf59813e7ce1c.tar.bz2
android-node-v8-0db49fef4152e3642c2a0686c30bf59813e7ce1c.zip
crypto: support Uint8Array prime in createDH
PR-URL: https://github.com/nodejs/node/pull/11983 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'lib/crypto.js')
-rw-r--r--lib/crypto.js11
1 files changed, 7 insertions, 4 deletions
diff --git a/lib/crypto.js b/lib/crypto.js
index 7ceca8ba26..662ddef60e 100644
--- a/lib/crypto.js
+++ b/lib/crypto.js
@@ -42,6 +42,7 @@ const timingSafeEqual = binding.timingSafeEqual;
const Buffer = require('buffer').Buffer;
const stream = require('stream');
const util = require('util');
+const { isUint8Array } = process.binding('util');
const LazyTransform = require('internal/streams/lazy_transform');
const DH_GENERATOR = 2;
@@ -368,10 +369,12 @@ function DiffieHellman(sizeOrKey, keyEncoding, generator, genEncoding) {
if (!(this instanceof DiffieHellman))
return new DiffieHellman(sizeOrKey, keyEncoding, generator, genEncoding);
- if (!(sizeOrKey instanceof Buffer) &&
- typeof sizeOrKey !== 'number' &&
- typeof sizeOrKey !== 'string')
- throw new TypeError('First argument should be number, string or Buffer');
+ if (typeof sizeOrKey !== 'number' &&
+ typeof sizeOrKey !== 'string' &&
+ !isUint8Array(sizeOrKey)) {
+ throw new TypeError('First argument should be number, string, ' +
+ 'Uint8Array or Buffer');
+ }
if (keyEncoding) {
if (typeof keyEncoding !== 'string' ||