-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathimpl.ts
50 lines (43 loc) · 1.87 KB
/
impl.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
export type HashImpl = {
oneShot?: (input: Buffer) => Buffer | ArrayBuffer,
streaming: (handler: StreamingHashHandler) => void,
};
export type StreamingHashImpl<State> = {
construct: () => State,
update: (state: State, data: Buffer) => void,
final: (state: State) => Buffer | ArrayBuffer,
};
// A wrapper so we can use 'State' as an existentially quantified type.
export type StreamingHashHandler = <State>(digester: StreamingHashImpl<State>) => void;
export type AsymmetricSignImpl = {
sign: (input: Buffer) => Buffer,
verify: (signature: Buffer, input: Buffer) => boolean,
};
export type SymmetricEncryptAndAuthImpl = {
ivNumBytes: number,
encryptAndAuth: (iv: Buffer, plainText: Buffer) => Array<Buffer>, // cipherText, authTag, etc
verifyDecrypt: (iv: Buffer, chunks: Array<Buffer>) => Array<Buffer> | null,
};
export type RandomImpl = (output: Buffer) => void;
export type Algo<Impl> = {
name: string,
source: string,
impl: Impl,
// To reduce the number of things we have to run, we don't run some implementations on large inputs.
// 1. Some implementations are slow. They're included just so people can see how slow they
// are, but let's not waste time running them on large inputs.
// 2. Some implementations are just slight variations on other ones, where the difference
// only matters for small inputs. For example, we might have variations where we
// pre-allocate some of the buffers. This only makes a significant difference for
// small inputs.
skipBigInputs?: true,
};
export type Registry = {
packages: Set<string>,
hashAlgos: Array<Algo<HashImpl>>,
macAlgos: Array<Algo<HashImpl>>,
asymmetricSignAlgos: Array<Algo<AsymmetricSignImpl>>,
symmetricEncryptAndAuthAlgos: Array<Algo<SymmetricEncryptAndAuthImpl>>,
randomAlgos: Array<Algo<RandomImpl>>,
macKey: Buffer,
};