-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathindex.d.ts
250 lines (225 loc) · 9.87 KB
/
index.d.ts
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
/// <reference types="node" />
import type { Socket } from 'net';
export declare const allKeyUsages: readonly ["digitalSignature", "nonRepudiation", "keyEncipherment", "dataEncipherment", "keyAgreement", "keyCertSign", "cRLSign", "encipherOnly", "decipherOnly"];
export declare class ASN1Bytes extends Bytes {
readASN1Length(comment?: string): Promise<number>;
expectASN1Length(comment?: string): Promise<readonly [() => void, () => number]>;
readASN1OID(comment?: string): Promise<string>;
readASN1Boolean(comment?: string): Promise<boolean>;
readASN1UTCTime(): Promise<Date>;
readASN1GeneralizedTime(): Promise<Date>;
readASN1BitString(): Promise<Uint8Array<ArrayBuffer>>;
}
export declare class Bytes {
indent: number;
fetchFn: undefined | ((bytes: number) => Promise<Uint8Array | undefined>);
endOfReadableData: number;
offset: number;
dataView: DataView;
data: Uint8Array;
comments: Record<number, string>;
indents: Record<number, number>;
/**
* @param data -
* * If data is a `Uint8Array`, this is the initial data
* * If data is a `number`, this is the initial size in bytes (all zeroes)
* * If data is a `function`, this function is called to retrieve data when required
*/
constructor(data?: Uint8Array | number | ((bytes: number) => Promise<Uint8Array | undefined>), indent?: number);
readRemaining(): number;
resizeTo(newSize: number): void;
ensureReadAvailable(bytes: number): Promise<void>;
ensureWriteAvailable(bytes: number): void;
expectLength(length: number, indentDelta?: number): readonly [() => void, () => number];
comment(s: string, offset?: number): this;
lengthComment(length: number, comment?: string, inclusive?: boolean): string;
subarrayForRead(length: number): Promise<Uint8Array<ArrayBufferLike>>;
skipRead(length: number, comment?: string): Promise<this>;
readBytes(length: number): Promise<Uint8Array<ArrayBuffer>>;
readUTF8String(length: number): Promise<string>;
readUTF8StringNullTerminated(): Promise<string>;
readUint8(comment?: string): Promise<number>;
readUint16(comment?: string): Promise<number>;
readUint24(comment?: string): Promise<number>;
readUint32(comment?: string): Promise<number>;
expectBytes(expected: Uint8Array | number[], comment?: string): Promise<void>;
expectUint8(expectedValue: number, comment?: string): Promise<void>;
expectUint16(expectedValue: number, comment?: string): Promise<void>;
expectUint24(expectedValue: number, comment?: string): Promise<void>;
expectUint32(expectedValue: number, comment?: string): Promise<void>;
expectReadLength(length: number, indentDelta?: number): Promise<readonly [() => void, () => number]>;
expectLengthUint8(comment?: string): Promise<readonly [() => void, () => number]>;
expectLengthUint16(comment?: string): Promise<readonly [() => void, () => number]>;
expectLengthUint24(comment?: string): Promise<readonly [() => void, () => number]>;
expectLengthUint32(comment?: string): Promise<readonly [() => void, () => number]>;
expectLengthUint8Incl(comment?: string): Promise<readonly [() => void, () => number]>;
expectLengthUint16Incl(comment?: string): Promise<readonly [() => void, () => number]>;
expectLengthUint24Incl(comment?: string): Promise<readonly [() => void, () => number]>;
expectLengthUint32Incl(comment?: string): Promise<readonly [() => void, () => number]>;
subarrayForWrite(length: number): Uint8Array<ArrayBufferLike>;
skipWrite(length: number, comment?: string): this;
writeBytes(bytes: number[] | Uint8Array): this;
writeUTF8String(s: string): this;
writeUTF8StringNullTerminated(s: string): this;
writeUint8(value: number, comment?: string): Bytes;
writeUint16(value: number, comment?: string): Bytes;
writeUint24(value: number, comment?: string): Bytes;
writeUint32(value: number, comment?: string): Bytes;
_writeLengthGeneric(lengthBytes: number, inclusive: boolean, comment?: string): () => void;
writeLengthUint8(comment?: string): () => void;
writeLengthUint16(comment?: string): () => void;
writeLengthUint24(comment?: string): () => void;
writeLengthUint32(comment?: string): () => void;
writeLengthUint8Incl(comment?: string): () => void;
writeLengthUint16Incl(comment?: string): () => void;
writeLengthUint24Incl(comment?: string): () => void;
writeLengthUint32Incl(comment?: string): () => void;
expectWriteLength(length: number, indentDelta?: number): readonly [() => void, () => number];
array(): Uint8Array<ArrayBufferLike>;
commentedString(all?: boolean): string;
}
export declare class Cert {
serialNumber: Uint8Array;
algorithm: OID;
issuer: DistinguishedName;
validityPeriod: {
notBefore: Date;
notAfter: Date;
};
subject: DistinguishedName;
publicKey: {
identifiers: OID[];
data: Uint8Array;
all: Uint8Array;
};
signature: Uint8Array;
keyUsage?: {
critical?: boolean;
usages: Set<typeof allKeyUsages[number]>;
};
subjectAltNames?: string[];
extKeyUsage?: {
clientTls?: true;
serverTls?: true;
};
authorityKeyIdentifier?: Uint8Array;
subjectKeyIdentifier?: Uint8Array;
basicConstraints?: {
critical?: boolean;
ca?: boolean;
pathLength?: number;
} | undefined;
signedData: Uint8Array;
rawData: Uint8Array;
constructor();
static distinguishedNamesAreEqual(dn1: DistinguishedName, dn2: DistinguishedName): boolean;
static stringFromDistinguishedName(dn: DistinguishedName): string;
static create(certData: Uint8Array | ASN1Bytes | CertJSON): Promise<Cert>;
subjectAltNameMatchingHost(host: string): string | undefined;
isValidAtMoment(moment?: Date): boolean;
description(): string;
toJSON(): {
serialNumber: string;
algorithm: string;
issuer: DistinguishedName;
validityPeriod: {
notBefore: string;
notAfter: string;
};
subject: DistinguishedName;
publicKey: {
identifiers: string[];
data: string;
all: string;
};
signature: string;
keyUsage: {
critical: boolean | undefined;
usages: ("digitalSignature" | "nonRepudiation" | "keyEncipherment" | "dataEncipherment" | "keyAgreement" | "keyCertSign" | "cRLSign" | "encipherOnly" | "decipherOnly")[];
};
subjectAltNames: string[] | undefined;
extKeyUsage: {
clientTls?: true;
serverTls?: true;
} | undefined;
authorityKeyIdentifier: string | undefined;
subjectKeyIdentifier: string | undefined;
basicConstraints: {
critical?: boolean;
ca?: boolean;
pathLength?: number;
} | undefined;
signedData: string;
rawData: string;
};
static uint8ArraysFromPEM(pem: string): Uint8Array<ArrayBuffer>[];
static fromPEM(pem: string): Promise<Cert[]>;
}
export declare type CertJSON = ReturnType<typeof Cert.prototype.toJSON>;
export declare interface DataRequest {
bytes: number;
resolve: (data: Uint8Array | undefined) => void;
readMode: ReadMode;
}
export declare type DistinguishedName = Record<string, string | string[]>;
export declare function hexFromU8(u8: Uint8Array | number[], spacer?: string): string;
export declare class LazyReadFunctionReadQueue extends ReadQueue {
protected readFn: () => Promise<Uint8Array | undefined>;
protected dataIsExhausted: boolean;
constructor(readFn: () => Promise<Uint8Array | undefined>);
read(bytes: number, readMode?: ReadMode): Promise<Uint8Array<ArrayBufferLike> | undefined>;
moreDataMayFollow(): boolean;
}
export declare type OID = string;
export declare enum ReadMode {
CONSUME = 0,
PEEK = 1
}
export declare abstract class ReadQueue {
queue: Uint8Array[];
outstandingRequest: DataRequest | undefined;
constructor();
abstract moreDataMayFollow(): boolean;
enqueue(data: Uint8Array): void;
dequeue(): void;
bytesInQueue(): number;
read(bytes: number, readMode?: ReadMode): Promise<Uint8Array<ArrayBufferLike> | undefined>;
}
export declare type RootCertsData = Uint8Array;
export declare interface RootCertsDatabase {
index: RootCertsIndex;
data: RootCertsData;
}
export declare interface RootCertsIndex {
offsets: number[];
subjects: Record<string, number>;
}
export declare class SocketReadQueue extends ReadQueue {
protected socket: Socket;
constructor(socket: Socket);
moreDataMayFollow(): boolean;
}
export declare function stableStringify(x: any, replacer?: (key: string, value: any) => any, indent?: string | number): string;
export declare function startTls(host: string, rootCertsDatabase: RootCertsDatabase | string, networkRead: (bytes: number) => Promise<Uint8Array | undefined>, networkWrite: (data: Uint8Array) => void, { useSNI, requireServerTlsExtKeyUsage, requireDigitalSigKeyUsage, writePreData, expectPreData, commentPreData }?: {
useSNI?: boolean;
requireServerTlsExtKeyUsage?: boolean;
requireDigitalSigKeyUsage?: boolean;
writePreData?: Uint8Array;
expectPreData?: Uint8Array;
commentPreData?: string;
}): Promise<{
readonly read: () => Promise<Uint8Array<ArrayBufferLike> | undefined>;
readonly write: (data: Uint8Array) => Promise<void>;
readonly userCert: Cert;
}>;
export declare class TrustedCert extends Cert {
static databaseFromPEM(pem: string): Promise<RootCertsDatabase>;
static findInDatabase(subjectOrSubjectKeyId: DistinguishedName | string, db: RootCertsDatabase): Promise<Cert | undefined>;
}
export declare function u8FromHex(hex: string): Uint8Array<ArrayBuffer>;
export declare class WebSocketReadQueue extends ReadQueue {
protected socket: WebSocket;
constructor(socket: WebSocket);
moreDataMayFollow(): boolean;
}
export * from "hextreme";