Skip to content

Commit 963b7b8

Browse files
committed
0.0.3 add NamedGroup
1 parent a6d02dc commit 963b7b8

File tree

3 files changed

+67
-1
lines changed

3 files changed

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

src/namedgroup.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// deno-lint-ignore-file no-slow-types
2+
// @ts-self-types="../type/namedgroup.d.ts"
3+
4+
import { Enum } from "./enum.js";
5+
6+
/**
7+
* Supported groups - @see https://datatracker.ietf.org/doc/html/rfc8446#section-4.2.7.
8+
*/
9+
export class NamedGroup extends Enum {
10+
/* Elliptic Curve Groups (ECDHE) */
11+
static SECP256R1 = new NamedGroup('SECP256R1', 0x0017);
12+
static SECP384R1 = new NamedGroup('SECP384R1', 0x0018);
13+
static SECP521R1 = new NamedGroup('SECP521R1', 0x0019);
14+
static X25519 = new NamedGroup('X25519', 0x001D);
15+
static X448 = new NamedGroup('X448', 0x001E);
16+
17+
/* Finite Field Groups (DHE) */
18+
static FFDHE2048 = new NamedGroup('FFDHE2048', 0x0100);
19+
static FFDHE3072 = new NamedGroup('FFDHE3072', 0x0101);
20+
static FFDHE4096 = new NamedGroup('FFDHE4096', 0x0102);
21+
static FFDHE6144 = new NamedGroup('FFDHE6144', 0x0103);
22+
static FFDHE8192 = new NamedGroup('FFDHE8192', 0x0104);
23+
/**
24+
* check octet and return valid SignatureScheme
25+
*
26+
* @static
27+
* @param {Uint8Array} octet
28+
* @returns {NamedGroup}
29+
*/
30+
static parse(octet) {
31+
const value = octet[0] * 256 + octet[1]
32+
return NamedGroup.fromValue(value) ?? Error(`Unknown ${value} NamedGroup type`);
33+
}
34+
35+
/**return 16 */
36+
get bit() { return 16 }
37+
38+
}
39+
40+
// npx -p typescript tsc ./src/namedgroup.js --declaration --allowJs --emitDeclarationOnly --lib ESNext --outDir ./dist

type/namedgroup.d.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/**
2+
* Supported groups - @see https://datatracker.ietf.org/doc/html/rfc8446#section-4.2.7.
3+
*/
4+
export class NamedGroup extends Enum {
5+
static SECP256R1: NamedGroup;
6+
static SECP384R1: NamedGroup;
7+
static SECP521R1: NamedGroup;
8+
static X25519: NamedGroup;
9+
static X448: NamedGroup;
10+
static FFDHE2048: NamedGroup;
11+
static FFDHE3072: NamedGroup;
12+
static FFDHE4096: NamedGroup;
13+
static FFDHE6144: NamedGroup;
14+
static FFDHE8192: NamedGroup;
15+
/**
16+
* check octet and return valid SignatureScheme
17+
*
18+
* @static
19+
* @param {Uint8Array} octet
20+
* @returns {NamedGroup}
21+
*/
22+
static parse(octet: Uint8Array): NamedGroup;
23+
/**return 16 */
24+
get bit(): number;
25+
}
26+
import { Enum } from "../src/enum.js";

0 commit comments

Comments
 (0)