diff options
author | Bert Belder <bertbelder@gmail.com> | 2021-10-26 22:27:47 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-26 22:27:47 +0200 |
commit | cf9c4f0031a46b58989a984af0528a2005547e2d (patch) | |
tree | 40d2a2efbc8570e0f875ce877f6f95c6d5f27be9 /ext/net/02_tls.js | |
parent | c27ef0ac7b5fd7aba4de24292e80387c8243896e (diff) |
feat(ext/net): add TlsConn.handshake() (#12467)
A `handshake()` method was added that returns when the TLS handshake is
complete. The `TlsListener` and `TlsConn` interfaces were added to
accomodate this new method.
Closes: #11759.
Diffstat (limited to 'ext/net/02_tls.js')
-rw-r--r-- | ext/net/02_tls.js | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/ext/net/02_tls.js b/ext/net/02_tls.js index 9f8fb314c..df7923f4c 100644 --- a/ext/net/02_tls.js +++ b/ext/net/02_tls.js @@ -23,6 +23,16 @@ return core.opAsync("op_start_tls", args); } + function opTlsHandshake(rid) { + return core.opAsync("op_tls_handshake", rid); + } + + class TlsConn extends Conn { + handshake() { + return opTlsHandshake(this.rid); + } + } + async function connectTls({ port, hostname = "127.0.0.1", @@ -41,13 +51,13 @@ certChain, privateKey, }); - return new Conn(res.rid, res.remoteAddr, res.localAddr); + return new TlsConn(res.rid, res.remoteAddr, res.localAddr); } - class TLSListener extends Listener { + class TlsListener extends Listener { async accept() { const res = await opAcceptTLS(this.rid); - return new Conn(res.rid, res.remoteAddr, res.localAddr); + return new TlsConn(res.rid, res.remoteAddr, res.localAddr); } } @@ -67,7 +77,7 @@ transport, alpnProtocols, }); - return new TLSListener(res.rid, res.localAddr); + return new TlsListener(res.rid, res.localAddr); } async function startTls( @@ -80,13 +90,14 @@ certFile, caCerts, }); - return new Conn(res.rid, res.remoteAddr, res.localAddr); + return new TlsConn(res.rid, res.remoteAddr, res.localAddr); } window.__bootstrap.tls = { startTls, listenTls, connectTls, - TLSListener, + TlsConn, + TlsListener, }; })(this); |