pdf-parser.js 5.2.27 → 5.2.28

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (145) hide show
  1. package/dist/{afm-widths-BYiX2L9D.cjs → afm-widths-BHD2HZIL.cjs} +553 -642
  2. package/dist/{afm-widths-blUDDjlI.js → afm-widths-B_IGbGky.js} +553 -642
  3. package/dist/afm-widths.cjs +1 -1
  4. package/dist/afm-widths.js +1 -1
  5. package/dist/annotations.cjs +5 -3
  6. package/dist/annotations.js +5 -3
  7. package/dist/builtin-encoding.cjs +17 -6
  8. package/dist/builtin-encoding.js +17 -6
  9. package/dist/bytes/crc32.cjs +5 -3
  10. package/dist/bytes/crc32.js +5 -3
  11. package/dist/bytes/flate.cjs +0 -1
  12. package/dist/bytes/flate.js +0 -1
  13. package/dist/cff-bounds.cjs +42 -24
  14. package/dist/cff-bounds.js +42 -24
  15. package/dist/cff.cjs +13 -6
  16. package/dist/cff.js +13 -6
  17. package/dist/cmap-table.cjs +54 -26
  18. package/dist/cmap-table.js +54 -26
  19. package/dist/cmap.cjs +5 -3
  20. package/dist/cmap.js +5 -3
  21. package/dist/content-write.cjs +3 -2
  22. package/dist/content-write.js +3 -2
  23. package/dist/crypto/aes.cjs +76 -55
  24. package/dist/crypto/aes.js +76 -55
  25. package/dist/crypto/md5.cjs +345 -149
  26. package/dist/crypto/md5.js +345 -149
  27. package/dist/crypto/rc4.cjs +5 -4
  28. package/dist/crypto/rc4.js +5 -4
  29. package/dist/crypto/sha2.cjs +92 -43
  30. package/dist/crypto/sha2.js +92 -43
  31. package/dist/embedded-font.cjs +4 -2
  32. package/dist/embedded-font.js +4 -2
  33. package/dist/encoding.cjs +1 -1
  34. package/dist/encoding.js +1 -1
  35. package/dist/encrypt-write.cjs +25 -21
  36. package/dist/encrypt-write.js +25 -21
  37. package/dist/encrypt.cjs +43 -64
  38. package/dist/encrypt.js +43 -64
  39. package/dist/filters.cjs +40 -20
  40. package/dist/filters.js +40 -20
  41. package/dist/font-face.cjs +2 -1
  42. package/dist/font-face.js +2 -1
  43. package/dist/font-read.cjs +12 -6
  44. package/dist/font-read.js +12 -6
  45. package/dist/font-tables.cjs +55 -28
  46. package/dist/font-tables.js +55 -28
  47. package/dist/gdef-table.cjs +6 -3
  48. package/dist/gdef-table.js +6 -3
  49. package/dist/glyf-contours.cjs +3 -1
  50. package/dist/glyf-contours.js +3 -1
  51. package/dist/glyf.cjs +22 -11
  52. package/dist/glyf.js +22 -11
  53. package/dist/gpos-table.cjs +37 -19
  54. package/dist/gpos-table.js +37 -19
  55. package/dist/gsub-table.cjs +28 -17
  56. package/dist/gsub-table.js +28 -17
  57. package/dist/hmtx-table.cjs +5 -3
  58. package/dist/hmtx-table.js +5 -3
  59. package/dist/image/ccitt-encode.cjs +8 -5
  60. package/dist/image/ccitt-encode.js +8 -5
  61. package/dist/image/ccitt.cjs +801 -209
  62. package/dist/image/ccitt.js +801 -209
  63. package/dist/image/jbig2-arith.cjs +340 -306
  64. package/dist/image/jbig2-arith.js +340 -306
  65. package/dist/image/jbig2-bitmap.cjs +8 -5
  66. package/dist/image/jbig2-bitmap.js +8 -5
  67. package/dist/image/jbig2-generic.cjs +240 -69
  68. package/dist/image/jbig2-generic.js +240 -69
  69. package/dist/image/jbig2-text.cjs +4 -2
  70. package/dist/image/jbig2-text.js +4 -2
  71. package/dist/image/jbig2.cjs +69 -31
  72. package/dist/image/jbig2.js +69 -31
  73. package/dist/image/jp2-boxes.cjs +52 -27
  74. package/dist/image/jp2-boxes.js +52 -27
  75. package/dist/image/jpeg-info.cjs +29 -24
  76. package/dist/image/jpeg-info.js +29 -24
  77. package/dist/image/jpeg2000-codestream.cjs +44 -24
  78. package/dist/image/jpeg2000-codestream.js +44 -24
  79. package/dist/image/jpeg2000-dwt.cjs +2 -1
  80. package/dist/image/jpeg2000-dwt.js +2 -1
  81. package/dist/image/jpeg2000-t1.cjs +21 -11
  82. package/dist/image/jpeg2000-t1.js +21 -11
  83. package/dist/image/jpeg2000-t2.cjs +12 -5
  84. package/dist/image/jpeg2000-t2.js +12 -5
  85. package/dist/image/jpeg2000-tagtree.cjs +8 -4
  86. package/dist/image/jpeg2000-tagtree.js +8 -4
  87. package/dist/image/jpeg2000.cjs +11 -6
  88. package/dist/image/jpeg2000.js +11 -6
  89. package/dist/image/png-decode.cjs +62 -39
  90. package/dist/image/png-decode.d.cts +3 -2
  91. package/dist/image/png-decode.d.ts +3 -2
  92. package/dist/image/png-decode.js +62 -39
  93. package/dist/image/png-filter.cjs +23 -15
  94. package/dist/image/png-filter.js +23 -15
  95. package/dist/images-read.cjs +41 -36
  96. package/dist/images-read.js +41 -36
  97. package/dist/index.cjs +1 -1
  98. package/dist/index.js +1 -1
  99. package/dist/interpret.cjs +39 -24
  100. package/dist/interpret.js +39 -24
  101. package/dist/lexer.cjs +86 -51
  102. package/dist/lexer.js +86 -51
  103. package/dist/math-content-write.cjs +9 -5
  104. package/dist/math-content-write.js +9 -5
  105. package/dist/math-font-write.cjs +2 -1
  106. package/dist/math-font-write.js +2 -1
  107. package/dist/math-font.cjs +16 -7
  108. package/dist/math-font.js +16 -7
  109. package/dist/math-table.cjs +25 -13
  110. package/dist/math-table.js +25 -13
  111. package/dist/matrix.cjs +3 -2
  112. package/dist/matrix.js +3 -2
  113. package/dist/measure.cjs +1 -1
  114. package/dist/measure.js +1 -1
  115. package/dist/navigation.cjs +10 -5
  116. package/dist/navigation.js +10 -5
  117. package/dist/ot-layout-common.cjs +4 -2
  118. package/dist/ot-layout-common.js +4 -2
  119. package/dist/parse.cjs +7 -5
  120. package/dist/parse.js +7 -5
  121. package/dist/pdf-text.cjs +5 -2
  122. package/dist/pdf-text.js +5 -2
  123. package/dist/predictors.cjs +14 -9
  124. package/dist/predictors.js +14 -9
  125. package/dist/raster.cjs +30 -19
  126. package/dist/raster.js +30 -19
  127. package/dist/read.cjs +17 -8
  128. package/dist/read.js +17 -8
  129. package/dist/serialize.cjs +6 -2
  130. package/dist/serialize.js +6 -2
  131. package/dist/sfnt-subset.cjs +25 -13
  132. package/dist/sfnt-subset.js +25 -13
  133. package/dist/sfnt.cjs +20 -10
  134. package/dist/sfnt.js +20 -10
  135. package/dist/text-group.cjs +0 -1
  136. package/dist/text-group.js +0 -1
  137. package/dist/tounicode.cjs +4 -2
  138. package/dist/tounicode.js +4 -2
  139. package/dist/winansi.cjs +1 -1
  140. package/dist/winansi.js +1 -1
  141. package/dist/write.cjs +20 -12
  142. package/dist/write.js +20 -12
  143. package/dist/xref.cjs +5 -2
  144. package/dist/xref.js +5 -2
  145. package/package.json +1 -1
@@ -3,137 +3,333 @@ const BLOCK_BYTES = 64;
3
3
  const DIGEST_BYTES = 16;
4
4
  const ROUNDS = 64;
5
5
  const WORDS_PER_BLOCK = 16;
6
- const T = new Uint32Array([
7
- 3614090360,
8
- 3905402710,
9
- 606105819,
10
- 3250441966,
11
- 4118548399,
12
- 1200080426,
13
- 2821735955,
14
- 4249261313,
15
- 1770035416,
16
- 2336552879,
17
- 4294925233,
18
- 2304563134,
19
- 1804603682,
20
- 4254626195,
21
- 2792965006,
22
- 1236535329,
23
- 4129170786,
24
- 3225465664,
25
- 643717713,
26
- 3921069994,
27
- 3593408605,
28
- 38016083,
29
- 3634488961,
30
- 3889429448,
31
- 568446438,
32
- 3275163606,
33
- 4107603335,
34
- 1163531501,
35
- 2850285829,
36
- 4243563512,
37
- 1735328473,
38
- 2368359562,
39
- 4294588738,
40
- 2272392833,
41
- 1839030562,
42
- 4259657740,
43
- 2763975236,
44
- 1272893353,
45
- 4139469664,
46
- 3200236656,
47
- 681279174,
48
- 3936430074,
49
- 3572445317,
50
- 76029189,
51
- 3654602809,
52
- 3873151461,
53
- 530742520,
54
- 3299628645,
55
- 4096336452,
56
- 1126891415,
57
- 2878612391,
58
- 4237533241,
59
- 1700485571,
60
- 2399980690,
61
- 4293915773,
62
- 2240044497,
63
- 1873313359,
64
- 4264355552,
65
- 2734768916,
66
- 1309151649,
67
- 4149444226,
68
- 3174756917,
69
- 718787259,
70
- 3951481745
71
- ]);
6
+ const STEPS_PER_ROUND = 16;
7
+ const BITS_PER_BYTE = 8;
8
+ const BYTES_PER_WORD = 4;
9
+ const BYTE_MASK = 255;
10
+ const WORD_BITS = 32;
11
+ const UINT32_MODULUS = 4294967296;
12
+ const LENGTH_FIELD_BYTES = 8;
13
+ const ROUND_2_G_MULTIPLIER = 5;
14
+ const ROUND_3_G_MULTIPLIER = 3;
15
+ const ROUND_3_G_OFFSET = 5;
16
+ const ROUND_4_G_MULTIPLIER = 7;
17
+ const ROUND_4_START = 48;
18
+ const T = Uint32Array.from([
19
+ {
20
+ i: 1,
21
+ value: 3614090360
22
+ },
23
+ {
24
+ i: 2,
25
+ value: 3905402710
26
+ },
27
+ {
28
+ i: 3,
29
+ value: 606105819
30
+ },
31
+ {
32
+ i: 4,
33
+ value: 3250441966
34
+ },
35
+ {
36
+ i: 5,
37
+ value: 4118548399
38
+ },
39
+ {
40
+ i: 6,
41
+ value: 1200080426
42
+ },
43
+ {
44
+ i: 7,
45
+ value: 2821735955
46
+ },
47
+ {
48
+ i: 8,
49
+ value: 4249261313
50
+ },
51
+ {
52
+ i: 9,
53
+ value: 1770035416
54
+ },
55
+ {
56
+ i: 10,
57
+ value: 2336552879
58
+ },
59
+ {
60
+ i: 11,
61
+ value: 4294925233
62
+ },
63
+ {
64
+ i: 12,
65
+ value: 2304563134
66
+ },
67
+ {
68
+ i: 13,
69
+ value: 1804603682
70
+ },
71
+ {
72
+ i: 14,
73
+ value: 4254626195
74
+ },
75
+ {
76
+ i: 15,
77
+ value: 2792965006
78
+ },
79
+ {
80
+ i: 16,
81
+ value: 1236535329
82
+ },
83
+ {
84
+ i: 17,
85
+ value: 4129170786
86
+ },
87
+ {
88
+ i: 18,
89
+ value: 3225465664
90
+ },
91
+ {
92
+ i: 19,
93
+ value: 643717713
94
+ },
95
+ {
96
+ i: 20,
97
+ value: 3921069994
98
+ },
99
+ {
100
+ i: 21,
101
+ value: 3593408605
102
+ },
103
+ {
104
+ i: 22,
105
+ value: 38016083
106
+ },
107
+ {
108
+ i: 23,
109
+ value: 3634488961
110
+ },
111
+ {
112
+ i: 24,
113
+ value: 3889429448
114
+ },
115
+ {
116
+ i: 25,
117
+ value: 568446438
118
+ },
119
+ {
120
+ i: 26,
121
+ value: 3275163606
122
+ },
123
+ {
124
+ i: 27,
125
+ value: 4107603335
126
+ },
127
+ {
128
+ i: 28,
129
+ value: 1163531501
130
+ },
131
+ {
132
+ i: 29,
133
+ value: 2850285829
134
+ },
135
+ {
136
+ i: 30,
137
+ value: 4243563512
138
+ },
139
+ {
140
+ i: 31,
141
+ value: 1735328473
142
+ },
143
+ {
144
+ i: 32,
145
+ value: 2368359562
146
+ },
147
+ {
148
+ i: 33,
149
+ value: 4294588738
150
+ },
151
+ {
152
+ i: 34,
153
+ value: 2272392833
154
+ },
155
+ {
156
+ i: 35,
157
+ value: 1839030562
158
+ },
159
+ {
160
+ i: 36,
161
+ value: 4259657740
162
+ },
163
+ {
164
+ i: 37,
165
+ value: 2763975236
166
+ },
167
+ {
168
+ i: 38,
169
+ value: 1272893353
170
+ },
171
+ {
172
+ i: 39,
173
+ value: 4139469664
174
+ },
175
+ {
176
+ i: 40,
177
+ value: 3200236656
178
+ },
179
+ {
180
+ i: 41,
181
+ value: 681279174
182
+ },
183
+ {
184
+ i: 42,
185
+ value: 3936430074
186
+ },
187
+ {
188
+ i: 43,
189
+ value: 3572445317
190
+ },
191
+ {
192
+ i: 44,
193
+ value: 76029189
194
+ },
195
+ {
196
+ i: 45,
197
+ value: 3654602809
198
+ },
199
+ {
200
+ i: 46,
201
+ value: 3873151461
202
+ },
203
+ {
204
+ i: 47,
205
+ value: 530742520
206
+ },
207
+ {
208
+ i: 48,
209
+ value: 3299628645
210
+ },
211
+ {
212
+ i: 49,
213
+ value: 4096336452
214
+ },
215
+ {
216
+ i: 50,
217
+ value: 1126891415
218
+ },
219
+ {
220
+ i: 51,
221
+ value: 2878612391
222
+ },
223
+ {
224
+ i: 52,
225
+ value: 4237533241
226
+ },
227
+ {
228
+ i: 53,
229
+ value: 1700485571
230
+ },
231
+ {
232
+ i: 54,
233
+ value: 2399980690
234
+ },
235
+ {
236
+ i: 55,
237
+ value: 4293915773
238
+ },
239
+ {
240
+ i: 56,
241
+ value: 2240044497
242
+ },
243
+ {
244
+ i: 57,
245
+ value: 1873313359
246
+ },
247
+ {
248
+ i: 58,
249
+ value: 4264355552
250
+ },
251
+ {
252
+ i: 59,
253
+ value: 2734768916
254
+ },
255
+ {
256
+ i: 60,
257
+ value: 1309151649
258
+ },
259
+ {
260
+ i: 61,
261
+ value: 4149444226
262
+ },
263
+ {
264
+ i: 62,
265
+ value: 3174756917
266
+ },
267
+ {
268
+ i: 63,
269
+ value: 718787259
270
+ },
271
+ {
272
+ i: 64,
273
+ value: 3951481745
274
+ }
275
+ ], (entry) => entry.value);
276
+ const S11 = 7;
277
+ const S12 = 12;
278
+ const S13 = 17;
279
+ const S14 = 22;
280
+ const S21 = 5;
281
+ const S22 = 9;
282
+ const S23 = 14;
283
+ const S24 = 20;
284
+ const S31 = 4;
285
+ const S32 = 11;
286
+ const S33 = 16;
287
+ const S34 = 23;
288
+ const S41 = 6;
289
+ const S42 = 10;
290
+ const S43 = 15;
291
+ const S44 = 21;
292
+ const ROUND_1_SHIFTS = [
293
+ S11,
294
+ S12,
295
+ S13,
296
+ S14
297
+ ];
298
+ const ROUND_2_SHIFTS = [
299
+ S21,
300
+ S22,
301
+ S23,
302
+ S24
303
+ ];
304
+ const ROUND_3_SHIFTS = [
305
+ S31,
306
+ S32,
307
+ S33,
308
+ S34
309
+ ];
310
+ const ROUND_4_SHIFTS = [
311
+ S41,
312
+ S42,
313
+ S43,
314
+ S44
315
+ ];
72
316
  const SHIFT = [
73
- 7,
74
- 12,
75
- 17,
76
- 22,
77
- 7,
78
- 12,
79
- 17,
80
- 22,
81
- 7,
82
- 12,
83
- 17,
84
- 22,
85
- 7,
86
- 12,
87
- 17,
88
- 22,
89
- 5,
90
- 9,
91
- 14,
92
- 20,
93
- 5,
94
- 9,
95
- 14,
96
- 20,
97
- 5,
98
- 9,
99
- 14,
100
- 20,
101
- 5,
102
- 9,
103
- 14,
104
- 20,
105
- 4,
106
- 11,
107
- 16,
108
- 23,
109
- 4,
110
- 11,
111
- 16,
112
- 23,
113
- 4,
114
- 11,
115
- 16,
116
- 23,
117
- 4,
118
- 11,
119
- 16,
120
- 23,
121
- 6,
122
- 10,
123
- 15,
124
- 21,
125
- 6,
126
- 10,
127
- 15,
128
- 21,
129
- 6,
130
- 10,
131
- 15,
132
- 21,
133
- 6,
134
- 10,
135
- 15,
136
- 21
317
+ ...ROUND_1_SHIFTS,
318
+ ...ROUND_1_SHIFTS,
319
+ ...ROUND_1_SHIFTS,
320
+ ...ROUND_1_SHIFTS,
321
+ ...ROUND_2_SHIFTS,
322
+ ...ROUND_2_SHIFTS,
323
+ ...ROUND_2_SHIFTS,
324
+ ...ROUND_2_SHIFTS,
325
+ ...ROUND_3_SHIFTS,
326
+ ...ROUND_3_SHIFTS,
327
+ ...ROUND_3_SHIFTS,
328
+ ...ROUND_3_SHIFTS,
329
+ ...ROUND_4_SHIFTS,
330
+ ...ROUND_4_SHIFTS,
331
+ ...ROUND_4_SHIFTS,
332
+ ...ROUND_4_SHIFTS
137
333
  ];
138
334
  const INITIAL_STATE = [
139
335
  1732584193,
@@ -142,20 +338,20 @@ const INITIAL_STATE = [
142
338
  271733878
143
339
  ];
144
340
  function rotl32(value, bits) {
145
- return (value << bits | value >>> 32 - bits) >>> 0;
341
+ return (value << bits | value >>> WORD_BITS - bits) >>> 0;
146
342
  }
147
343
  function padMessage(bytes) {
148
- const paddedLength = (Math.floor((bytes.length + 8) / BLOCK_BYTES) + 1) * BLOCK_BYTES;
344
+ const paddedLength = (Math.floor((bytes.length + LENGTH_FIELD_BYTES) / BLOCK_BYTES) + 1) * BLOCK_BYTES;
149
345
  const padded = new Uint8Array(paddedLength);
150
346
  padded.set(bytes);
151
347
  padded[bytes.length] = 128;
152
- const bitLength = bytes.length * 8;
153
- let low = bitLength % 4294967296;
154
- let high = Math.floor(bitLength / 4294967296);
155
- for (let i = 0; i < 4; i++) {
156
- padded[paddedLength - 8 + i] = low & 255;
348
+ const bitLength = bytes.length * BITS_PER_BYTE;
349
+ let low = bitLength % UINT32_MODULUS;
350
+ let high = Math.floor(bitLength / UINT32_MODULUS);
351
+ for (let i = 0; i < BYTES_PER_WORD; i++) {
352
+ padded[paddedLength - LENGTH_FIELD_BYTES + i] = low & BYTE_MASK;
157
353
  low = Math.floor(low / 256);
158
- padded[paddedLength - 4 + i] = high & 255;
354
+ padded[paddedLength - BYTES_PER_WORD + i] = high & BYTE_MASK;
159
355
  high = Math.floor(high / 256);
160
356
  }
161
357
  return padded;
@@ -166,8 +362,8 @@ function md5(bytes) {
166
362
  const block = new Uint32Array(WORDS_PER_BLOCK);
167
363
  for (let offset = 0; offset < padded.length; offset += BLOCK_BYTES) {
168
364
  for (let i = 0; i < WORDS_PER_BLOCK; i++) {
169
- const at = offset + i * 4;
170
- block[i] = (padded[at] | padded[at + 1] << 8 | padded[at + 2] << 16 | padded[at + 3] << 24) >>> 0;
365
+ const at = offset + i * BYTES_PER_WORD;
366
+ block[i] = (padded[at] | padded[at + 1] << BITS_PER_BYTE | padded[at + 2] << 16 | padded[at + 3] << 24) >>> 0;
171
367
  }
172
368
  let a = state[0];
173
369
  let b = state[1];
@@ -176,18 +372,18 @@ function md5(bytes) {
176
372
  for (let i = 0; i < ROUNDS; i++) {
177
373
  let f;
178
374
  let g;
179
- if (i < 16) {
375
+ if (i < STEPS_PER_ROUND) {
180
376
  f = b & c | ~b & d;
181
377
  g = i;
182
378
  } else if (i < 32) {
183
379
  f = d & b | ~d & c;
184
- g = (5 * i + 1) % WORDS_PER_BLOCK;
185
- } else if (i < 48) {
380
+ g = (ROUND_2_G_MULTIPLIER * i + 1) % WORDS_PER_BLOCK;
381
+ } else if (i < ROUND_4_START) {
186
382
  f = b ^ c ^ d;
187
- g = (3 * i + 5) % WORDS_PER_BLOCK;
383
+ g = (ROUND_3_G_MULTIPLIER * i + ROUND_3_G_OFFSET) % WORDS_PER_BLOCK;
188
384
  } else {
189
385
  f = c ^ (b | ~d);
190
- g = 7 * i % WORDS_PER_BLOCK;
386
+ g = ROUND_4_G_MULTIPLIER * i % WORDS_PER_BLOCK;
191
387
  }
192
388
  const rotated = rotl32(a + (f >>> 0) + T[i] + block[g] >>> 0, SHIFT[i]);
193
389
  a = d;
@@ -203,10 +399,10 @@ function md5(bytes) {
203
399
  const digest = new Uint8Array(DIGEST_BYTES);
204
400
  for (let i = 0; i < state.length; i++) {
205
401
  const word = state[i];
206
- digest[i * 4] = word & 255;
207
- digest[i * 4 + 1] = word >>> 8 & 255;
208
- digest[i * 4 + 2] = word >>> 16 & 255;
209
- digest[i * 4 + 3] = word >>> 24 & 255;
402
+ digest[i * BYTES_PER_WORD] = word & BYTE_MASK;
403
+ digest[i * BYTES_PER_WORD + 1] = word >>> BITS_PER_BYTE & BYTE_MASK;
404
+ digest[i * BYTES_PER_WORD + 2] = word >>> 16 & BYTE_MASK;
405
+ digest[i * BYTES_PER_WORD + 3] = word >>> 24 & BYTE_MASK;
210
406
  }
211
407
  return digest;
212
408
  }
@@ -1,12 +1,13 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  //#region src/crypto/rc4.ts
3
3
  const STATE_SIZE = 256;
4
+ const STATE_INDEX_MASK = 255;
4
5
  function rc4(key, data) {
5
6
  const state = Uint8Array.from({ length: STATE_SIZE }, (_, i) => i);
6
7
  if (key.length === 0) return Uint8Array.from(data);
7
8
  let j = 0;
8
9
  for (let i = 0; i < STATE_SIZE; i++) {
9
- j = j + state[i] + key[i % key.length] & 255;
10
+ j = j + state[i] + key[i % key.length] & STATE_INDEX_MASK;
10
11
  const swap = state[i];
11
12
  state[i] = state[j];
12
13
  state[j] = swap;
@@ -15,12 +16,12 @@ function rc4(key, data) {
15
16
  let x = 0;
16
17
  let y = 0;
17
18
  data.forEach((byte, n) => {
18
- x = x + 1 & 255;
19
- y = y + state[x] & 255;
19
+ x = x + 1 & STATE_INDEX_MASK;
20
+ y = y + state[x] & STATE_INDEX_MASK;
20
21
  const swap = state[x];
21
22
  state[x] = state[y];
22
23
  state[y] = swap;
23
- out[n] = byte ^ state[state[x] + state[y] & 255];
24
+ out[n] = byte ^ state[state[x] + state[y] & STATE_INDEX_MASK];
24
25
  });
25
26
  return out;
26
27
  }
@@ -1,11 +1,12 @@
1
1
  //#region src/crypto/rc4.ts
2
2
  const STATE_SIZE = 256;
3
+ const STATE_INDEX_MASK = 255;
3
4
  function rc4(key, data) {
4
5
  const state = Uint8Array.from({ length: STATE_SIZE }, (_, i) => i);
5
6
  if (key.length === 0) return Uint8Array.from(data);
6
7
  let j = 0;
7
8
  for (let i = 0; i < STATE_SIZE; i++) {
8
- j = j + state[i] + key[i % key.length] & 255;
9
+ j = j + state[i] + key[i % key.length] & STATE_INDEX_MASK;
9
10
  const swap = state[i];
10
11
  state[i] = state[j];
11
12
  state[j] = swap;
@@ -14,12 +15,12 @@ function rc4(key, data) {
14
15
  let x = 0;
15
16
  let y = 0;
16
17
  data.forEach((byte, n) => {
17
- x = x + 1 & 255;
18
- y = y + state[x] & 255;
18
+ x = x + 1 & STATE_INDEX_MASK;
19
+ y = y + state[x] & STATE_INDEX_MASK;
19
20
  const swap = state[x];
20
21
  state[x] = state[y];
21
22
  state[y] = swap;
22
- out[n] = byte ^ state[state[x] + state[y] & 255];
23
+ out[n] = byte ^ state[state[x] + state[y] & STATE_INDEX_MASK];
23
24
  });
24
25
  return out;
25
26
  }