|
1 | 1 | // @ts-self-types="../type/cipher.d.ts" |
2 | 2 |
|
| 3 | +import { Uint16 } from "./dep.ts"; |
3 | 4 | import { Enum } from "./enum.js"; |
4 | 5 |
|
5 | 6 | export class Cipher extends Enum { |
6 | | - static AES_128_GCM_SHA256 = new Cipher('AES_128_GCM_SHA256', 0x01); |
7 | | - static AES_256_GCM_SHA384 = new Cipher('AES_256_GCM_SHA384', 0x02); |
8 | | - static CHACHA20_POLY1305_SHA256 = new Cipher('CHACHA20_POLY1305_SHA256', 0x03); |
| 7 | + static AES_128_GCM_SHA256 = new Cipher('AES_128_GCM_SHA256', Uint16.from(Uint8Array.of(0x13, 0x01)).value); |
| 8 | + static AES_256_GCM_SHA384 = new Cipher('AES_256_GCM_SHA384', Uint16.from(Uint8Array.of(0x13, 0x02)).value); |
| 9 | + static CHACHA20_POLY1305_SHA256 = new Cipher('CHACHA20_POLY1305_SHA256', Uint16.from(Uint8Array.of(0x13, 0x03)).value); |
| 10 | + |
| 11 | + static TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384 = new Cipher('TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384', Uint16.from(Uint8Array.of(0xC0, 0x2C)).value); |
| 12 | + static TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 = new Cipher('TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384', Uint16.from(Uint8Array.of(0xC0, 0x30)).value); |
| 13 | + static TLS_DHE_RSA_WITH_AES_256_GCM_SHA384 = new Cipher('TLS_DHE_RSA_WITH_AES_256_GCM_SHA384', Uint16.from(Uint8Array.of(0x00, 0x9F)).value); |
| 14 | + static TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256 = new Cipher('TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305_SHA256', Uint16.from(Uint8Array.of(0xCC, 0xA9)).value); |
| 15 | + static TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256 = new Cipher('TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305_SHA256', Uint16.from(Uint8Array.of(0xCC, 0xA8)).value); |
| 16 | + static TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256 = new Cipher('TLS_DHE_RSA_WITH_CHACHA20_POLY1305_SHA256', Uint16.from(Uint8Array.of(0xCC, 0xAA)).value); |
| 17 | + static TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256 = new Cipher('TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256', Uint16.from(Uint8Array.of(0xC0, 0x2B)).value); |
| 18 | + static TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 = new Cipher('TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256', Uint16.from(Uint8Array.of(0xC0, 0x2F)).value); |
| 19 | + static TLS_DHE_RSA_WITH_AES_128_GCM_SHA256 = new Cipher('TLS_DHE_RSA_WITH_AES_128_GCM_SHA256', Uint16.from(Uint8Array.of(0x00, 0x9E)).value); |
| 20 | + static TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384 = new Cipher('TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384', Uint16.from(Uint8Array.of(0xC0, 0x24)).value); |
| 21 | + static TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 = new Cipher('TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384', Uint16.from(Uint8Array.of(0xC0, 0x28)).value); |
| 22 | + static TLS_DHE_RSA_WITH_AES_256_CBC_SHA256 = new Cipher('TLS_DHE_RSA_WITH_AES_256_CBC_SHA256', Uint16.from(Uint8Array.of(0x00, 0x6B)).value); |
| 23 | + static TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 = new Cipher('TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256', Uint16.from(Uint8Array.of(0xC0, 0x23)).value); |
| 24 | + static TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 = new Cipher('TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256', Uint16.from(Uint8Array.of(0xC0, 0x27)).value); |
| 25 | + static TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 = new Cipher('TLS_DHE_RSA_WITH_AES_128_CBC_SHA256', Uint16.from(Uint8Array.of(0x00, 0x67)).value); |
| 26 | + static TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA = new Cipher('TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA', Uint16.from(Uint8Array.of(0xC0, 0x0A)).value); |
| 27 | + static TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA = new Cipher('TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA', Uint16.from(Uint8Array.of(0xC0, 0x14)).value); |
| 28 | + static TLS_DHE_RSA_WITH_AES_256_CBC_SHA = new Cipher('TLS_DHE_RSA_WITH_AES_256_CBC_SHA', Uint16.from(Uint8Array.of(0x00, 0x39)).value); |
| 29 | + static TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA = new Cipher('TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA', Uint16.from(Uint8Array.of(0xC0, 0x09)).value); |
| 30 | + static TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA = new Cipher('TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA', Uint16.from(Uint8Array.of(0xC0, 0x13)).value); |
| 31 | + static TLS_DHE_RSA_WITH_AES_128_CBC_SHA = new Cipher('TLS_DHE_RSA_WITH_AES_128_CBC_SHA', Uint16.from(Uint8Array.of(0x00, 0x33)).value); |
| 32 | + static TLS_RSA_WITH_AES_256_GCM_SHA384 = new Cipher('TLS_RSA_WITH_AES_256_GCM_SHA384', Uint16.from(Uint8Array.of(0x00, 0x9D)).value); |
| 33 | + static TLS_RSA_WITH_AES_128_GCM_SHA256 = new Cipher('TLS_RSA_WITH_AES_128_GCM_SHA256', Uint16.from(Uint8Array.of(0x00, 0x9C)).value); |
| 34 | + static TLS_RSA_WITH_AES_256_CBC_SHA256 = new Cipher('TLS_RSA_WITH_AES_256_CBC_SHA256', Uint16.from(Uint8Array.of(0x00, 0x3D)).value); |
| 35 | + static TLS_RSA_WITH_AES_128_CBC_SHA256 = new Cipher('TLS_RSA_WITH_AES_128_CBC_SHA256', Uint16.from(Uint8Array.of(0x00, 0x3C)).value); |
| 36 | + static TLS_RSA_WITH_AES_256_CBC_SHA = new Cipher('TLS_RSA_WITH_AES_256_CBC_SHA', Uint16.from(Uint8Array.of(0x00, 0x35)).value); |
| 37 | + static TLS_RSA_WITH_AES_128_CBC_SHA = new Cipher('TLS_RSA_WITH_AES_128_CBC_SHA', Uint16.from(Uint8Array.of(0x00, 0x2F)).value); |
| 38 | + static TLS_EMPTY_RENEGOTIATION_INFO_SCSV = new Cipher('TLS_EMPTY_RENEGOTIATION_INFO_SCSV', Uint16.from(Uint8Array.of(0x00, 0xFF)).value); |
9 | 39 |
|
10 | 40 | static from(array) { |
11 | | - const copy = Uint8Array.from(array); |
12 | | - if (copy.at(0) !== 0x13) throw TypeError(`Expected 0x13 at index 0`) |
13 | | - return Cipher.fromValue(copy.at(1)) |
| 41 | + const copy = Uint16.from(array.slice(0, 2)).value; |
| 42 | + return Cipher.fromValue(copy) |
14 | 43 | } |
15 | 44 |
|
16 | | - get Uint16() { return Uint8Array.of(0x13, +this) } |
17 | | - get byte(){ return this.Uint16 } |
| 45 | + get Uint16() { return Uint16.fromValue(this.value); } |
| 46 | + get byte() { return this.Uint16 } |
18 | 47 | get length() { return 2 } |
19 | 48 |
|
20 | 49 | get hashLength() { |
|
0 commit comments