From af532e7daa9ff87def4a814355532d765052535f Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Sat, 14 Dec 2019 10:30:40 -0500 Subject: [PATCH 1/5] tls: for...of in _tls_common.js --- lib/_tls_common.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/lib/_tls_common.js b/lib/_tls_common.js index e4180a2f4dc7a3..61cc2a1d9961e6 100644 --- a/lib/_tls_common.js +++ b/lib/_tls_common.js @@ -101,14 +101,12 @@ exports.createSecureContext = function createSecureContext(options) { const c = new SecureContext(options.secureProtocol, secureOptions, options.minVersion, options.maxVersion); let i; - let val; // Add CA before the cert to be able to load cert's issuer in C++ code. const { ca } = options; if (ca) { if (ArrayIsArray(ca)) { - for (i = 0; i < ca.length; ++i) { - val = ca[i]; + for (const val in ca) { validateKeyOrCertOption('ca', val); c.context.addCACert(val); } @@ -123,8 +121,7 @@ exports.createSecureContext = function createSecureContext(options) { const { cert } = options; if (cert) { if (ArrayIsArray(cert)) { - for (i = 0; i < cert.length; ++i) { - val = cert[i]; + for (const val in cert) { validateKeyOrCertOption('cert', val); c.context.setCert(val); } @@ -142,8 +139,7 @@ exports.createSecureContext = function createSecureContext(options) { const passphrase = options.passphrase; if (key) { if (ArrayIsArray(key)) { - for (i = 0; i < key.length; ++i) { - val = key[i]; + for (const val in key) { // eslint-disable-next-line eqeqeq const pem = (val != undefined && val.pem !== undefined ? val.pem : val); validateKeyOrCertOption('key', pem); @@ -242,8 +238,8 @@ exports.createSecureContext = function createSecureContext(options) { if (options.crl) { if (ArrayIsArray(options.crl)) { - for (i = 0; i < options.crl.length; i++) { - c.context.addCRL(options.crl[i]); + for (const crl in options.crl) { + c.context.addCRL(crl); } } else { c.context.addCRL(options.crl); @@ -259,8 +255,7 @@ exports.createSecureContext = function createSecureContext(options) { toBuf = require('internal/crypto/util').toBuf; if (ArrayIsArray(options.pfx)) { - for (i = 0; i < options.pfx.length; i++) { - const pfx = options.pfx[i]; + for (const pfx in options.pfx) { const raw = pfx.buf ? pfx.buf : pfx; const buf = toBuf(raw); const passphrase = pfx.passphrase || options.passphrase; From 666a4b4dae807887a530a3f3a8415bff6085518d Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Sat, 14 Dec 2019 10:32:16 -0500 Subject: [PATCH 2/5] tls: for...of in _tls_wrap.js --- lib/_tls_wrap.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js index 5d7a5c8e281047..02a5074b4fead8 100644 --- a/lib/_tls_wrap.js +++ b/lib/_tls_wrap.js @@ -465,9 +465,9 @@ function makeMethodProxy(name) { return this._parent[name].apply(this._parent, args); }; } -for (let n = 0; n < proxiedMethods.length; n++) { - tls_wrap.TLSWrap.prototype[proxiedMethods[n]] = - makeMethodProxy(proxiedMethods[n]); +for (const proxiedMethod of proxiedMethods) { + tls_wrap.TLSWrap.prototype[proxiedMethod] = + makeMethodProxy(proxiedMethod); } tls_wrap.TLSWrap.prototype.close = function close(cb) { @@ -1303,8 +1303,7 @@ Server.prototype[EE.captureRejectionSymbol] = function( function SNICallback(servername, callback) { const contexts = this.server._contexts; - for (let i = 0; i < contexts.length; i++) { - const elem = contexts[i]; + for (const elem of contexts) { if (elem[0].test(servername)) { callback(null, elem[1]); return; From 494f6a47cd0a9767ce51fa585ac2d3b28f40ed16 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Sat, 14 Dec 2019 10:35:38 -0500 Subject: [PATCH 3/5] tls: for...of in tls.js --- lib/internal/tls.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/lib/internal/tls.js b/lib/internal/tls.js index d7370ad52c0f8e..8d538b27574402 100644 --- a/lib/internal/tls.js +++ b/lib/internal/tls.js @@ -9,12 +9,11 @@ const { // C=US\nST=CA\nL=SF\nO=Joyent\nOU=Node.js\nCN=ca1\nemailAddress=ry@clouds.org function parseCertString(s) { const out = ObjectCreate(null); - const parts = s.split('\n'); - for (let i = 0, len = parts.length; i < len; i++) { - const sepIndex = parts[i].indexOf('='); + for (const part of s.split('\n')) { + const sepIndex = part.indexOf('='); if (sepIndex > 0) { - const key = parts[i].slice(0, sepIndex); - const value = parts[i].slice(sepIndex + 1); + const key = part.slice(0, sepIndex); + const value = part.slice(sepIndex + 1); if (key in out) { if (!ArrayIsArray(out[key])) { out[key] = [out[key]]; From 9f05ca5dbca87db618dbb1b9692e667eeb145283 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Sat, 14 Dec 2019 10:37:39 -0500 Subject: [PATCH 4/5] f remove unused i from _tls_common.js --- lib/_tls_common.js | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/_tls_common.js b/lib/_tls_common.js index 61cc2a1d9961e6..bfc155b6b0194f 100644 --- a/lib/_tls_common.js +++ b/lib/_tls_common.js @@ -100,7 +100,6 @@ exports.createSecureContext = function createSecureContext(options) { const c = new SecureContext(options.secureProtocol, secureOptions, options.minVersion, options.maxVersion); - let i; // Add CA before the cert to be able to load cert's issuer in C++ code. const { ca } = options; From c0cd5b21c87e0e0969d39dc37dcd33233959bca8 Mon Sep 17 00:00:00 2001 From: Trivikram Kamat <16024985+trivikr@users.noreply.github.com> Date: Sat, 14 Dec 2019 10:47:15 -0500 Subject: [PATCH 5/5] f typo for...in to for...of --- lib/_tls_common.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/_tls_common.js b/lib/_tls_common.js index bfc155b6b0194f..9f7747c1b52848 100644 --- a/lib/_tls_common.js +++ b/lib/_tls_common.js @@ -105,7 +105,7 @@ exports.createSecureContext = function createSecureContext(options) { const { ca } = options; if (ca) { if (ArrayIsArray(ca)) { - for (const val in ca) { + for (const val of ca) { validateKeyOrCertOption('ca', val); c.context.addCACert(val); } @@ -120,7 +120,7 @@ exports.createSecureContext = function createSecureContext(options) { const { cert } = options; if (cert) { if (ArrayIsArray(cert)) { - for (const val in cert) { + for (const val of cert) { validateKeyOrCertOption('cert', val); c.context.setCert(val); } @@ -138,7 +138,7 @@ exports.createSecureContext = function createSecureContext(options) { const passphrase = options.passphrase; if (key) { if (ArrayIsArray(key)) { - for (const val in key) { + for (const val of key) { // eslint-disable-next-line eqeqeq const pem = (val != undefined && val.pem !== undefined ? val.pem : val); validateKeyOrCertOption('key', pem); @@ -237,7 +237,7 @@ exports.createSecureContext = function createSecureContext(options) { if (options.crl) { if (ArrayIsArray(options.crl)) { - for (const crl in options.crl) { + for (const crl of options.crl) { c.context.addCRL(crl); } } else { @@ -254,7 +254,7 @@ exports.createSecureContext = function createSecureContext(options) { toBuf = require('internal/crypto/util').toBuf; if (ArrayIsArray(options.pfx)) { - for (const pfx in options.pfx) { + for (const pfx of options.pfx) { const raw = pfx.buf ? pfx.buf : pfx; const buf = toBuf(raw); const passphrase = pfx.passphrase || options.passphrase;