Skip to content

Commit 6152389

Browse files
committed
add NamedGroupList
1 parent 20382b5 commit 6152389

File tree

3 files changed

+25
-14
lines changed

3 files changed

+25
-14
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.5.6",
3+
"version": "0.5.7",
44
"exports": "./src/mod.ts",
55
"publish": {
66
"exclude": ["dist/"]

src/namedgroup.js

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,24 @@ export class KeyShareEntry extends Struct {
167167
}
168168
}
169169

170-
170+
export class NamedGroupList extends Constrained {
171+
static from(array){
172+
const copy = Uint8Array.from(array);
173+
const lengthOf = Uint16.from(copy).value;
174+
const namedGroups = new Set;
175+
let offset = 2;
176+
while(true){
177+
const namedgroup = NamedGroup.from(copy.subarray(offset));offset+=2;
178+
namedGroups.add(namedgroup);
179+
if(offset>=lengthOf+2)break;
180+
}
181+
return new NamedGroupList(...namedGroups)
182+
}
183+
constructor(...namedGroups){
184+
super(2, 2**16-1, ...namedGroups.map(e=>e.Uint16));
185+
this.namedGroups = namedGroups
186+
}
187+
}
171188

172189

173190

test/namedgroup_test.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { assertEquals } from "jsr:@std/assert";
2-
import { NamedGroup } from "../src/namedgroup.js";
2+
import { NamedGroup, NamedGroupList } from "../src/namedgroup.js";
33

44
Deno.test(
55
"NamedGroup",
@@ -19,15 +19,9 @@ Deno.test(
1919
}
2020
)
2121

22-
//const x25519 = NamedGroup.X25519.keyShareEntry();
2322

24-
const x25519 = NamedGroup.X25519;
25-
assertEquals(x25519.name, 'X25519')
26-
const pub = x25519.keyGen.getPublicKey(x25519.privateKey);
27-
assertEquals(pub.length, 32)
28-
const peerPublicKey = crypto.getRandomValues(new Uint8Array(32));
29-
assertEquals(peerPublicKey.length, 32)
30-
const sharedKey = x25519.getSharedKey(peerPublicKey)
31-
assertEquals(sharedKey.length, 32)
32-
33-
debugger;
23+
Deno.test("NamedGroupList", () => {
24+
const namedGroupList = new NamedGroupList(NamedGroup.X25519, NamedGroup.X448);
25+
const backNGL = NamedGroupList.from(namedGroupList);
26+
assertEquals(namedGroupList.toString(), backNGL.toString())
27+
})

0 commit comments

Comments
 (0)