Skip to content

Commit

Permalink
tls: improve createSecureContext in _tls_common
Browse files Browse the repository at this point in the history
- this shares the iterator variable `i` expictly.
- this converts some var to const.

PR-URL: #8781
Reviewed-By: Brian White <mscdex@mscdex.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
yorkie authored and Fishrock123 committed Oct 11, 2016
1 parent 0522aa0 commit d2eaa12
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions lib/_tls_common.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,15 @@ 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;

// 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)) {
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 {
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit d2eaa12

Please sign in to comment.