Skip to content

Commit

Permalink
tls: remove util and calls to util.format
Browse files Browse the repository at this point in the history
Currently util.format is being used for string templating in tls.
By replacing all of the instances of util.format with backtick
string we can remove the need to require util in tls all together.

PR-URL: #3456
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Fedor Indutny <fedor@indutny.com>
  • Loading branch information
Myles Borins authored and jasnell committed Dec 17, 2015
1 parent 753c507 commit c10c086
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions lib/tls.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const net = require('net');
const url = require('url');
const util = require('util');
const binding = process.binding('crypto');
const Buffer = require('buffer').Buffer;
const constants = require('constants');
Expand Down Expand Up @@ -126,9 +125,7 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
return ip === host;
});
if (!valid) {
reason = util.format('IP: %s is not in the cert\'s list: %s',
host,
ips.join(', '));
reason = `IP: ${host} is not in the cert's list: ${ips.join(', ')}`;
}
} else if (cert.subject) {
// Transform hostname to canonical form
Expand Down Expand Up @@ -174,13 +171,11 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {

if (!valid) {
if (cert.subjectaltname) {
reason = util.format('Host: %s is not in the cert\'s altnames: %s',
host,
cert.subjectaltname);
reason =
`Host: ${host} is not in the cert's altnames: ` +
`${cert.subjectaltname}`;
} else {
reason = util.format('Host: %s is not cert\'s CN: %s',
host,
cert.subject.CN);
reason = `Host: ${host} is not cert's CN: ${cert.subject.CN}`;
}
}
} else {
Expand All @@ -189,8 +184,7 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {

if (!valid) {
var err = new Error(
util.format('Hostname/IP doesn\'t match certificate\'s altnames: %j',
reason));
`Hostname/IP doesn't match certificate's altnames: "${reason}"`);
err.reason = reason;
err.host = host;
err.cert = cert;
Expand Down

0 comments on commit c10c086

Please sign in to comment.