-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tls: make deprecated tls.createSecurePair() use public API
Make the deprecated `tls.createSecurePair()` method use other public APIs only (`TLSSocket` in particular). Since `tls.createSecurePair()` has been runtime-deprecated only since Node 8, it probably isn’t quite time to remove it yet, but this patch removes almost all of the code complexity that is retained by it. The API, as it is documented, is retained. However, it is very likely that some users have come to rely on parts of undocumented API of the `SecurePair` class, especially since some of the existing tests checked for those. Therefore, this should definitely be considered a breaking change. PR-URL: #17882 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
- Loading branch information
Showing
15 changed files
with
90 additions
and
1,871 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
'use strict'; | ||
const { Duplex } = require('stream'); | ||
|
||
const kCallback = Symbol('Callback'); | ||
const kOtherSide = Symbol('Other'); | ||
|
||
class DuplexSocket extends Duplex { | ||
constructor() { | ||
super(); | ||
this[kCallback] = null; | ||
this[kOtherSide] = null; | ||
} | ||
|
||
_read() { | ||
const callback = this[kCallback]; | ||
if (callback) { | ||
this[kCallback] = null; | ||
callback(); | ||
} | ||
} | ||
|
||
_write(chunk, encoding, callback) { | ||
this[kOtherSide][kCallback] = callback; | ||
this[kOtherSide].push(chunk); | ||
} | ||
|
||
_final(callback) { | ||
this[kOtherSide].on('end', callback); | ||
this[kOtherSide].push(null); | ||
} | ||
} | ||
|
||
class DuplexPair { | ||
constructor() { | ||
this.socket1 = new DuplexSocket(); | ||
this.socket2 = new DuplexSocket(); | ||
this.socket1[kOtherSide] = this.socket2; | ||
this.socket2[kOtherSide] = this.socket1; | ||
} | ||
} | ||
|
||
module.exports = DuplexPair; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.