Skip to content

Commit 8c2be35

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: #3456 Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Fedor Indutny <[email protected]>
1 parent 28280f7 commit 8c2be35

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');
@@ -126,9 +125,7 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
126125
return ip === host;
127126
});
128127
if (!valid) {
129-
reason = util.format('IP: %s is not in the cert\'s list: %s',
130-
host,
131-
ips.join(', '));
128+
reason = `IP: ${host} is not in the cert's list: ${ips.join(', ')}`;
132129
}
133130
} else if (cert.subject) {
134131
// Transform hostname to canonical form
@@ -174,13 +171,11 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
174171

175172
if (!valid) {
176173
if (cert.subjectaltname) {
177-
reason = util.format('Host: %s is not in the cert\'s altnames: %s',
178-
host,
179-
cert.subjectaltname);
174+
reason =
175+
`Host: ${host} is not in the cert's altnames: ` +
176+
`${cert.subjectaltname}`;
180177
} else {
181-
reason = util.format('Host: %s is not cert\'s CN: %s',
182-
host,
183-
cert.subject.CN);
178+
reason = `Host: ${host} is not cert's CN: ${cert.subject.CN}`;
184179
}
185180
}
186181
} else {
@@ -189,8 +184,7 @@ exports.checkServerIdentity = function checkServerIdentity(host, cert) {
189184

190185
if (!valid) {
191186
var err = new Error(
192-
util.format('Hostname/IP doesn\'t match certificate\'s altnames: %j',
193-
reason));
187+
`Hostname/IP doesn't match certificate's altnames: "${reason}"`);
194188
err.reason = reason;
195189
err.host = host;
196190
err.cert = cert;

0 commit comments

Comments
 (0)