Skip to content

Commit 90c1f5a

Browse files
committed
add set privateKey(key) and set publicKey(key) to NamedGroup.js
1 parent a1d1493 commit 90c1f5a

File tree

3 files changed

+24
-11
lines changed

3 files changed

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

src/namedgroup.js

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,16 @@ export class NamedGroup extends Enum {
6969
* @returns {Function} The key generation function.
7070
*/
7171
get keyGen() {
72+
if (this.#keyGen) return this.#keyGen
7273
switch (this.name) {
73-
case "SECP256R1": return p256;
74-
case "SECP384R1": return p384;
75-
case "SECP521R1": return p521;
76-
case "X25519": return x25519;
77-
case "X448": return x448;
78-
default: return x25519;
74+
case "SECP256R1": this.#keyGen = p256; break;
75+
case "SECP384R1": this.#keyGen = p384; break;
76+
case "SECP521R1": this.#keyGen = p521; break;
77+
case "X448": this.#keyGen = x448; break;
78+
case "X25519":
79+
default: this.#keyGen = x25519; break;
7980
}
81+
return this.#keyGen
8082
}
8183

8284
/**
@@ -90,16 +92,20 @@ export class NamedGroup extends Enum {
9092
return this.#privateKey
9193
}
9294

95+
set privateKey(key) { this.#privateKey = key }
96+
9397
/**
9498
* Gets the public key associated with the NamedGroup.
9599
*
96100
* @returns {Uint8Array} The public key.
97101
*/
98-
get publicKey() {
99-
if(this.#publicKey)return this.#publicKey;
102+
get publicKey() {
103+
if (this.#publicKey) return this.#publicKey;
100104
this.#publicKey = this.keyGen?.getPublicKey(this.privateKey);
101105
return this.#publicKey;
102-
}
106+
}
107+
108+
set publicKey(key) { this.#publicKey = key }
103109

104110
/**
105111
* Computes the shared key with a peer's public key.
@@ -146,7 +152,7 @@ export class KeyExchange extends Constrained {
146152
* Represents a key share entry.
147153
*/
148154
export class KeyShareEntry extends Struct {
149-
155+
150156
static from(array) {
151157
const copy = Uint8Array.from(array);
152158
const group = NamedGroup.from(copy.subarray(0, 2));

type/namedgroup.d.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,20 @@ export class NamedGroup extends Enum {
6060
*/
6161
get privateKey(): Uint8Array;
6262

63+
/** Sets the private key associated with the NamedGroup. */
64+
set privateKey(key : Uint8Array);
65+
6366
/**
6467
* Gets the public key associated with the NamedGroup.
6568
*
6669
* @returns {Uint8Array} The public key.
6770
*/
6871
get publicKey(): Uint8Array;
6972

73+
74+
/** Sets the public key associated with the NamedGroup. */
75+
set publicKey(key : Uint8Array);
76+
7077
/**
7178
* Computes the shared key with a peer's public key.
7279
*

0 commit comments

Comments
 (0)