Browse Source

tls: improve createSecureContext in _tls_common

- this shares the iterator variable `i` expictly.
- this converts some var to const.

PR-URL: https://github.com/nodejs/node/pull/8781
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
v6.x
yorkie 8 years ago
committed by Jeremiah Senkpiel
parent
commit
d2eaa12a23
  1. 14
      lib/_tls_common.js

14
lib/_tls_common.js

@ -43,6 +43,7 @@ exports.createSecureContext = function createSecureContext(options, context) {
secureOptions |= SSL_OP_CIPHER_SERVER_PREFERENCE;
var c = new SecureContext(options.secureProtocol, secureOptions, context);
var i;
if (context) return c;
@ -50,7 +51,7 @@ exports.createSecureContext = function createSecureContext(options, context) {
// cert's issuer in C++ code.
if (options.ca) {
if (Array.isArray(options.ca)) {
for (let i = 0, len = options.ca.length; i < len; i++) {
for (i = 0; i < options.ca.length; i++) {
c.context.addCACert(options.ca[i]);
}
} else {
@ -62,7 +63,7 @@ exports.createSecureContext = function createSecureContext(options, context) {
if (options.cert) {
if (Array.isArray(options.cert)) {
for (let i = 0; i < options.cert.length; i++)
for (i = 0; i < options.cert.length; i++)
c.context.setCert(options.cert[i]);
} else {
c.context.setCert(options.cert);
@ -75,9 +76,8 @@ exports.createSecureContext = function createSecureContext(options, context) {
// which leads to the crash later on.
if (options.key) {
if (Array.isArray(options.key)) {
for (let i = 0; i < options.key.length; i++) {
var key = options.key[i];
for (i = 0; i < options.key.length; i++) {
const key = options.key[i];
if (key.passphrase)
c.context.setKey(key.pem, key.passphrase);
else
@ -103,14 +103,14 @@ exports.createSecureContext = function createSecureContext(options, context) {
c.context.setECDHCurve(options.ecdhCurve);
if (options.dhparam) {
var warning = c.context.setDHParam(options.dhparam);
const warning = c.context.setDHParam(options.dhparam);
if (warning)
internalUtil.trace(warning);
}
if (options.crl) {
if (Array.isArray(options.crl)) {
for (let i = 0, len = options.crl.length; i < len; i++) {
for (i = 0; i < options.crl.length; i++) {
c.context.addCRL(options.crl[i]);
}
} else {

Loading…
Cancel
Save