Skip to content

Commit d18cf3a

Browse files
committed
remove other non Enum class
1 parent b5c2413 commit d18cf3a

File tree

8 files changed

+5
-307
lines changed

8 files changed

+5
-307
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.7.0",
3+
"version": "0.7.1",
44
"exports": "./src/mod.ts",
55
"publish": {
66
"exclude": ["dist/"]

src/certificatetype.js

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
// @ts-self-types="../type/certificatetype.d.ts"
33

44
import { Enum } from "./enum.js";
5-
import { Constrained, Struct, Uint24, Uint8, Uint16 } from "./dep.ts"
6-
import { x509 } from "./dep.ts";
7-
import { Extension } from "./extensiontype.js"
85

96
/**
107
* Supported groups - @see https://datatracker.ietf.org/doc/html/rfc8446#section-4.2.7.

src/contentype.js

Lines changed: 1 addition & 107 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
// deno-lint-ignore-file no-slow-types
22
// @ts-self-types="../type/contentype.d.ts"
33

4-
import { Uint8, Uint16, Struct } from "./dep.ts";
4+
import { Uint8 } from "./dep.ts";
55
import { Enum } from "./enum.js";
6-
import { Handshake } from "./handshaketype.js";
7-
import { HandshakeType } from "./handshaketype.js";
8-
import { Version } from "./version.js";
9-
import { Alert } from "./alert.js"
106

117
/**
128
* The higher-level protocol used to process the enclosed
@@ -40,109 +36,7 @@ export class ContentType extends Enum {
4036

4137
/**return 8 */
4238
get bit() { return 8 }
43-
44-
tlsPlaintext(fragment) {
45-
return TLSPlaintext.createFrom(
46-
this,
47-
fragment.msg_type == HandshakeType.CLIENT_HELLO ? Version.TLS10: Version.TLS12,
48-
fragment
49-
)
50-
}
51-
52-
tlsInnerPlaintext(content, numZeros) {
53-
return new TLSInnerPlaintext(content, this, numZeros)
54-
}
55-
56-
tlsCiphertext(encrypted_record) {
57-
return new TLSCiphertext(encrypted_record)
58-
}
5939
}
6040

61-
export class TLSPlaintext extends Uint8Array {
62-
static from(array) {
63-
let offset = 0;
64-
const copy = Uint8Array.from(array);
65-
const type = ContentType.from(copy); offset += 1;
66-
const version = Version.from(copy.subarray(offset)); offset += 2;
67-
const lengthOf = Uint16.from(copy.subarray(offset)).value; offset += 2;
68-
const fragment = copy.subarray(offset, offset + lengthOf)
69-
return new TLSPlaintext(type, version, fragment)
70-
}
71-
static createFrom(type, version, fragment) { return new TLSPlaintext(type, version, fragment) }
72-
constructor(type, version, fragment) {
73-
const struct = new Struct(
74-
type.Uint8,
75-
version.protocolVersion(),
76-
Uint16.fromValue(fragment.length),
77-
fragment
78-
)
79-
super(struct)
80-
81-
this.type = type;
82-
this.version = version;
83-
this.fragment = fragment
84-
this.items = struct.items
85-
86-
this.parseFragment();
87-
}
88-
parseFragment(){
89-
if(this.type == ContentType.HANDSHAKE){
90-
this.handshake = Handshake.from(this.fragment);
91-
}
92-
if(this.type == ContentType.ALERT){
93-
this.alert = Alert.from(this.fragment);
94-
}
95-
}
96-
}
97-
98-
export class TLSInnerPlaintext extends Uint8Array {
99-
content;
100-
type;
101-
numZeros;
102-
static from(array) {
103-
const copy = Uint8Array.from(array);
104-
const lastNonZeroIndex = copy.reduceRight((li, v, i) => (li === -1 && v !== 0 ? i : li), -1);
105-
const content = copy.slice(0, lastNonZeroIndex);
106-
const type = ContentType.fromValue(copy[lastNonZeroIndex]);
107-
const numZeros = copy.length - 1 - lastNonZeroIndex;
108-
return new TLSInnerPlaintext(content, type, numZeros)
109-
}
110-
constructor(content, type, numZeros = 0) {
111-
const struct = new Uint8Array(content.length + 1 + numZeros);
112-
struct.set(content, 0);
113-
struct[content.length] = +type;
114-
super(struct);
115-
this.content = content;
116-
this.type = type;
117-
this.numZeros = numZeros
118-
}
119-
header(keyLength){
120-
const lengthOf = this.length + keyLength;
121-
return Uint8Array.of(+this.type, 3, 3, Math.trunc(lengthOf / 256), lengthOf % 256)
122-
}
123-
}
124-
125-
export class TLSCiphertext extends Uint8Array {
126-
static from(array) {
127-
const copy = Uint8Array.from(array);
128-
// NOTE should check contentType
129-
// NOTE legacy version can be bypassed
130-
const lengthOf = Uint16.from(copy.subarray(3)).value;
131-
const encrypted_record = copy.subarray(5, lengthOf + 5);
132-
return new TLSCiphertext(encrypted_record)
133-
}
134-
constructor(encrypted_record) {
135-
const struct = new Uint8Array(encrypted_record.length + 5);
136-
const lengthOf = Uint16.fromValue(encrypted_record.length);
137-
struct[0] = 23; // always application data
138-
struct[1] = 3; // major legacy version;
139-
struct[2] = 3; // minor legacy verions = TLS v1.2
140-
struct.set(lengthOf, 3);
141-
struct.set(encrypted_record, 5);
142-
super(struct)
143-
this.header = Uint8Array.from(struct.subarray(0, 5));
144-
this.encrypted_record = Uint8Array.from(encrypted_record)
145-
}
146-
}
14741

14842
//npx -p typescript tsc ./src/contentype.js --declaration --allowJs --emitDeclarationOnly --lib ESNext --outDir ./dist

src/mod.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@ export * from "./keyupdate.js"
99
export * from "./namedgroup.js"
1010
export * from "./pskmode.js"
1111
export * from "./version.js"
12-
export * from "./cipher.js"
12+
export * from "./cipher.js"
13+
export * from "./bimap.js"

test/certificate_test.js

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +0,0 @@
1-
import { Certificate } from "../src/certificatetype.js";
2-
import { Handshake } from "../src/handshaketype.js";
3-
import { HexaDecimal } from "../src/dep.ts";
4-
5-
const test = Handshake.from(HexaDecimal.fromString(`0b 00 01 b9 00 00 01 b5 00 01 b0 30 82
6-
01 ac 30 82 01 15 a0 03 02 01 02 02 01 02 30 0d 06 09 2a 86 48
7-
86 f7 0d 01 01 0b 05 00 30 0e 31 0c 30 0a 06 03 55 04 03 13 03
8-
72 73 61 30 1e 17 0d 31 36 30 37 33 30 30 31 32 33 35 39 5a 17
9-
0d 32 36 30 37 33 30 30 31 32 33 35 39 5a 30 0e 31 0c 30 0a 06
10-
03 55 04 03 13 03 72 73 61 30 81 9f 30 0d 06 09 2a 86 48 86 f7
11-
0d 01 01 01 05 00 03 81 8d 00 30 81 89 02 81 81 00 b4 bb 49 8f
12-
82 79 30 3d 98 08 36 39 9b 36 c6 98 8c 0c 68 de 55 e1 bd b8 26
13-
d3 90 1a 24 61 ea fd 2d e4 9a 91 d0 15 ab bc 9a 95 13 7a ce 6c
14-
1a f1 9e aa 6a f9 8c 7c ed 43 12 09 98 e1 87 a8 0e e0 cc b0 52
15-
4b 1b 01 8c 3e 0b 63 26 4d 44 9a 6d 38 e2 2a 5f da 43 08 46 74
16-
80 30 53 0e f0 46 1c 8c a9 d9 ef bf ae 8e a6 d1 d0 3e 2b d1 93
17-
ef f0 ab 9a 80 02 c4 74 28 a6 d3 5a 8d 88 d7 9f 7f 1e 3f 02 03
18-
01 00 01 a3 1a 30 18 30 09 06 03 55 1d 13 04 02 30 00 30 0b 06
19-
03 55 1d 0f 04 04 03 02 05 a0 30 0d 06 09 2a 86 48 86 f7 0d 01
20-
01 0b 05 00 03 81 81 00 85 aa d2 a0 e5 b9 27 6b 90 8c 65 f7 3a
21-
72 67 17 06 18 a5 4c 5f 8a 7b 33 7d 2d f7 a5 94 36 54 17 f2 ea
22-
e8 f8 a5 8c 8f 81 72 f9 31 9c f3 6b 7f d6 c5 5b 80 f2 1a 03 01
23-
51 56 72 60 96 fd 33 5e 5e 67 f2 db f1 02 70 2e 60 8c ca e6 be
24-
c1 fc 63 a4 2a 99 be 5c 3e b7 10 7c 3c 54 e9 b9 eb 2b d5 20 3b
25-
1c 3b 84 e0 a8 b2 f7 59 40 9b a3 ea c9 d9 1d 40 2d cc 0c c8 f8
26-
96 12 29 ac 91 87 b4 2b 4d e1 00 00`).byte)
27-
28-
const certificate = Certificate.from(test.message)

test/contentype_test.js

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +0,0 @@
1-
import { TLSPlaintext } from "../src/contentype.js";
2-
import { ContentType } from "../src/contentype.js";
3-
import { HexaDecimal } from "../src/dep.ts";
4-
5-
const data = Uint8Array.of(22,3,3,0,90,2,0,0,86,3,3,228,44,20,180,246,26,219,188,122,213,217,251,41,50,155,92,116,81,250,39,242,191,183,76,171,149,171,114,12,38,251,125,0,19,1,0,0,46,0,51,0,36,0,29,0,32,72,219,7,104,122,209,174,22,1,246,130,27,135,6,145,132,226,105,143,24,65,0,64,40,1,55,237,193,144,208,141,16,0,43,0,2,3,4,20,3,3,0,1,1,23,3,3,16,245,139,23,30,56,24,105,181,235,87,121,171,236,209,141,199,14,135,3,85,199,189,77,183,193,102,9,201,106,174,88,54,164,130,10,171,247,110,213,114,194,69,11,19,132,66,116,23,235,134,13,192,238,41,136,126,213,177,46,133,155,80,149,194,11,217,40,203,81,52,35,128,247,59,52,46,237,31,110,210,36,135,193,101,228,135,67,93,117,46,166,45,163,236,109,132,77,110,114,14,234,82,165,251,190,251,157,29,32,33,66,42,63,162,239,6,12,231,213,78,205,179,45,11,171,151,202,224,244,141,132,118,252,198,64,222,156,207,23,201,249,147,151,137,177,3,84,23,105,231,87,51,120,112,254,95,22,226,95,138,238,101,27,224,169,64,75,236,122,20,151,125,128,68,167,117,127,171,166,137,179,68,185,243,229,198,220,248,201,121,109,14,236,54,230,34,152,24,53,131,140,47,40,199,37,52,159,69,186,22,134,72,131,41,243,77,34,211,16,59,38,225,116,169,100,65,120,14,170,250,159,176,197,185,207,210,51,120,230,135,133,50,214,46,45,250,251,220,61,18,238,74,70,97,134,50,153,19,87,37,137,206,250,125,180,171,157,34,178,114,199,110,242,223,90,248,245,101,239,111,196,246,194,193,121,31,91,91,29,176,198,255,183,69,39,55,39,243,148,174,167,252,4,193,3,83,64,132,2,99,65,142,100,147,165,87,168,175,34,206,137,90,49,176,2,194,169,43,102,127,209,136,175,34,243,1,150,152,176,231,153,37,205,143,242,203,99,91,197,20,235,205,60,208,75,183,33,196,117,29,101,166,184,34,198,1,140,132,209,219,235,187,150,211,188,199,42,49,14,109,183,7,191,71,16,177,60,117,91,241,81,188,153,182,48,214,191,114,7,98,199,54,153,186,171,100,252,112,141,143,162,151,185,17,235,185,119,253,80,246,168,111,73,29,140,43,103,98,209,48,210,0,235,120,213,103,28,26,50,161,195,108,37,56,68,85,46,253,225,107,176,234,134,153,236,116,12,213,140,137,88,218,7,19,189,128,175,211,247,143,158,71,184,172,65,182,29,16,10,203,67,237,204,168,57,177,45,3,244,161,31,211,30,151,231,48,77,25,34,212,122,22,190,65,104,58,54,28,65,103,255,116,117,147,234,166,125,0,70,145,2,162,254,79,102,220,208,255,159,48,226,177,174,132,203,121,211,250,5,205,39,46,229,63,100,153,170,126,164,200,105,227,179,93,106,183,175,188,153,12,93,65,112,74,209,224,203,144,236,147,54,213,120,136,176,160,44,219,85,29,17,228,99,32,46,183,183,190,210,42,79,111,96,38,165,137,96,249,38,113,86,94,159,102,252,9,27,134,17,123,165,7,145,123,157,255,10,129,159,139,45,92,235,72,162,244,153,11,91,236,216,44,162,212,225,146,235,33,9,185,212,160,9,75,71,240,238,128,177,121,130,109,246,26,113,195,192,226,225,29,140,153,193,119,124,73,21,10,243,203,145,20,228,87,162,224,173,255,136,74,2,221,45,221,70,239,152,59,207,51,134,222,208,92,116,17,97,140,102,166,48,173,17,49,98,124,100,172,220,94,31,205,15,56,163,6,250,195,133,203,222,60,5,9,95,48,103,64,47,219,208,163,86,205,242,120,255,208,112,189,217,38,185,60,221,73,182,99,123,39,174,168,67,96,1,247,102,104,167,222,191,205,4,6,81,255,196,147,179,84,30,46,40,236,112,190,151,102,122,165,117,222,37,136,72,33,159,126,87,88,137,103,180,105,169,139,46,190,91,77,118,71,155,228,227,134,202,128,168,198,229,229,227,125,99,97,52,10,135,60,26,143,107,156,29,175,186,47,91,53,31,121,124,116,254,28,87,88,83,49,161,19,81,34,16,61,185,142,6,216,0,40,140,68,169,180,204,56,124,103,218,118,36,44,157,255,226,56,123,194,235,47,165,148,46,94,134,227,112,153,114,68,191,150,209,209,196,90,158,126,5,80,134,61,137,34,62,95,132,56,13,179,88,53,131,207,123,107,175,76,53,65,77,88,84,122,193,130,54,184,135,43,144,152,67,17,96,166,93,163,87,177,166,26,156,49,232,205,44,188,244,144,32,74,189,97,37,50,173,42,37,181,27,121,155,129,254,61,46,71,95,9,18,179,208,187,147,63,48,228,177,60,155,199,109,216,7,87,225,108,12,141,76,239,97,113,169,189,29,245,104,200,203,71,109,7,108,240,17,234,34,214,50,142,11,57,146,158,162,160,189,163,107,246,140,141,194,155,197,239,249,96,136,19,189,243,62,251,107,117,38,24,14,253,5,91,153,70,26,41,6,145,10,192,77,187,236,114,80,179,23,31,92,123,67,189,246,206,194,173,43,24,169,106,115,121,206,120,126,191,30,136,60,244,29,109,242,16,140,146,124,161,61,138,244,20,126,174,177,209,39,119,169,100,24,96,8,100,5,169,27,130,209,68,209,8,208,150,100,224,137,192,197,120,113,151,88,179,36,76,220,89,57,136,240,222,202,212,116,48,146,189,155,37,214,244,168,216,104,114,63,130,118,48,110,209,83,46,203,33,168,4,72,243,175,201,17,152,162,15,128,14,156,247,209,80,172,41,111,135,133,176,212,233,203,157,86,203,71,141,8,62,31,229,216,190,95,234,224,252,213,217,197,114,141,96,6,247,92,17,163,166,80,177,227,161,203,24,110,103,147,117,30,201,34,181,35,103,13,189,172,138,200,38,47,203,141,84,18,38,42,29,2,164,169,69,94,96,248,35,17,111,99,1,179,221,119,60,95,30,125,115,70,55,210,172,225,188,179,239,254,226,39,254,68,88,144,233,153,101,95,87,62,134,198,158,152,216,140,244,4,166,180,253,234,0,66,144,40,40,202,90,123,50,201,42,48,234,48,9,18,216,36,47,183,227,181,202,253,229,226,94,123,101,34,21,251,120,50,240,160,201,112,173,76,225,155,123,37,178,180,59,1,214,101,45,97,185,220,57,146,8,69,31,75,191,76,147,141,183,31,210,53,13,157,198,46,17,112,129,153,173,201,39,255,171,21,68,146,112,65,15,252,232,103,140,109,154,173,209,242,110,230,69,138,5,204,37,179,254,88,190,127,92,173,145,174,42,9,26,9,239,112,16,158,113,35,25,203,159,4,192,55,242,163,163,159,39,157,143,4,164,16,173,3,182,185,223,195,125,227,108,188,115,35,160,76,240,29,25,229,226,111,4,184,34,13,75,242,101,130,7,122,87,126,208,148,239,121,206,162,173,40,148,248,117,114,139,38,234,8,169,95,142,78,194,238,75,101,131,145,23,61,230,120,154,140,215,3,43,214,147,236,5,100,211,35,44,106,49,172,116,43,179,89,236,21,46,250,165,200,137,166,206,24,206,251,52,53,240,93,255,58,135,122,118,186,213,240,107,14,51,46,55,157,81,207,3,229,31,223,60,248,139,112,255,22,28,145,143,144,104,35,187,86,107,150,228,8,133,222,80,198,235,109,243,100,186,6,33,139,124,199,49,98,166,124,17,122,150,220,240,12,246,172,76,14,111,252,212,161,19,118,189,122,128,163,14,152,139,219,28,28,188,250,100,89,81,49,84,128,141,117,95,213,138,92,68,227,165,1,99,134,87,1,22,45,0,163,234,181,202,83,40,83,255,87,207,146,45,49,59,110,190,215,250,148,151,162,163,236,158,102,219,91,218,41,203,51,143,155,12,19,118,1,94,184,240,58,50,8,251,235,240,179,203,146,192,146,157,101,26,179,94,249,191,246,221,159,55,29,180,9,146,220,85,229,119,132,30,32,239,152,35,173,198,48,112,58,124,6,190,253,182,173,81,146,161,242,182,121,156,97,80,150,195,0,62,134,80,147,49,110,197,56,33,39,41,248,251,194,33,167,246,141,87,200,190,146,95,242,32,123,214,235,77,173,46,114,120,171,132,245,49,248,195,166,22,172,141,163,158,31,165,84,1,235,249,120,81,231,23,110,13,128,211,61,131,219,219,92,88,202,217,221,159,39,211,64,72,68,41,34,185,10,122,23,84,0,236,16,163,20,167,90,205,243,145,11,89,56,77,158,45,105,51,224,186,104,92,191,129,191,59,57,1,225,189,18,72,72,37,38,165,45,107,26,242,70,248,17,86,220,252,149,64,201,42,104,89,129,35,94,232,51,103,205,78,90,91,94,111,201,127,50,109,109,18,113,138,242,59,211,4,13,199,173,3,255,69,66,162,254,128,62,252,165,175,221,185,224,119,36,229,178,199,120,178,53,188,45,52,102,44,136,165,194,89,115,154,149,70,27,137,177,190,240,34,132,105,172,57,32,6,10,141,94,122,78,236,99,150,144,59,234,239,208,161,23,227,234,225,208,242,49,55,94,135,224,144,171,12,205,206,72,200,12,88,126,141,237,50,65,200,131,220,8,199,77,162,129,6,232,242,81,17,114,157,67,31,25,213,234,35,44,106,116,176,170,55,18,168,96,171,164,99,229,4,129,56,237,188,59,150,107,102,64,44,63,68,94,191,53,74,199,64,192,24,21,124,154,199,200,80,177,156,49,35,67,239,98,246,89,214,111,144,168,185,10,117,45,168,252,228,73,233,60,95,27,50,17,118,179,116,170,76,55,39,67,54,73,71,71,9,167,245,220,109,76,244,157,218,96,43,21,166,141,89,14,127,162,76,74,88,134,83,183,99,124,39,9,237,28,201,185,208,38,125,6,86,67,206,165,190,40,140,158,135,129,120,192,63,82,37,254,155,76,158,64,141,29,157,177,156,248,232,137,101,169,164,157,5,102,96,43,253,159,109,64,180,118,125,216,85,49,2,42,0,251,185,17,198,108,51,80,139,215,22,163,239,191,140,230,190,81,144,107,213,206,89,46,48,178,83,175,216,233,86,96,29,60,114,95,97,56,202,233,20,38,128,164,214,206,5,230,51,148,43,193,214,228,177,232,167,37,204,128,64,141,203,189,78,169,64,169,147,244,4,151,84,178,227,126,17,176,91,7,224,129,59,123,150,176,58,231,17,235,176,39,221,99,212,252,195,27,248,242,205,86,169,113,205,117,7,84,233,216,174,200,141,232,219,209,96,194,28,8,168,75,63,196,178,137,229,180,216,129,60,78,138,247,111,39,246,132,248,180,208,42,54,176,172,109,211,109,20,131,175,64,183,13,68,79,49,191,36,45,190,64,255,148,230,84,158,232,21,206,202,210,23,105,201,226,82,192,17,228,65,117,215,177,222,56,169,40,159,99,133,210,84,58,214,177,54,249,104,99,146,64,40,234,157,87,78,169,45,201,162,198,150,84,160,173,17,34,83,224,21,223,206,228,193,146,53,26,255,118,169,208,173,254,40,20,177,75,218,54,24,203,211,169,202,212,96,212,81,84,225,17,163,132,173,58,32,61,162,20,247,206,10,25,11,82,65,182,24,229,27,130,208,32,168,203,243,58,245,165,114,136,167,229,129,14,77,54,149,196,4,65,22,232,22,187,202,48,220,85,192,37,155,68,226,114,226,212,79,249,129,126,190,253,194,175,139,19,246,203,105,46,153,82,79,0,104,29,69,52,95,36,132,67,90,189,88,104,49,38,104,109,113,154,179,134,244,149,119,17,209,31,17,246,166,170,198,70,153,241,172,89,150,148,209,61,150,81,226,102,3,62,74,86,136,34,162,238,169,99,253,96,161,31,133,78,223,142,6,3,43,113,34,121,148,196,151,210,140,128,29,41,118,111,60,118,74,225,13,160,239,219,230,161,104,2,34,34,0,60,182,88,222,58,241,140,54,162,144,65,100,197,36,151,152,214,45,241,228,77,217,150,141,34,13,112,152,127,158,124,223,42,223,246,54,235,30,120,146,71,71,58,134,196,88,134,60,144,166,33,220,122,37,118,4,197,7,224,162,27,246,183,106,156,253,63,200,225,214,251,146,181,234,197,150,11,117,200,74,195,11,98,137,217,204,200,214,27,84,224,163,163,212,102,190,233,239,10,104,212,204,199,82,12,115,189,208,126,63,37,184,134,250,90,208,67,31,163,63,213,198,184,215,178,111,228,96,94,14,148,202,43,201,108,146,232,227,243,15,184,143,241);
6-
7-
const records = new Set
8-
let offset = 0;
9-
while(true){
10-
const record = TLSPlaintext.from(data.subarray(offset));offset+=record.length
11-
records.add(record);
12-
if(offset>=data.length)break;
13-
}
14-
15-
debugger;

test/handshaketype_test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ for (const e of codes) {
1212

1313
const eoData = new EndOfEarlyData;
1414
const eoDataHandshake = eoData.handshake;
15-
const eoDataTlsInnerPlaintext = eoDataHandshake.tlsInnerPlaintext();
15+
1616

1717

0 commit comments

Comments
 (0)