11//@ts -self-types="../type/certificatereq.d.ts"
22
33import { Uint16 , Extension } from "./dep.ts" ;
4- import { parseExtension , parseItems } from "./utils.js" ;
4+ import { parseItems } from "./dep.ts" ;
5+ import { parseExtension } from "./encrypted.js" ;
56
6- /* class Extensions extends Constrained {
7- static from(array) {
8- const copy = Uint8Array.from(array);
9- const lengthOf = Uint16.from(copy.subarray(0, 2)).value;
10- if (lengthOf < 2) throw RangeError(`Minimum length of extension is 2 bytes`)
11- const extensions = [];
12- for (let offset = 2; offset < lengthOf + 2;) {
13- const extension = Extension.from(copy.subarray(offset))
14- extensions.push(extension);
15- offset += extension.length;
16- }
17- return new Extensions(...extensions)
18- }
19- constructor(...extensions) {
20- super(2, 65535, ...extensions)
21- this.extensions = extensions
22- }
23- }
24-
25- class Certificate_request_context extends Constrained {
26- static from(array) {
27- const copy = Uint8Array.from(array);
28- const lengthOf = copy.at(0);
29- if (lengthOf == 0) return new Certificate_request_context
30- const context = copy.subarray(1, 1 + lengthOf);
31- return new Certificate_request_context(context);
32- }
33- constructor(opaque) {
34- super(0, 255, opaque)
35- this.opaque = opaque
36- }
37- } */
387/**
8+ * ```
9+ * struct {
10+ opaque certificate_request_context<0..2^8-1>;
11+ Extension extensions<2..2^16-1>;
12+ } CertificateRequest;
13+ ```
3914 * https://datatracker.ietf.org/doc/html/rfc8446#section-4.3.2
4015 */
4116export class CertificateRequest extends Uint8Array {
4217 #context
4318 #extensions
44- static sanitize ( array ) {
45- const lengthOf_1 = array . at ( 0 ) ;
19+ static sanitize ( args ) {
20+ const a0 = args [ 0 ] ;
21+ if ( ! ( a0 instanceof Uint8Array ) ) return
22+ const lengthOf_1 = a0 . at ( 0 ) ;
4623 if ( lengthOf_1 > 255 ) throw Error ( `Context must less than 256 byte` )
47- const lengthOf_2 = Uint16 . from ( array . subarray ( 1 + lengthOf_1 ) ) . value ;
24+ const lengthOf_2 = Uint16 . from ( a0 . subarray ( 1 + lengthOf_1 ) ) . value ;
4825 if ( lengthOf_2 > 65535 ) throw Error ( `Extension must less than 65536` )
49- const output = array . slice ( 0 , lengthOf_1 + lengthOf_2 + 3 )
50- return [ output ]
26+ args [ 0 ] = a0 . slice ( 0 , lengthOf_1 + lengthOf_2 + 3 )
27+ return
5128 }
5229 static from ( array ) { return new CertificateRequest ( array ) }
5330 constructor ( ...args ) {
54- args = ( args [ 0 ] instanceof Uint8Array ) ? CertificateRequest . sanitize ( args [ 0 ] ) : args
31+ CertificateRequest . sanitize ( args )
5532 super ( ...args )
5633 }
5734 get context ( ) {
@@ -68,20 +45,4 @@ export class CertificateRequest extends Uint8Array {
6845 }
6946}
7047
71- /* export class CertificateRequest_0 extends Struct {
72- static from(array) {
73- const copy = Uint8Array.from(array);
74- const certificate_request_context = Certificate_request_context.from(copy);
75- const extensions = Extensions.from(copy.subarray(certificate_request_context.length))
76- return new CertificateRequest(certificate_request_context.opaque, ...extensions.extensions)
77- }
78- constructor(certificate_request_context, ...extension) {
79- super(
80- new Certificate_request_context(certificate_request_context),
81- new Extensions(...extension)
82- )
83- }
84- static extensions = Extensions
85- static certificate_request_context = Certificate_request_context
86- } */
8748
0 commit comments