Skip to content

Commit a87f824

Browse files
committed
add a more complete cipher
1 parent cf321b1 commit a87f824

File tree

3 files changed

+44
-12
lines changed

3 files changed

+44
-12
lines changed

deno.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tls/enum",
3-
"version": "0.8.3",
3+
"version": "0.8.4",
44
"exports": "./src/mod.ts",
55
"publish": {
66
"exclude": ["dist/"]

src/cipher.js

Lines changed: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,49 @@
11
// @ts-self-types="../type/cipher.d.ts"
22

3+
import { Uint16 } from "./dep.ts";
34
import { Enum } from "./enum.js";
45

56
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);
939

1040
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)
1443
}
1544

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 }
1847
get length() { return 2 }
1948

2049
get hashLength() {

test/cipher_test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,14 @@ import { assertEquals } from "jsr:@std/assert";
22
import { Cipher } from "../src/cipher.js";
33

44
Deno.test("Cipher", () => {
5-
const test = Cipher.AES_128_GCM_SHA256.Uint16;
6-
const back = Cipher.from(test).Uint16;
5+
const test = Cipher.AES_128_GCM_SHA256.byte;
6+
const back = Cipher.from(test).byte;
77
assertEquals(test, back)
88
})
99

1010
console.log(Cipher.AES_128_GCM_SHA256.keyLength);
1111
console.log(Cipher.AES_256_GCM_SHA384.hashLength);
12-
console.log(Cipher.CHACHA20_POLY1305_SHA256.keyLength);
12+
console.log(Cipher.CHACHA20_POLY1305_SHA256.keyLength);
13+
14+
const test = Cipher.AES_128_GCM_SHA256.byte;
15+
const back = Cipher.from(test).byte;

0 commit comments

Comments
 (0)