Skip to content

Commit b64ce59

Browse files
Myles Borinsrvagg
Myles Borins
authored andcommitted
tls: remove util and calls to util.format
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: nodejs#3456 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Fedor Indutny <[email protected]>
1 parent f236b3a commit b64ce59

File tree

1 file changed

+6
-12
lines changed

1 file changed

+6
-12
lines changed

lib/tls.js

+6-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
const net = require('net');
44
const url = require('url');
5-
const util = require('util');
65
const binding = process.binding('crypto');
76
const Buffer = require('buffer').Buffer;
87
const constants = require('constants');
@@ -141,9 +140,7 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
141140
return ip === host;
142141
});
143142
if (!valid) {
144-
reason = util.format('IP: %s is not in the cert\'s list: %s',
145-
host,
146-
ips.join(', '));
143+
reason = `IP: ${host} is not in the cert's list: ${ips.join(', ')}`;
147144
}
148145
} else if (cert.subject) {
149146
// Transform hostname to canonical form
@@ -189,13 +186,11 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
189186

190187
if (!valid) {
191188
if (cert.subjectaltname) {
192-
reason = util.format('Host: %s is not in the cert\'s altnames: %s',
193-
host,
194-
cert.subjectaltname);
189+
reason =
190+
`Host: ${host} is not in the cert's altnames: ` +
191+
`${cert.subjectaltname}`;
195192
} else {
196-
reason = util.format('Host: %s is not cert\'s CN: %s',
197-
host,
198-
cert.subject.CN);
193+
reason = `Host: ${host} is not cert's CN: ${cert.subject.CN}`;
199194
}
200195
}
201196
} else {
@@ -204,8 +199,7 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
204199

205200
if (!valid) {
206201
var err = new Error(
207-
util.format('Hostname/IP doesn\'t match certificate\'s altnames: %j',
208-
reason));
202+
`Hostname/IP doesn't match certificate's altnames: "${reason}"`);
209203
err.reason = reason;
210204
err.host = host;
211205
err.cert = cert;

0 commit comments

Comments
 (0)