summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJon Moss <me@jonathanmoss.me>2018-08-05 16:20:02 -0400
committerAnna Henningsen <anna@addaleax.net>2018-09-17 17:34:19 +0200
commit3c2aa4b9f3a566c58d2958e96f239d59f509b50c (patch)
treea95d77ee365be8daf36b8db660ff582a29373594 /lib
parent29cf335e6a81343d910910fb17d68743cc2bb5c3 (diff)
downloadandroid-node-v8-3c2aa4b9f3a566c58d2958e96f239d59f509b50c.tar.gz
android-node-v8-3c2aa4b9f3a566c58d2958e96f239d59f509b50c.tar.bz2
android-node-v8-3c2aa4b9f3a566c58d2958e96f239d59f509b50c.zip
tls: de-duplicate for TLSSocket methods
Similar approach is used for `TLSWrap`, where C++ handle methods are mapped one-to-one in JS. PR-URL: https://github.com/nodejs/node/pull/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>
Diffstat (limited to 'lib')
-rw-r--r--lib/_tls_wrap.js60
1 files changed, 15 insertions, 45 deletions
diff --git a/lib/_tls_wrap.js b/lib/_tls_wrap.js
index b3fbba0596..7df4b66122 100644
--- a/lib/_tls_wrap.js
+++ b/lib/_tls_wrap.js
@@ -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());
};
@@ -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;
};