Skip to content

Commit d12ad44

Browse files
committed
ver 0.2.9
1 parent db9685e commit d12ad44

File tree

5 files changed

+286
-16
lines changed

5 files changed

+286
-16
lines changed

deno.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@tls/enum",
3-
"version": "0.2.8",
3+
"version": "0.2.9",
44
"exports": "./src/mod.ts",
55
"publish": {
66
"exclude": ["dist/"]
@@ -17,6 +17,6 @@
1717
"@std/assert": "jsr:@std/assert@^1.0.2",
1818
"@tls/extension": "jsr:@tls/extension@^0.2.0",
1919
"@tls/record": "jsr:@tls/record@^0.0.6",
20-
"@tls/struct": "jsr:@tls/struct@^0.2.6"
20+
"@tls/struct": "jsr:@tls/struct@^0.3.1"
2121
}
2222
}

src/certificatetype.js

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// @ts-self-types="../type/certificatetype.d.ts"
33

44
import { Enum } from "./enum.js";
5+
import { Constrained, Struct, Uint24, Uint8, Uint16 } from "./dep.ts"
56

67
/**
78
* Supported groups - @see https://datatracker.ietf.org/doc/html/rfc8446#section-4.2.7.
@@ -25,4 +26,90 @@ export class CertificateType extends Enum {
2526

2627
}
2728

29+
export class CertificateEntry extends Uint8Array {
30+
static from(array){
31+
const copy = Uint8Array.from(array);
32+
let offset = 0
33+
const cert_data = Cert_data.from(copy.subarray(offset));offset+=cert_data.length;
34+
const extensions = Extensions.from(copy.subarray(offset));
35+
return new CertificateEntry(cert_data.opaque, ...extensions.extension)
36+
}
37+
constructor(opaque, ...extension){
38+
const cert_data = new Cert_data(opaque);
39+
const extensions = new Extensions(...extension);
40+
const struct = new Struct(cert_data, extensions);
41+
super(struct);
42+
this.opaque = opaque;
43+
this.extension = extension
44+
}
45+
}
46+
47+
export class Certificate extends Uint8Array {
48+
static from(array){
49+
const copy = Uint8Array.from(array);
50+
let offset = 0;
51+
const certificate_request_context = Certificate_request_context.from(copy.subarray(offset)); offset+= certificate_request_context.length;
52+
const certificate_list = Certificate_list.from(copy.subarray(offset));
53+
return new Certificate(certificate_request_context.opaque, ...certificate_list.certificateEntry)
54+
}
55+
constructor(opaque, ...certificateEntry){
56+
const certificate_request_context = new Certificate_request_context(opaque);
57+
const certificate_list = new Certificate_list(...certificateEntry);
58+
const struct = new Struct(certificate_request_context, certificate_list);
59+
super(struct);
60+
this.opaque = opaque;
61+
this.certificateEntry = certificateEntry
62+
}
63+
}
64+
65+
class Cert_data extends Constrained {
66+
static from(array){
67+
const copy = Uint8Array.from(array);
68+
const lengthOf = Uint24.from(copy).value;
69+
return new Cert_data(copy.subarray(3, lengthOf+3))
70+
}
71+
constructor(opaque){
72+
super(1, 2**24-1, opaque);
73+
this.opaque = opaque
74+
}
75+
}
76+
77+
class Extensions extends Constrained {
78+
static from(array){
79+
const copy = Uint8Array.from(array);
80+
const lengthOf = Uint16.from(copy).value;
81+
return new Extensions(copy.subarray(2, lengthOf + 2))
82+
}
83+
constructor(...extension){
84+
super(0, 2**16-1, ...extension);
85+
this.extension = extension
86+
}
87+
}
88+
89+
class Certificate_request_context extends Constrained {
90+
static from(array){
91+
const copy = Uint8Array.from(array);
92+
const lengthOf = Uint8.from(copy).value;
93+
return new Certificate_request_context(copy.subarray(1, lengthOf + 1))
94+
}
95+
constructor(opaque){
96+
super(0, 2**8-1, opaque);
97+
this.opaque = opaque
98+
}
99+
}
100+
101+
class Certificate_list extends Constrained {
102+
static from(array){
103+
const copy = Uint8Array.from(array);
104+
const lengthOf = Uint24.from(copy).value;
105+
return new Certificate_list(copy.subarray(3, lengthOf + 3))
106+
}
107+
constructor(...certificateEntry){
108+
super(0, 2**24-1, ...certificateEntry);
109+
this.certificateEntry = certificateEntry
110+
}
111+
}
112+
113+
114+
28115
// npx -p typescript tsc ./src/certificatetype.js --declaration --allowJs --emitDeclarationOnly --lib ESNext --outDir ./dist

src/dep.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ export { x25519 } from '@noble/curves/ed25519'
88
export { x448 } from '@noble/curves/ed448'
99
export * as utils from "@noble/curves/abstract/utils"
1010
export { TLSPlaintext } from "@tls/record"
11+
export { HexaDecimal } from "@tls/struct"
1112

test/certificate_test.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import { Certificate } from "../src/certificatetype.js";
2+
import { Handshake } from "../src/handshaketype.js";
3+
import { HexaDecimal } from "../src/dep.ts";
4+
5+
const test = Certificate.from(HexaDecimal.fromString(`0b 00 01 b9 00 00 01 b5 00 01 b0 30 82
6+
01 ac 30 82 01 15 a0 03 02 01 02 02 01 02 30 0d 06 09 2a 86 48
7+
86 f7 0d 01 01 0b 05 00 30 0e 31 0c 30 0a 06 03 55 04 03 13 03
8+
72 73 61 30 1e 17 0d 31 36 30 37 33 30 30 31 32 33 35 39 5a 17
9+
0d 32 36 30 37 33 30 30 31 32 33 35 39 5a 30 0e 31 0c 30 0a 06
10+
03 55 04 03 13 03 72 73 61 30 81 9f 30 0d 06 09 2a 86 48 86 f7
11+
0d 01 01 01 05 00 03 81 8d 00 30 81 89 02 81 81 00 b4 bb 49 8f
12+
82 79 30 3d 98 08 36 39 9b 36 c6 98 8c 0c 68 de 55 e1 bd b8 26
13+
d3 90 1a 24 61 ea fd 2d e4 9a 91 d0 15 ab bc 9a 95 13 7a ce 6c
14+
1a f1 9e aa 6a f9 8c 7c ed 43 12 09 98 e1 87 a8 0e e0 cc b0 52
15+
4b 1b 01 8c 3e 0b 63 26 4d 44 9a 6d 38 e2 2a 5f da 43 08 46 74
16+
80 30 53 0e f0 46 1c 8c a9 d9 ef bf ae 8e a6 d1 d0 3e 2b d1 93
17+
ef f0 ab 9a 80 02 c4 74 28 a6 d3 5a 8d 88 d7 9f 7f 1e 3f 02 03
18+
01 00 01 a3 1a 30 18 30 09 06 03 55 1d 13 04 02 30 00 30 0b 06
19+
03 55 1d 0f 04 04 03 02 05 a0 30 0d 06 09 2a 86 48 86 f7 0d 01
20+
01 0b 05 00 03 81 81 00 85 aa d2 a0 e5 b9 27 6b 90 8c 65 f7 3a
21+
72 67 17 06 18 a5 4c 5f 8a 7b 33 7d 2d f7 a5 94 36 54 17 f2 ea
22+
e8 f8 a5 8c 8f 81 72 f9 31 9c f3 6b 7f d6 c5 5b 80 f2 1a 03 01
23+
51 56 72 60 96 fd 33 5e 5e 67 f2 db f1 02 70 2e 60 8c ca e6 be
24+
c1 fc 63 a4 2a 99 be 5c 3e b7 10 7c 3c 54 e9 b9 eb 2b d5 20 3b
25+
1c 3b 84 e0 a8 b2 f7 59 40 9b a3 ea c9 d9 1d 40 2d cc 0c c8 f8
26+
96 12 29 ac 91 87 b4 2b 4d e1 00 00`).byte)

type/certificatetype.d.ts

Lines changed: 170 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,174 @@
1+
import { Enum } from "../src/enum.js";
2+
import { Constrained } from "../src/dep.ts";
3+
14
/**
2-
* Supported groups - @see https://datatracker.ietf.org/doc/html/rfc8446#section-4.2.7.
5+
* Represents TLS Certificate Types.
6+
* @see https://datatracker.ietf.org/doc/html/rfc8446#section-4.2.7
7+
* @extends {Enum}
38
*/
49
export class CertificateType extends Enum {
5-
static X509: CertificateType;
6-
static RAWPUBLICKEY: CertificateType;
7-
/**
8-
* check octet and return valid CertificateType
9-
*
10-
* @static
11-
* @param {Uint8Array} octet
12-
* @returns {CertificateType }
13-
*/
14-
static from(octet: Uint8Array): CertificateType;
15-
/**return 8 */
16-
get bit(): number;
10+
/** Certificate type X.509 */
11+
static X509: CertificateType;
12+
13+
/** Certificate type Raw Public Key */
14+
static RAWPUBLICKEY: CertificateType;
15+
16+
/**
17+
* Checks the given octet and returns a valid `CertificateType`.
18+
* @param {Uint8Array} octet - The octet to validate.
19+
* @returns {CertificateType} The corresponding `CertificateType`.
20+
* @throws Will throw an error if the type is unknown.
21+
*/
22+
static from(octet: Uint8Array): CertificateType;
23+
24+
/**
25+
* The bit length of the certificate type.
26+
* @type {number}
27+
* @readonly
28+
*/
29+
get bit(): number;
30+
}
31+
32+
/**
33+
* Represents a TLS Certificate Entry.
34+
* @extends {Uint8Array}
35+
*/
36+
export class CertificateEntry extends Uint8Array {
37+
/**
38+
* Parses an array to create a `CertificateEntry`.
39+
* @param {Uint8Array} array - The array to parse.
40+
* @returns {CertificateEntry} The parsed certificate entry.
41+
*/
42+
static from(array: Uint8Array): CertificateEntry;
43+
44+
/**
45+
* Constructs a `CertificateEntry`.
46+
* @param {Uint8Array} opaque - The certificate data.
47+
* @param {...Uint8Array} extension - The certificate extensions.
48+
*/
49+
constructor(opaque: Uint8Array, ...extension: Uint8Array[]);
50+
51+
/** The certificate data. */
52+
opaque: Uint8Array;
53+
54+
/** The certificate extensions. */
55+
extension: Uint8Array[];
56+
}
57+
58+
/**
59+
* Represents a TLS Certificate structure.
60+
* @extends {Uint8Array}
61+
*/
62+
export class Certificate extends Uint8Array {
63+
/**
64+
* Parses an array to create a `Certificate`.
65+
* @param {Uint8Array} array - The array to parse.
66+
* @returns {Certificate} The parsed certificate.
67+
*/
68+
static from(array: Uint8Array): Certificate;
69+
70+
/**
71+
* Constructs a `Certificate`.
72+
* @param {Uint8Array} opaque - The certificate request context.
73+
* @param {...CertificateEntry} certificateEntry - The list of certificate entries.
74+
*/
75+
constructor(opaque: Uint8Array, ...certificateEntry: CertificateEntry[]);
76+
77+
/** The certificate request context. */
78+
opaque: Uint8Array;
79+
80+
/** The list of certificate entries. */
81+
certificateEntry: CertificateEntry[];
82+
}
83+
84+
/**
85+
* Represents constrained certificate data.
86+
* @extends {Constrained}
87+
* @private
88+
*/
89+
declare class Cert_data extends Constrained {
90+
/**
91+
* Parses an array to create `Cert_data`.
92+
* @param {Uint8Array} array - The array to parse.
93+
* @returns {Cert_data} The parsed certificate data.
94+
*/
95+
static from(array: Uint8Array): Cert_data;
96+
97+
/**
98+
* Constructs a `Cert_data` instance.
99+
* @param {Uint8Array} opaque - The certificate data.
100+
*/
101+
constructor(opaque: Uint8Array);
102+
103+
/** The certificate data. */
104+
opaque: Uint8Array;
105+
}
106+
107+
/**
108+
* Represents constrained extensions.
109+
* @extends {Constrained}
110+
* @private
111+
*/
112+
declare class Extensions extends Constrained {
113+
/**
114+
* Parses an array to create `Extensions`.
115+
* @param {Uint8Array} array - The array to parse.
116+
* @returns {Extensions} The parsed extensions.
117+
*/
118+
static from(array: Uint8Array): Extensions;
119+
120+
/**
121+
* Constructs an `Extensions` instance.
122+
* @param {...Uint8Array} extension - The list of extensions.
123+
*/
124+
constructor(...extension: Uint8Array[]);
125+
126+
/** The list of extensions. */
127+
extension: Uint8Array[];
128+
}
129+
130+
/**
131+
* Represents a certificate request context.
132+
* @extends {Constrained}
133+
* @private
134+
*/
135+
declare class Certificate_request_context extends Constrained {
136+
/**
137+
* Parses an array to create `Certificate_request_context`.
138+
* @param {Uint8Array} array - The array to parse.
139+
* @returns {Certificate_request_context} The parsed context.
140+
*/
141+
static from(array: Uint8Array): Certificate_request_context;
142+
143+
/**
144+
* Constructs a `Certificate_request_context` instance.
145+
* @param {Uint8Array} opaque - The context data.
146+
*/
147+
constructor(opaque: Uint8Array);
148+
149+
/** The context data. */
150+
opaque: Uint8Array;
151+
}
152+
153+
/**
154+
* Represents a certificate list.
155+
* @extends {Constrained}
156+
* @private
157+
*/
158+
declare class Certificate_list extends Constrained {
159+
/**
160+
* Parses an array to create `Certificate_list`.
161+
* @param {Uint8Array} array - The array to parse.
162+
* @returns {Certificate_list} The parsed list.
163+
*/
164+
static from(array: Uint8Array): Certificate_list;
165+
166+
/**
167+
* Constructs a `Certificate_list` instance.
168+
* @param {...CertificateEntry} certificateEntry - The list of certificate entries.
169+
*/
170+
constructor(...certificateEntry: CertificateEntry[]);
171+
172+
/** The list of certificate entries. */
173+
certificateEntry: CertificateEntry[];
17174
}
18-
import { Enum } from "../src/enum.js";

0 commit comments

Comments
 (0)