File tree Expand file tree Collapse file tree 4 files changed +30
-6
lines changed Expand file tree Collapse file tree 4 files changed +30
-6
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " @tls/enum" ,
3- "version" : " 0.5.5 " ,
3+ "version" : " 0.5.6 " ,
44 "exports" : " ./src/mod.ts" ,
55 "publish" : {
66 "exclude" : [" dist/" ]
Original file line number Diff line number Diff line change @@ -6,13 +6,21 @@ export class Cipher extends Enum {
66 static AES_128_GCM_SHA256 = new Cipher ( 'AES_128_GCM_SHA256' , 0x01 ) ;
77 static AES_256_GCM_SHA384 = new Cipher ( 'AES_256_GCM_SHA384' , 0x02 ) ;
88 static CHACHA20_POLY1305_SHA256 = new Cipher ( 'CHACHA20_POLY1305_SHA256' , 0x03 ) ;
9-
10- static from ( array ) {
9+
10+ static from ( array ) {
1111 const copy = Uint8Array . from ( array ) ;
12- if ( copy . at ( 0 ) !== 0x13 ) throw TypeError ( `Expected 0x13 at index 0` )
12+ if ( copy . at ( 0 ) !== 0x13 ) throw TypeError ( `Expected 0x13 at index 0` )
1313 return Cipher . fromValue ( copy . at ( 1 ) )
1414 }
1515
16- get Uint16 ( ) { return Uint8Array . of ( 0x13 , + this ) }
16+ get Uint16 ( ) { return Uint8Array . of ( 0x13 , + this ) }
17+
18+ get hashLength ( ) {
19+ return this . name . slice ( - 3 ) / 8 ;
20+ }
21+
22+ get keyLength ( ) {
23+ return this . name . startsWith ( 'AES_128' ) ? 16 : 32
24+ }
1725}
1826
Original file line number Diff line number Diff line change @@ -5,4 +5,8 @@ Deno.test("Cipher", () => {
55 const test = Cipher . AES_128_GCM_SHA256 . Uint16 ;
66 const back = Cipher . from ( test ) . Uint16 ;
77 assertEquals ( test , back )
8- } )
8+ } )
9+
10+ console . log ( Cipher . AES_128_GCM_SHA256 . keyLength ) ;
11+ console . log ( Cipher . AES_256_GCM_SHA384 . hashLength ) ;
12+ console . log ( Cipher . CHACHA20_POLY1305_SHA256 . keyLength ) ;
Original file line number Diff line number Diff line change @@ -33,4 +33,16 @@ export class Cipher extends Enum {
3333 * @returns A `Uint8Array` containing the cipher suite identifier.
3434 */
3535 get Uint16 ( ) : Uint8Array ;
36+
37+ /**
38+ * Get hash length for respective cipher
39+ * @returns hash length either 32 or 48
40+ */
41+ get hashLength ( ) : number ;
42+
43+ /**
44+ * Get key length for respective cipher
45+ * @returns key length either 16 or 32
46+ */
47+ get keyLength ( ) : number ;
3648}
You can’t perform that action at this time.
0 commit comments