Skip to content

Commit 7117a39

Browse files
committed
add SignatureSchemeList
1 parent 6152389 commit 7117a39

File tree

6 files changed

+77
-5
lines changed

6 files changed

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

src/namedgroup.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,9 +180,9 @@ export class NamedGroupList extends Constrained {
180180
}
181181
return new NamedGroupList(...namedGroups)
182182
}
183-
constructor(...namedGroups){
184-
super(2, 2**16-1, ...namedGroups.map(e=>e.Uint16));
185-
this.namedGroups = namedGroups
183+
constructor(...named_group_list){
184+
super(2, 2**16-1, ...named_group_list.map(e=>e.Uint16));
185+
this.named_group_list = named_group_list
186186
}
187187
}
188188

src/signaturescheme.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,25 @@ export class SignatureScheme extends Enum {
117117
}
118118
}
119119

120+
export class SignatureSchemeList extends Constrained {
121+
static from(array){
122+
const copy = Uint8Array.from(array);
123+
const lengthOf = Uint16.from(copy).value;
124+
const algorithms = new Set;
125+
let offset = 2;
126+
while(true){
127+
const algorithm = SignatureScheme.from(copy.subarray(offset));offset+=2;
128+
algorithms.add(algorithm);
129+
if(offset>=lengthOf+2)break;
130+
}
131+
return new SignatureSchemeList(...algorithms)
132+
}
133+
constructor(...supported_signature_algorithms) {
134+
super(2, 2 ** 16 - 2, ...supported_signature_algorithms.map(e => e.Uint16))
135+
this.supported_signature_algorithms = supported_signature_algorithms;
136+
}
137+
}
138+
120139
export class CertificateVerify extends Uint8Array {
121140
static fromMsg(array) {
122141
const copy = Uint8Array.from(array)

test/signaturescheme_test.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { SignatureScheme, CertificateVerify, finished, Finished } from "../src/s
22
import { assertEquals } from "jsr:@std/assert";
33
import { HexaDecimal, sha256 } from "../src/dep.ts";
44
import { HandshakeType } from "../src/handshaketype.js"
5+
import { SignatureSchemeList } from "../src/signaturescheme.js";
56

67
console.log(SignatureScheme.ED448);
78

@@ -18,6 +19,17 @@ Deno.test("SignatureAlgorithmSchema", () => {
1819
assertEquals(test, back)
1920
})
2021

22+
Deno.test("SignatureSchemeList", ()=>{
23+
const test = new SignatureSchemeList(
24+
SignatureScheme.RSA_PSS_RSAE_SHA256,
25+
SignatureScheme.RSA_PSS_RSAE_SHA384
26+
)
27+
28+
const back = SignatureSchemeList.from(test);
29+
assertEquals(test.toString(), back.toString())
30+
})
31+
32+
2133
const clientHelloMsg = HexaDecimal.fromString(
2234
`01 00 00 c0 03 03 cb 34 ec b1 e7 81 63
2335
ba 1c 38 c6 da cb 19 6a 6d ff a2 1a 8d 99 12 ec 18 a2 ef 62 83
@@ -122,7 +134,6 @@ const finished_key = HexaDecimal.fromString(
122134
const finished_0 = await finished(finished_key, 256, clientHelloMsg, serverHelloMsg, encryptedExtensionsMsg, certificateMsg);
123135

124136

125-
debugger;
126137

127138

128139

type/namedgroup.d.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,23 @@ export class KeyShareEntry extends Struct {
142142
/** The key exchange octet. */
143143
key_exchange: Uint8Array;
144144
}
145+
146+
export class NamedGroupList extends Constrained {
147+
/**
148+
* Parses a NamedGroupList from a Uint8Array.
149+
* @param array - The input array containing named groups data.
150+
* @returns A new instance of NamedGroupList.
151+
*/
152+
static from(array: Uint8Array): NamedGroupList;
153+
154+
/**
155+
* Constructs a NamedGroupList.
156+
* @param named_group_list - A list of NamedGroup instances.
157+
*/
158+
constructor(...named_group_list: NamedGroup[]);
159+
160+
/**
161+
* The list of named groups.
162+
*/
163+
readonly named_group_list: NamedGroup[];
164+
}

type/signaturescheme.d.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,25 @@ export declare class Finished extends Uint8Array {
131131
constructor(verify_data: Uint8Array);
132132
verify_data: Uint8Array;
133133
}
134+
135+
export declare class SignatureSchemeList extends Constrained {
136+
/**
137+
* Parses a `SignatureSchemeList` from a `Uint8Array`.
138+
* @param array - The input array containing signature schemes data.
139+
* @returns A new instance of `SignatureSchemeList`.
140+
* @throws {Error} If the input array is invalid or incomplete.
141+
*/
142+
static from(array: Uint8Array): SignatureSchemeList;
143+
144+
/**
145+
* Constructs a `SignatureSchemeList`.
146+
* @param supported_signature_algorithms - A list of supported signature schemes.
147+
* @throws {Error} If the constraints are not satisfied.
148+
*/
149+
constructor(...supported_signature_algorithms: SignatureScheme[]);
150+
151+
/**
152+
* The list of supported signature schemes.
153+
*/
154+
readonly supported_signature_algorithms: SignatureScheme[];
155+
}

0 commit comments

Comments
 (0)