Skip to content

Commit

Permalink
tls: de-duplicate for TLSSocket methods
Browse files Browse the repository at this point in the history
Similar approach is used for `TLSWrap`, where C++ handle methods are
mapped one-to-one in JS.

PR-URL: #22142
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
maclover7 authored and addaleax committed Sep 17, 2018
1 parent 29cf335 commit 3c2aa4b
Showing 1 changed file with 15 additions and 45 deletions.
60 changes: 15 additions & 45 deletions lib/_tls_wrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -591,10 +591,6 @@ TLSSocket.prototype.setMaxSendFragment = function setMaxSendFragment(size) {
return this._handle.setMaxSendFragment(size) === 1;
};

TLSSocket.prototype.getTLSTicket = function getTLSTicket() {
return this._handle.getTLSTicket();
};

TLSSocket.prototype._handleTimeout = function() {
this._emitTLSError(new ERR_TLS_HANDSHAKE_TIMEOUT());
};
Expand Down Expand Up @@ -671,51 +667,25 @@ TLSSocket.prototype.getPeerCertificate = function(detailed) {
return null;
};

TLSSocket.prototype.getFinished = function() {
if (this._handle)
return this._handle.getFinished();
};

TLSSocket.prototype.getPeerFinished = function() {
if (this._handle)
return this._handle.getPeerFinished();
};

TLSSocket.prototype.getSession = function() {
if (this._handle) {
return this._handle.getSession();
}

return null;
};

TLSSocket.prototype.isSessionReused = function() {
if (this._handle) {
return this._handle.isSessionReused();
}

return null;
};

TLSSocket.prototype.getCipher = function(err) {
if (this._handle) {
return this._handle.getCurrentCipher();
} else {
// Proxy TLSSocket handle methods
function makeSocketMethodProxy(name) {
return function socketMethodProxy(...args) {
if (this._handle)
return this._handle[name].apply(this._handle, args);
return null;
}
};

TLSSocket.prototype.getEphemeralKeyInfo = function() {
if (this._handle)
return this._handle.getEphemeralKeyInfo();
};
}

return null;
};
[
'getFinished', 'getPeerFinished', 'getSession', 'isSessionReused',
'getEphemeralKeyInfo', 'getProtocol', 'getTLSTicket'
].forEach((method) => {
TLSSocket.prototype[method] = makeSocketMethodProxy(method);
});

TLSSocket.prototype.getProtocol = function() {
TLSSocket.prototype.getCipher = function(err) {
if (this._handle)
return this._handle.getProtocol();

return this._handle.getCurrentCipher();
return null;
};

Expand Down

0 comments on commit 3c2aa4b

Please sign in to comment.