11// deno-lint-ignore-file no-slow-types
22// @ts -self-types="../type/encrypted.d.ts"
33import { ContentType , HandshakeType } from "./dep.ts" ;
4- import { Uint16 , Constrained , Uint24 } from "./dep.ts" ;
4+ import { Uint16 , Constrained , Uint24 , parseItems } from "./dep.ts" ;
55import {
66 Extension , ExtensionType ,
77 NamedGroupList , RecordSizeLimit ,
@@ -19,16 +19,19 @@ export class EncryptedExtensions extends Constrained {
1919 ext = new Set ;
2020 static fromExtensions ( ...extensions ) { return new EncryptedExtensions ( ...extensions ) }
2121 static fromHandshake ( array ) {
22- const copy = array . slice ( ) ;
23- const _type = HandshakeType . from ( copy ) ;
24- const _lengthOf = Uint24 . from ( copy . subarray ( 1 ) ) . value ;
22+ const copy = Uint8Array . from ( array ) ;
23+ const type = HandshakeType . from ( copy ) ;
24+ if ( type !== HandshakeType . ENCRYPTED_EXTENSIONS ) return TypeError ( `Expected EncryptedExtension` )
25+ const lengthOf = Uint24 . from ( copy . subarray ( 1 ) ) . value ;
26+ if ( lengthOf == 2 ) return new EncryptedExtensions
2527 return EncryptedExtensions . from ( copy . subarray ( 4 ) )
2628 }
2729 static from ( array ) {
2830 const copy = Uint8Array . from ( array )
29- if ( copy . length == 0 ) return new EncryptedExtensions
30- const extensions = Extensions . from ( copy . subarray ( ) ) ;
31- return new EncryptedExtensions ( ...extensions . extensions )
31+ const lengthOf = Uint16 . from ( copy ) . value ;
32+ if ( lengthOf == 0 ) return new EncryptedExtensions
33+ const extensions = parseItems ( copy , 2 , lengthOf , Extension ) ; //_Extensions.from(copy.subarray());
34+ return new EncryptedExtensions ( ...extensions )
3235 }
3336
3437 constructor ( ...extensions ) {
@@ -45,22 +48,22 @@ export class EncryptedExtensions extends Constrained {
4548 }
4649}
4750
48- class Extensions extends Constrained {
49- static fromExtension ( ...extensions ) { return new Extensions ( ...extensions ) }
51+ class _Extensions extends Constrained {
52+ static fromExtension ( ...extensions ) { return new _Extensions ( ...extensions ) }
5053 static from ( array ) {
5154 const copy = Uint8Array . from ( array ) ;
5255 const _lengthOf = Uint16 . from ( copy ) . value ;
5356 const extensions = [ ] ;
5457 let offset = 2 ;
5558 //for (let offset = 2; offset < lengthOf + 2;) {
56- //if (offset > copy.length - 2) break;
57- while ( true ) {
59+ //if (offset > copy.length - 2) break;
60+ while ( true ) {
5861 const extension = Extension . from ( copy . subarray ( offset ) ) ; offset += extension . length
5962 parseExtension ( extension ) ;
6063 extensions . push ( extension )
6164 if ( offset >= copy . length - 2 ) break ;
6265 }
63- return new Extensions ( ...extensions )
66+ return new _Extensions ( ...extensions )
6467 }
6568 constructor ( ...extensions ) {
6669 super ( 0 , 2 ** 16 - 1 , ...extensions )
0 commit comments