mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
e435c2be15
Co-authored-by: Ryan Dahl <ry@tinyclouds.org>
59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
|
|
import * as tlsOps from "./ops/tls.ts";
|
|
import { Listener, Transport, Conn, ConnImpl, ListenerImpl } from "./net.ts";
|
|
|
|
// TODO(ry) There are many configuration options to add...
|
|
// https://docs.rs/rustls/0.16.0/rustls/struct.ClientConfig.html
|
|
interface ConnectTLSOptions {
|
|
transport?: Transport;
|
|
port: number;
|
|
hostname?: string;
|
|
certFile?: string;
|
|
}
|
|
|
|
export async function connectTLS({
|
|
port,
|
|
hostname = "127.0.0.1",
|
|
transport = "tcp",
|
|
certFile = undefined
|
|
}: ConnectTLSOptions): Promise<Conn> {
|
|
const res = await tlsOps.connectTLS({
|
|
port,
|
|
hostname,
|
|
transport,
|
|
certFile
|
|
});
|
|
return new ConnImpl(res.rid, res.remoteAddr!, res.localAddr!);
|
|
}
|
|
|
|
class TLSListenerImpl extends ListenerImpl {
|
|
async accept(): Promise<Conn> {
|
|
const res = await tlsOps.acceptTLS(this.rid);
|
|
return new ConnImpl(res.rid, res.remoteAddr, res.localAddr);
|
|
}
|
|
}
|
|
|
|
export interface ListenTLSOptions {
|
|
port: number;
|
|
hostname?: string;
|
|
transport?: Transport;
|
|
certFile: string;
|
|
keyFile: string;
|
|
}
|
|
|
|
export function listenTLS({
|
|
port,
|
|
certFile,
|
|
keyFile,
|
|
hostname = "0.0.0.0",
|
|
transport = "tcp"
|
|
}: ListenTLSOptions): Listener {
|
|
const res = tlsOps.listenTLS({
|
|
port,
|
|
certFile,
|
|
keyFile,
|
|
hostname,
|
|
transport
|
|
});
|
|
return new TLSListenerImpl(res.rid, res.localAddr);
|
|
}
|