Skip to content

Commit 42b4696

Browse files
committed
revise EncryptedExtension
1 parent 93254b7 commit 42b4696

File tree

4 files changed

+41
-19
lines changed

4 files changed

+41
-19
lines changed

deno.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tls/param",
3-
"version": "0.1.7",
3+
"version": "0.1.8",
44
"exports": "./src/mod.ts",
55
"publish": {
66
"exclude": ["dist/"]
@@ -14,8 +14,8 @@
1414
},
1515
"imports": {
1616
"@std/assert": "jsr:@std/assert@^1.0.2",
17-
"@tls/enum": "jsr:@tls/enum@^0.6.5",
17+
"@tls/enum": "jsr:@tls/enum@^0.6.6",
1818
"@tls/extension": "jsr:@tls/extension@^0.2.9",
19-
"@tls/struct": "jsr:@tls/struct@^0.3.6"
19+
"@tls/struct": "jsr:@tls/struct@^0.3.7"
2020
}
2121
}

deno.lock

Lines changed: 19 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/encrypted.js

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// deno-lint-ignore-file no-slow-types
22
// @ts-self-types="../type/encrypted.d.ts"
33
import { ContentType, HandshakeType } from "./dep.ts";
4-
import { Uint16, Constrained, Uint24 } from "./dep.ts";
4+
import { Uint16, Constrained, Uint24, parseItems } from "./dep.ts";
55
import {
66
Extension, ExtensionType,
77
NamedGroupList, RecordSizeLimit,
@@ -19,16 +19,19 @@ export class EncryptedExtensions extends Constrained {
1919
ext = new Set;
2020
static fromExtensions(...extensions) { return new EncryptedExtensions(...extensions) }
2121
static fromHandshake(array) {
22-
const copy = array.slice();
23-
const _type = HandshakeType.from(copy);
24-
const _lengthOf = Uint24.from(copy.subarray(1)).value;
22+
const copy = Uint8Array.from(array);
23+
const type = HandshakeType.from(copy);
24+
if (type !== HandshakeType.ENCRYPTED_EXTENSIONS) return TypeError(`Expected EncryptedExtension`)
25+
const lengthOf = Uint24.from(copy.subarray(1)).value;
26+
if (lengthOf == 2) return new EncryptedExtensions
2527
return EncryptedExtensions.from(copy.subarray(4))
2628
}
2729
static from(array) {
2830
const copy = Uint8Array.from(array)
29-
if (copy.length == 0) return new EncryptedExtensions
30-
const extensions = Extensions.from(copy.subarray());
31-
return new EncryptedExtensions(...extensions.extensions)
31+
const lengthOf = Uint16.from(copy).value;
32+
if (lengthOf == 0) return new EncryptedExtensions
33+
const extensions = parseItems(copy, 2, lengthOf, Extension);//_Extensions.from(copy.subarray());
34+
return new EncryptedExtensions(...extensions)
3235
}
3336

3437
constructor(...extensions) {
@@ -45,22 +48,22 @@ export class EncryptedExtensions extends Constrained {
4548
}
4649
}
4750

48-
class Extensions extends Constrained {
49-
static fromExtension(...extensions) { return new Extensions(...extensions) }
51+
class _Extensions extends Constrained {
52+
static fromExtension(...extensions) { return new _Extensions(...extensions) }
5053
static from(array) {
5154
const copy = Uint8Array.from(array);
5255
const _lengthOf = Uint16.from(copy).value;
5356
const extensions = [];
5457
let offset = 2;
5558
//for (let offset = 2; offset < lengthOf + 2;) {
56-
//if (offset > copy.length - 2) break;
57-
while(true){
59+
//if (offset > copy.length - 2) break;
60+
while (true) {
5861
const extension = Extension.from(copy.subarray(offset)); offset += extension.length
5962
parseExtension(extension);
6063
extensions.push(extension)
6164
if (offset >= copy.length - 2) break;
6265
}
63-
return new Extensions(...extensions)
66+
return new _Extensions(...extensions)
6467
}
6568
constructor(...extensions) {
6669
super(0, 2 ** 16 - 1, ...extensions)

test/encryptedext_test.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,9 @@ const encryptedExtensionMsg = HexaDecimal.fromString(`08 00 00 28 00 26 00 0a 00
1818

1919
const back = EncryptedExtensions.fromHandshake(encryptedExtensionMsg).handshake;
2020

21+
const test = Uint8Array.of(8,0,0,2,0,0);
22+
const back_0 = EncryptedExtensions.fromHandshake(test);
23+
const back_1 = EncryptedExtensions.from(test.subarray(4))
24+
2125
const _n = null;
2226

0 commit comments

Comments
 (0)