Skip to content

Commit 0468f1d

Browse files
committed
revise numZero with default value to 0
1 parent 38ae08d commit 0468f1d

File tree

2 files changed

+13
-13
lines changed

2 files changed

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

src/contentype.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,11 @@ export class ContentType extends Enum {
4444
)
4545
}
4646

47-
tlsInnerPlaintext(content, numZeros){
47+
tlsInnerPlaintext(content, numZeros) {
4848
return new TLSInnerPlaintext(content, this, numZeros)
4949
}
5050

51-
tlsCiphertext(encrypted_record){
51+
tlsCiphertext(encrypted_record) {
5252
return new TLSCiphertext(encrypted_record)
5353
}
5454
}
@@ -81,15 +81,15 @@ export class TLSPlaintext extends Uint8Array {
8181
}
8282

8383
export class TLSInnerPlaintext extends Uint8Array {
84-
static from(array){
84+
static from(array) {
8585
const copy = Uint8Array.from(array);
86-
const lastNonZeroIndex = copy.reduceRight((li,v,i)=>(li===-1 && v!==0? i:li),-1);
86+
const lastNonZeroIndex = copy.reduceRight((li, v, i) => (li === -1 && v !== 0 ? i : li), -1);
8787
const content = copy.slice(0, lastNonZeroIndex);
8888
const type = ContentType.fromValue(copy[lastNonZeroIndex]);
8989
const numZeros = copy.length - 1 - lastNonZeroIndex;
9090
return new TLSInnerPlaintext(content, type, numZeros)
9191
}
92-
constructor(content, type, numZeros) {
92+
constructor(content, type, numZeros = 0) {
9393
const struct = new Uint8Array(content.length + 1 + numZeros);
9494
struct.set(content, 0);
9595
struct[content.length] = +type;
@@ -98,24 +98,24 @@ export class TLSInnerPlaintext extends Uint8Array {
9898
}
9999

100100
export class TLSCiphertext extends Uint8Array {
101-
static from(array){
101+
static from(array) {
102102
const copy = Uint8Array.from(array);
103103
// NOTE should check contentType
104104
// NOTE legacy version can be bypassed
105105
const lengthOf = Uint16.from(copy.subarray(3));
106-
const encrypted_record = copy.subarray(5, lengthOf+5);
106+
const encrypted_record = copy.subarray(5, lengthOf + 5);
107107
return new TLSCiphertext(encrypted_record)
108108
}
109-
constructor(encrypted_record){
110-
const struct = new Uint8Array(encrypted_record.length+5);
109+
constructor(encrypted_record) {
110+
const struct = new Uint8Array(encrypted_record.length + 5);
111111
const lengthOf = Uint16.fromValue(encrypted_record.length);
112112
struct[0] = 23; // always application data
113113
struct[1] = 3; // major legacy version;
114114
struct[2] = 3; // minor legacy verions = TLS v1.2
115-
struct.set(lengthOf,3);
115+
struct.set(lengthOf, 3);
116116
struct.set(encrypted_record, 5);
117-
super(struct)
118-
this.header = struct.subarray(0,5);
117+
super(struct)
118+
this.header = struct.subarray(0, 5);
119119
this.encrypted_record = encrypted_record
120120
}
121121
}

0 commit comments

Comments
 (0)