Skip to content

Commit df8d559

Browse files
committed
add length to Version
1 parent ae39ca0 commit df8d559

File tree

8 files changed

+132
-248
lines changed

8 files changed

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

src/namedgroup.js

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -169,19 +169,5 @@ export class KeyShareEntry extends Struct {
169169
}
170170
}
171171

172-
export class NamedGroupList extends Constrained {
173-
static from(array){
174-
const copy = Uint8Array.from(array);
175-
const lengthOf = Uint16.from(copy).value;
176-
const namedGroups = parseItems(copy, 2, lengthOf, NamedGroup)
177-
return new NamedGroupList(...namedGroups)
178-
}
179-
constructor(...named_group_list){
180-
super(2, 2**16-1, ...named_group_list.map(e=>e.Uint16));
181-
this.named_group_list = named_group_list
182-
}
183-
}
184-
185-
186172

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

src/pskmode.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,19 +39,6 @@ export class PskKeyExchangeMode extends Enum {
3939

4040
}
4141

42-
export class PskKeyExchangeModes extends Constrained {
43-
static from(array){
44-
const copy = Uint8Array.from(array);
45-
const lengthOf = Uint8.from(copy).value;
46-
const ke_modes = parseItems(copy, 1, lengthOf, PskKeyExchangeMode);
47-
return new PskKeyExchangeModes(...ke_modes)
48-
}
49-
constructor(...ke_modes) {
50-
super(1, 255, ...ke_modes.map(e => e.Uint8))
51-
this.ke_modes = ke_modes;
52-
}
53-
}
54-
5542
/* const test = new PskKeyExchangeModes(PskKeyExchangeMode.PSK_KE);
5643
const back = PskKeyExchangeModes.from(test); */
5744

src/signaturescheme.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -119,19 +119,6 @@ export class SignatureScheme extends Enum {
119119
}
120120
}
121121

122-
export class SignatureSchemeList extends Constrained {
123-
static from(array){
124-
const copy = Uint8Array.from(array);
125-
const lengthOf = Uint16.from(copy).value;
126-
const algorithms = parseItems(copy, 2, lengthOf, SignatureScheme);
127-
return new SignatureSchemeList(...algorithms)
128-
}
129-
constructor(...supported_signature_algorithms) {
130-
super(2, 2 ** 16 - 2, ...supported_signature_algorithms.map(e => e.Uint16))
131-
this.supported_signature_algorithms = supported_signature_algorithms;
132-
}
133-
}
134-
135122
export class CertificateVerify extends Uint8Array {
136123
static fromMsg(array) {
137124
const copy = Uint8Array.from(array)

src/version.js

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export class Version extends Enum {
6868
* @returns {number} - The bit size of the version.
6969
*/
7070
get bit() { return 16 }
71+
get length(){ return 2 }
7172

7273
get Uint16() { return Uint16.fromValue(+this); }
7374

@@ -125,17 +126,4 @@ export class ProtocolVersion extends Uint8Array {
125126
}
126127
}
127128

128-
export class Versions extends Constrained {
129-
static from(array){
130-
const copy = Uint8Array.from(array);
131-
const lengthOf = Uint16.from(copy).value;
132-
const versions = parseItems(copy, 2, lengthOf, Version)
133-
return new Versions(...versions)
134-
}
135-
constructor(...versions){
136-
super(2, 254, ...versions.map(e=>e.Uint16));
137-
this.versions = versions
138-
}
139-
}
140-
141129
// npx -p typescript tsc ./src/version.js --declaration --allowJs --emitDeclarationOnly --lib ESNext --outDir ./dist

type/namedgroup.d.ts

Lines changed: 130 additions & 151 deletions
Original file line numberDiff line numberDiff line change
@@ -1,169 +1,148 @@
11
import { Enum } from "./enum.d.ts";
2-
import { Uint16, Constrained, Struct } from "../src/dep.ts";
2+
import { Constrained, Struct, Uint16 } from "../src/dep.ts";
33
/**
44
* Supported groups - @see https://datatracker.ietf.org/doc/html/rfc8446#section-4.2.7.
55
*/
66
export class NamedGroup extends Enum {
7-
static SECP256R1: NamedGroup;
8-
static SECP384R1: NamedGroup;
9-
static SECP521R1: NamedGroup;
10-
static X25519: NamedGroup;
11-
static X448: NamedGroup;
12-
static FFDHE2048: NamedGroup;
13-
static FFDHE3072: NamedGroup;
14-
static FFDHE4096: NamedGroup;
15-
static FFDHE6144: NamedGroup;
16-
static FFDHE8192: NamedGroup;
17-
18-
/**
19-
* Parses an octet array and returns a valid NamedGroup.
20-
*
21-
* @static
22-
* @param {Uint8Array} octet - The octet array to parse.
23-
* @returns {NamedGroup} The corresponding NamedGroup instance.
24-
* @throws {Error} If the octet does not correspond to a known NamedGroup.
25-
*/
26-
static from(octet: Uint8Array): NamedGroup;
27-
28-
/**
29-
* Returns the bit length of the NamedGroup.
30-
* @returns {number} The bit length, which is always 16.
31-
*/
32-
get bit(): number;
33-
/**
34-
* Returns the byte length
35-
* @returns {number} The byte length, which is always 2.
36-
*/
37-
get length(): number;
38-
39-
/**
40-
* Creates an instance of NamedGroup.
41-
*
42-
* @param {string} name - The name of the NamedGroup.
43-
* @param {number} value - The value associated with the NamedGroup.
44-
*/
45-
constructor(name: string, value: number);
46-
47-
/**
48-
* Converts the NamedGroup to a Uint16 representation.
49-
*
50-
* @returns {Uint16} The Uint16 representation of the NamedGroup.
51-
*/
52-
get Uint16(): Uint16;
53-
54-
/**
55-
* Gets the key generation algorithm associated with the NamedGroup.
56-
*
57-
* @returns {Function} The key generation function.
58-
*/
59-
get keyGen(): Function;
60-
61-
/**
62-
* Gets the private key associated with the NamedGroup.
63-
*
64-
* @returns {Uint8Array} The private key.
65-
*/
66-
get privateKey(): Uint8Array;
67-
68-
/** Sets the private key associated with the NamedGroup. */
69-
set privateKey(key : Uint8Array);
70-
71-
/**
72-
* Gets the public key associated with the NamedGroup.
73-
*
74-
* @returns {Uint8Array} The public key.
75-
*/
76-
get publicKey(): Uint8Array;
77-
78-
79-
/** Sets the public key associated with the NamedGroup. */
80-
set publicKey(key : Uint8Array);
81-
82-
/**
83-
* Computes the shared key with a peer's public key.
84-
*
85-
* @param {Uint8Array} peerPublicKey - The public key of the peer.
86-
* @returns {Uint8Array} The shared secret.
87-
*/
88-
getSharedKey(peerPublicKey: Uint8Array): Uint8Array;
89-
90-
/**
91-
* Creates a key share entry from the NamedGroup.
92-
*
93-
* @returns {KeyShareEntry} A new KeyShareEntry instance.
94-
*/
95-
keyShareEntry(): KeyShareEntry;
7+
static SECP256R1: NamedGroup;
8+
static SECP384R1: NamedGroup;
9+
static SECP521R1: NamedGroup;
10+
static X25519: NamedGroup;
11+
static X448: NamedGroup;
12+
static FFDHE2048: NamedGroup;
13+
static FFDHE3072: NamedGroup;
14+
static FFDHE4096: NamedGroup;
15+
static FFDHE6144: NamedGroup;
16+
static FFDHE8192: NamedGroup;
17+
18+
/**
19+
* Parses an octet array and returns a valid NamedGroup.
20+
*
21+
* @static
22+
* @param {Uint8Array} octet - The octet array to parse.
23+
* @returns {NamedGroup} The corresponding NamedGroup instance.
24+
* @throws {Error} If the octet does not correspond to a known NamedGroup.
25+
*/
26+
static from(octet: Uint8Array): NamedGroup;
27+
28+
/**
29+
* Returns the bit length of the NamedGroup.
30+
* @returns {number} The bit length, which is always 16.
31+
*/
32+
get bit(): number;
33+
/**
34+
* Returns the byte length
35+
* @returns {number} The byte length, which is always 2.
36+
*/
37+
get length(): number;
38+
39+
/**
40+
* Creates an instance of NamedGroup.
41+
*
42+
* @param {string} name - The name of the NamedGroup.
43+
* @param {number} value - The value associated with the NamedGroup.
44+
*/
45+
constructor(name: string, value: number);
46+
47+
/**
48+
* Converts the NamedGroup to a Uint16 representation.
49+
*
50+
* @returns {Uint16} The Uint16 representation of the NamedGroup.
51+
*/
52+
get Uint16(): Uint16;
53+
54+
/**
55+
* Gets the key generation algorithm associated with the NamedGroup.
56+
*
57+
* @returns {Function} The key generation function.
58+
*/
59+
get keyGen(): Function;
60+
61+
/**
62+
* Gets the private key associated with the NamedGroup.
63+
*
64+
* @returns {Uint8Array} The private key.
65+
*/
66+
get privateKey(): Uint8Array;
67+
68+
/** Sets the private key associated with the NamedGroup. */
69+
set privateKey(key: Uint8Array);
70+
71+
/**
72+
* Gets the public key associated with the NamedGroup.
73+
*
74+
* @returns {Uint8Array} The public key.
75+
*/
76+
get publicKey(): Uint8Array;
77+
78+
/** Sets the public key associated with the NamedGroup. */
79+
set publicKey(key: Uint8Array);
80+
81+
/**
82+
* Computes the shared key with a peer's public key.
83+
*
84+
* @param {Uint8Array} peerPublicKey - The public key of the peer.
85+
* @returns {Uint8Array} The shared secret.
86+
*/
87+
getSharedKey(peerPublicKey: Uint8Array): Uint8Array;
88+
89+
/**
90+
* Creates a key share entry from the NamedGroup.
91+
*
92+
* @returns {KeyShareEntry} A new KeyShareEntry instance.
93+
*/
94+
keyShareEntry(): KeyShareEntry;
9695
}
9796

9897
/**
9998
* Represents a key exchange mechanism.
10099
*/
101100
export class KeyExchange extends Constrained {
102-
/**
103-
* Creates a KeyExchange from an octet array.
104-
* @param {Uint8Array} octet - The octet array.
105-
* @returns {KeyExchange} A KeyExchange instance.
106-
*/
107-
static fromKey(octet: Uint8Array): KeyExchange;
108-
109-
/**
110-
* Creates a KeyExchange from a Uint8Array.
111-
* @param {Uint8Array} array - The input byte array.
112-
* @returns {KeyExchange} A KeyExchange instance.
113-
*/
114-
static from(array: Uint8Array): KeyExchange;
115-
116-
/**
117-
* Constructs a KeyExchange instance.
118-
* @param {Uint8Array} octet - The octet array representing the key exchange.
119-
*/
120-
constructor(octet: Uint8Array);
121-
122-
/** The key exchange octet. */
123-
key_exchange: Uint8Array;
101+
/**
102+
* Creates a KeyExchange from an octet array.
103+
* @param {Uint8Array} octet - The octet array.
104+
* @returns {KeyExchange} A KeyExchange instance.
105+
*/
106+
static fromKey(octet: Uint8Array): KeyExchange;
107+
108+
/**
109+
* Creates a KeyExchange from a Uint8Array.
110+
* @param {Uint8Array} array - The input byte array.
111+
* @returns {KeyExchange} A KeyExchange instance.
112+
*/
113+
static from(array: Uint8Array): KeyExchange;
114+
115+
/**
116+
* Constructs a KeyExchange instance.
117+
* @param {Uint8Array} octet - The octet array representing the key exchange.
118+
*/
119+
constructor(octet: Uint8Array);
120+
121+
/** The key exchange octet. */
122+
key_exchange: Uint8Array;
124123
}
125124

126125
/**
127126
* Represents a key share entry in TLS handshake.
128127
*/
129128
export class KeyShareEntry extends Struct {
130-
/**
131-
* Creates a KeyShareEntry from a Uint8Array.
132-
* @param {Uint8Array} array - The input byte array.
133-
* @returns {KeyShareEntry} A KeyShareEntry instance.
134-
*/
135-
static from(array: Uint8Array): KeyShareEntry;
136-
137-
/**
138-
* Constructs a KeyShareEntry instance.
139-
* @param {NamedGroup} group - The NamedGroup for the key share.
140-
* @param {KeyExchange} key_exchange - The KeyExchange for the key share.
141-
*/
142-
constructor(group: NamedGroup, key_exchange: KeyExchange);
143-
144-
/** The NamedGroup for the key share. */
145-
group: NamedGroup;
146-
147-
/** The key exchange octet. */
148-
key_exchange: Uint8Array;
129+
/**
130+
* Creates a KeyShareEntry from a Uint8Array.
131+
* @param {Uint8Array} array - The input byte array.
132+
* @returns {KeyShareEntry} A KeyShareEntry instance.
133+
*/
134+
static from(array: Uint8Array): KeyShareEntry;
135+
136+
/**
137+
* Constructs a KeyShareEntry instance.
138+
* @param {NamedGroup} group - The NamedGroup for the key share.
139+
* @param {KeyExchange} key_exchange - The KeyExchange for the key share.
140+
*/
141+
constructor(group: NamedGroup, key_exchange: KeyExchange);
142+
143+
/** The NamedGroup for the key share. */
144+
group: NamedGroup;
145+
146+
/** The key exchange octet. */
147+
key_exchange: Uint8Array;
149148
}
150-
151-
export class NamedGroupList extends Constrained {
152-
/**
153-
* Parses a NamedGroupList from a Uint8Array.
154-
* @param array - The input array containing named groups data.
155-
* @returns A new instance of NamedGroupList.
156-
*/
157-
static from(array: Uint8Array): NamedGroupList;
158-
159-
/**
160-
* Constructs a NamedGroupList.
161-
* @param named_group_list - A list of NamedGroup instances.
162-
*/
163-
constructor(...named_group_list: NamedGroup[]);
164-
165-
/**
166-
* The list of named groups.
167-
*/
168-
readonly named_group_list: NamedGroup[];
169-
}

0 commit comments

Comments
 (0)