Skip to content

Commit efd614e

Browse files
committed
chore: wip
chore: wip
1 parent 83e19d9 commit efd614e

9 files changed

Lines changed: 904 additions & 212 deletions

File tree

src/hmac.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
* Copyright (c) 2010-2012 Digital Bazaar, Inc. All rights reserved.
99
*/
1010

11-
import { ByteStringBuffer, createBuffer } from "./utils"
11+
import { ByteStringBuffer, createBuffer } from './utils'
1212

13-
type MessageDigest = {
13+
interface MessageDigest {
1414
start: () => MessageDigest
1515
update: (msg: string | ByteStringBuffer, encoding?: string) => MessageDigest
1616
digest: () => ByteStringBuffer
@@ -163,7 +163,7 @@ function create(): HMAC {
163163

164164
digest() {
165165
return this.getMac()
166-
}
166+
},
167167
}
168168

169169
return ctx

src/md5.ts

Lines changed: 135 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
import { ByteStringBuffer, createBuffer, encodeUtf8, fillString } from './utils'
1010

11-
type MD5State = {
11+
interface MD5State {
1212
h0: number
1313
h1: number
1414
h2: number
@@ -52,7 +52,7 @@ function create(): MessageDigest {
5252
let _input = createBuffer()
5353

5454
// used for word storage
55-
const _w = new Array(16).fill(0)
55+
const _w = Array.from({ length: 16 }).fill(0)
5656

5757
// message digest object
5858
const md: MessageDigest = {
@@ -107,7 +107,7 @@ function create(): MessageDigest {
107107
}
108108

109109
// update message length
110-
let len = msg instanceof ByteStringBuffer ? msg.length() : msg.length
110+
const len = msg instanceof ByteStringBuffer ? msg.length() : msg.length
111111
md.messageLength += len
112112
const lenArray: LengthArray = [Math.floor(len / 0x100000000) >>> 0, len >>> 0]
113113
for (let i = md.fullMessageLength.length - 1; i >= 0; --i) {
@@ -120,7 +120,8 @@ function create(): MessageDigest {
120120
// add bytes to input buffer
121121
if (msg instanceof ByteStringBuffer) {
122122
_input.putBytes(msg.bytes())
123-
} else {
123+
}
124+
else {
124125
_input.putBytes(msg)
125126
}
126127

@@ -151,8 +152,8 @@ function create(): MessageDigest {
151152

152153
// compute remaining size to be digested (include message length size)
153154
const remaining = (
154-
md.fullMessageLength[md.fullMessageLength.length - 1] +
155-
md.messageLengthSize
155+
md.fullMessageLength[md.fullMessageLength.length - 1]
156+
+ md.messageLengthSize
156157
)
157158

158159
// add padding for overflow blockSize - overflow
@@ -210,18 +211,138 @@ function _init() {
210211

211212
// g values
212213
_g.push(
213-
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
214-
1, 6, 11, 0, 5, 10, 15, 4, 9, 14, 3, 8, 13, 2, 7, 12,
215-
5, 8, 11, 14, 1, 4, 7, 10, 13, 0, 3, 6, 9, 12, 15, 2,
216-
0, 7, 14, 5, 12, 3, 10, 1, 8, 15, 6, 13, 4, 11, 2, 9
214+
0,
215+
1,
216+
2,
217+
3,
218+
4,
219+
5,
220+
6,
221+
7,
222+
8,
223+
9,
224+
10,
225+
11,
226+
12,
227+
13,
228+
14,
229+
15,
230+
1,
231+
6,
232+
11,
233+
0,
234+
5,
235+
10,
236+
15,
237+
4,
238+
9,
239+
14,
240+
3,
241+
8,
242+
13,
243+
2,
244+
7,
245+
12,
246+
5,
247+
8,
248+
11,
249+
14,
250+
1,
251+
4,
252+
7,
253+
10,
254+
13,
255+
0,
256+
3,
257+
6,
258+
9,
259+
12,
260+
15,
261+
2,
262+
0,
263+
7,
264+
14,
265+
5,
266+
12,
267+
3,
268+
10,
269+
1,
270+
8,
271+
15,
272+
6,
273+
13,
274+
4,
275+
11,
276+
2,
277+
9,
217278
)
218279

219280
// rounds table
220281
_r.push(
221-
7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22, 7, 12, 17, 22,
222-
5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20, 5, 9, 14, 20,
223-
4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23, 4, 11, 16, 23,
224-
6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21, 6, 10, 15, 21
282+
7,
283+
12,
284+
17,
285+
22,
286+
7,
287+
12,
288+
17,
289+
22,
290+
7,
291+
12,
292+
17,
293+
22,
294+
7,
295+
12,
296+
17,
297+
22,
298+
5,
299+
9,
300+
14,
301+
20,
302+
5,
303+
9,
304+
14,
305+
20,
306+
5,
307+
9,
308+
14,
309+
20,
310+
5,
311+
9,
312+
14,
313+
20,
314+
4,
315+
11,
316+
16,
317+
23,
318+
4,
319+
11,
320+
16,
321+
23,
322+
4,
323+
11,
324+
16,
325+
23,
326+
4,
327+
11,
328+
16,
329+
23,
330+
6,
331+
10,
332+
15,
333+
21,
334+
6,
335+
10,
336+
15,
337+
21,
338+
6,
339+
10,
340+
15,
341+
21,
342+
6,
343+
10,
344+
15,
345+
21,
225346
)
226347

227348
// get the result of abs(sin(i + 1)) as a 32-bit integer

src/pem.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
*
2727
* body: the binary-encoded body.
2828
*/
29-
import { encode64, decode64 } from './utils'
29+
import { decode64, encode64 } from './utils'
3030

3131
interface ProcType {
3232
version: string
@@ -126,7 +126,8 @@ export function decode(str: string): PemMessage[] {
126126
let match: RegExpExecArray | null
127127
while (true) {
128128
match = rMessage.exec(str)
129-
if (!match) break
129+
if (!match)
130+
break
130131

131132
// accept "NEW CERTIFICATE REQUEST" as "CERTIFICATE REQUEST"
132133
let type = match[1]
@@ -144,7 +145,8 @@ export function decode(str: string): PemMessage[] {
144145
rval.push(msg)
145146

146147
// no headers
147-
if (!match[2]) continue
148+
if (!match[2])
149+
continue
148150

149151
// parse headers
150152
const lines = match[2].split(rCRLF)
@@ -156,7 +158,8 @@ export function decode(str: string): PemMessage[] {
156158
// RFC2822 unfold any following folded lines
157159
for (let nl = li + 1; nl < lines.length; ++nl) {
158160
const next = lines[nl]
159-
if (!/\s/.test(next[0])) break
161+
if (!/\s/.test(next[0]))
162+
break
160163
line += next
161164
li = nl
162165
}
@@ -265,6 +268,6 @@ export interface Pem {
265268
}
266269

267270
export const pem: Pem = {
268-
encode: encode,
269-
decode: decode,
271+
encode,
272+
decode,
270273
}

0 commit comments

Comments
 (0)