diff options
author | Brian White <mscdex@mscdex.net> | 2017-08-27 11:03:45 -0400 |
---|---|---|
committer | Ruben Bridgewater <ruben@bridgewater.de> | 2017-08-30 15:17:45 -0300 |
commit | 5723c4c5f06f1382cc7962c64f31a7f96ca8a668 (patch) | |
tree | 0c0b661029e2ca9e55f3d472637fd35d92e215d6 /lib | |
parent | 67d792a74fa76fcd0120543c89994d81f2092a28 (diff) | |
download | android-node-v8-5723c4c5f06f1382cc7962c64f31a7f96ca8a668.tar.gz android-node-v8-5723c4c5f06f1382cc7962c64f31a7f96ca8a668.tar.bz2 android-node-v8-5723c4c5f06f1382cc7962c64f31a7f96ca8a668.zip |
tls: replace forEach with for
PR-URL: https://github.com/nodejs/node/pull/15053
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/_tls_common.js | 59 |
1 files changed, 34 insertions, 25 deletions
diff --git a/lib/_tls_common.js b/lib/_tls_common.js index d2de21dd06..272e17b2f7 100644 --- a/lib/_tls_common.js +++ b/lib/_tls_common.js @@ -73,34 +73,39 @@ exports.createSecureContext = function createSecureContext(options, context) { var c = new SecureContext(options.secureProtocol, secureOptions, context); var i; + var val; if (context) return c; // NOTE: It's important to add CA before the cert to be able to load // cert's issuer in C++ code. - if (options.ca) { - if (Array.isArray(options.ca)) { - options.ca.forEach((ca) => { - validateKeyCert(ca, 'ca'); - c.context.addCACert(ca); - }); + var ca = options.ca; + if (ca !== undefined) { + if (Array.isArray(ca)) { + for (i = 0; i < ca.length; ++i) { + val = ca[i]; + validateKeyCert(val, 'ca'); + c.context.addCACert(val); + } } else { - validateKeyCert(options.ca, 'ca'); - c.context.addCACert(options.ca); + validateKeyCert(ca, 'ca'); + c.context.addCACert(ca); } } else { c.context.addRootCerts(); } - if (options.cert) { - if (Array.isArray(options.cert)) { - options.cert.forEach((cert) => { - validateKeyCert(cert, 'cert'); - c.context.setCert(cert); - }); + var cert = options.cert; + if (cert !== undefined) { + if (Array.isArray(cert)) { + for (i = 0; i < cert.length; ++i) { + val = cert[i]; + validateKeyCert(val, 'cert'); + c.context.setCert(val); + } } else { - validateKeyCert(options.cert, 'cert'); - c.context.setCert(options.cert); + validateKeyCert(cert, 'cert'); + c.context.setCert(cert); } } @@ -108,15 +113,20 @@ exports.createSecureContext = function createSecureContext(options, context) { // `ssl_set_pkey` returns `0` when the key does not match the cert, but // `ssl_set_cert` returns `1` and nullifies the key in the SSL structure // which leads to the crash later on. - if (options.key) { - if (Array.isArray(options.key)) { - options.key.forEach((k) => { - validateKeyCert(k.pem || k, 'key'); - c.context.setKey(k.pem || k, k.passphrase || options.passphrase); - }); + var key = options.key; + var passphrase = options.passphrase; + if (key !== undefined) { + if (Array.isArray(key)) { + for (i = 0; i < key.length; ++i) { + val = key[i]; + // eslint-disable-next-line eqeqeq + const pem = (val != undefined && val.pem !== undefined ? val.pem : val); + validateKeyCert(pem, 'key'); + c.context.setKey(pem, val.passphrase || passphrase); + } } else { - validateKeyCert(options.key, 'key'); - c.context.setKey(options.key, options.passphrase); + validateKeyCert(key, 'key'); + c.context.setKey(key, passphrase); } } @@ -152,7 +162,6 @@ exports.createSecureContext = function createSecureContext(options, context) { if (options.pfx) { var pfx = options.pfx; - var passphrase = options.passphrase; if (!crypto) crypto = require('crypto'); |