summaryrefslogtreecommitdiff
path: root/cli/js/ops/tls.ts
blob: 3e49c1c9363488ce40e37a9674225cc693ed480e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
// Copyright 2018-2020 the Deno authors. All rights reserved. MIT license.
import { sendAsync, sendSync } from "./dispatch_json.ts";
import { Transport } from "./net.ts";

export interface ConnectTLSRequest {
  transport: Transport;
  hostname: string;
  port: number;
  certFile?: string;
}

interface ConnectTLSResponse {
  rid: number;
  localAddr: {
    hostname: string;
    port: number;
    transport: Transport;
  };
  remoteAddr: {
    hostname: string;
    port: number;
    transport: Transport;
  };
}

export async function connectTLS(
  args: ConnectTLSRequest
): Promise<ConnectTLSResponse> {
  return await sendAsync("op_connect_tls", args);
}

interface AcceptTLSResponse {
  rid: number;
  localAddr: {
    hostname: string;
    port: number;
    transport: Transport;
  };
  remoteAddr: {
    hostname: string;
    port: number;
    transport: Transport;
  };
}

export async function acceptTLS(rid: number): Promise<AcceptTLSResponse> {
  return await sendAsync("op_accept_tls", { rid });
}

export interface ListenTLSRequest {
  port: number;
  hostname: string;
  transport: Transport;
  certFile: string;
  keyFile: string;
}

interface ListenTLSResponse {
  rid: number;
  localAddr: {
    hostname: string;
    port: number;
    transport: Transport;
  };
}

export function listenTLS(args: ListenTLSRequest): ListenTLSResponse {
  return sendSync("op_listen_tls", args);
}