Skip to content

Commit a290324

Browse files
committed
improve tlsinnerplaintext and tlschipertext
1 parent 82d622b commit a290324

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
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.4.6",
3+
"version": "0.4.7",
44
"exports": "./src/mod.ts",
55
"publish": {
66
"exclude": ["dist/"]

src/contentype.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ export class TLSPlaintext extends Uint8Array {
8181
}
8282

8383
export class TLSInnerPlaintext extends Uint8Array {
84+
content;
85+
type;
86+
numZeros;
8487
static from(array) {
8588
const copy = Uint8Array.from(array);
8689
const lastNonZeroIndex = copy.reduceRight((li, v, i) => (li === -1 && v !== 0 ? i : li), -1);
@@ -93,7 +96,14 @@ export class TLSInnerPlaintext extends Uint8Array {
9396
const struct = new Uint8Array(content.length + 1 + numZeros);
9497
struct.set(content, 0);
9598
struct[content.length] = +type;
96-
super(struct)
99+
super(struct);
100+
this.content = content;
101+
this.type = type;
102+
this.numZeros = numZeros
103+
}
104+
header(keyLength){
105+
const lengthOf = this.length + keyLength;
106+
return Uint8Array.of(+this.type, 3, 3, Math.trunc(lengthOf / 256), lengthOf % 256)
97107
}
98108
}
99109

@@ -102,7 +112,7 @@ export class TLSCiphertext extends Uint8Array {
102112
const copy = Uint8Array.from(array);
103113
// NOTE should check contentType
104114
// NOTE legacy version can be bypassed
105-
const lengthOf = Uint16.from(copy.subarray(3));
115+
const lengthOf = Uint16.from(copy.subarray(3)).value;
106116
const encrypted_record = copy.subarray(5, lengthOf + 5);
107117
return new TLSCiphertext(encrypted_record)
108118
}

type/contentype.d.ts

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -134,28 +134,42 @@ export class TLSPlaintext extends Uint8Array {
134134
}
135135

136136
/**
137-
* Represents a TLSInnerPlaintext structure in the TLS 1.3 protocol.
138-
* This class extends `Uint8Array` to encapsulate TLSInnerPlaintext data.
137+
* Represents a TLSInnerPlaintext structure as per the TLS 1.3 specification.
139138
*/
140139
export class TLSInnerPlaintext extends Uint8Array {
140+
/** The content of the plaintext. */
141+
content: Uint8Array;
142+
143+
/** The content type associated with this plaintext. */
144+
type: ContentType;
145+
146+
/** The number of trailing zero bytes in the structure. */
147+
numZeros: number;
148+
141149
/**
142-
* Creates a TLSInnerPlaintext instance from a given array.
143-
*
144-
* @param {Uint8Array } array - The input array to parse.
145-
* @returns {TLSInnerPlaintext} A new instance of TLSInnerPlaintext.
150+
* Parses a `TLSInnerPlaintext` instance from a given array.
151+
* @param {Uint8Array} array - The input array to parse.
152+
* @returns {TLSInnerPlaintext} The parsed `TLSInnerPlaintext` instance.
146153
*/
147154
static from(array: Uint8Array): TLSInnerPlaintext;
148155

149156
/**
150-
* Constructs a TLSInnerPlaintext structure.
151-
*
152-
* @param {Uint8Array} content - The content bytes.
153-
* @param {ContentType} type - The content type as a `ContentType` instance.
154-
* @param {number} numZeros - The number of zero bytes to pad.
157+
* Constructs a `TLSInnerPlaintext` instance.
158+
* @param {Uint8Array} content - The main content of the plaintext.
159+
* @param {ContentType} type - The content type associated with the plaintext.
160+
* @param {number} [numZeros=0] - The number of trailing zero bytes (default is 0).
155161
*/
156-
constructor(content: Uint8Array, type: ContentType, numZeros: number);
162+
constructor(content: Uint8Array, type: ContentType, numZeros?: number);
163+
164+
/**
165+
* Generates a header for this plaintext structure.
166+
* @param {number} keyLength - The length of the encryption key.
167+
* @returns {Uint8Array} The generated header.
168+
*/
169+
header(keyLength: number): Uint8Array;
157170
}
158171

172+
159173
/**
160174
* Represents a TLSCiphertext structure in a TLS handshake.
161175
* Extends `Uint8Array` to include additional TLS-specific data and methods.

0 commit comments

Comments
 (0)