-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconst.ts
67 lines (58 loc) · 1.53 KB
/
const.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
/**
* Size (in bytes) of salt block in encryption content-coding header.
*/
export const SALT_LENGTH = 16;
/**
* Size (in bytes) of record size block in encryption content-coding header.
*/
export const RS_LENGTH = 4;
/**
* Size (in bytes) of idlen block in encryption content-coding header.
*/
export const IDLEN_LENGTH = 1;
/**
* Size (in bytes) of content-encryption key.
*/
export const KEY_LENGTH = 16;
/**
* Size of authentication tag block in encryption content-coding header.
*/
export const TAG_LENGTH = 16;
/**
* Size of a nonce.
*/
export const NONCE_LENGTH = 12;
/**
* Minimum size of an encryption content-coding header.
*/
export const HEADER_LENGTH_MIN = SALT_LENGTH + RS_LENGTH + IDLEN_LENGTH;
/**
* Default size of a record.
*/
export const DEFAULT_RECORD_SIZE = 1024 * 64;
/**
* Minimum size of a record.
*/
export const RECORD_SIZE_MIN = 18;
/**
* Maximum size of a record.
*/
export const RECORD_SIZE_MAX = 2 ** 36 - 31;
const encoder: TextEncoder = new TextEncoder();
/**
* Content-encryption key info as in https://www.rfc-editor.org/rfc/rfc8188#section-2.2
*/
export const CEK_INFO: Uint8Array = encoder.encode(
"Content-Encoding: aes128gcm\0",
);
/**
* Nonce info as in https://www.rfc-editor.org/rfc/rfc8188#section-2.3
*/
export const NONCE_INFO: Uint8Array = encoder.encode(
"Content-Encoding: nonce\0",
);
/**
* Uint8Array of size 1 containing a single byte of value 1.
* This is mostly used for concatenation with others Uint8Array.
*/
export const ONE_BYTE: Uint8Array = encoder.encode("\x01");