Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getSocket = function(protocol, options) {
switch (protocol) {
case 'tcp':
return new net.Socket();
case 'tls':
// todo
case 'ssl':
return new tls.TLSSocket(options);
}
throw new Error('unknown protocol');
}
this.dataSocket.connect({host, port, family}, () => {
this.dataSocket.pause();
if (this.connection.secure) {
const secureContext = tls.createSecureContext(this.server.options.tls);
const secureSocket = new tls.TLSSocket(this.dataSocket, {
isServer: true,
secureContext
});
this.dataSocket = secureSocket;
}
this.dataSocket.connected = true;
});
});
function secureTLSSocket(conn, client) {
const serverSocket = new tls.TLSSocket(conn, options);
serverSocket.on('error', (e) => {
throw new Error(`Socket error: ${e}`);
});
serverSocket.pipe(client);
}