11import { 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 */
66export 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 */
101100export 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 */
129128export 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