topbit 3.0.2 → 3.0.3

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.
package/README.cn.md CHANGED
@@ -1,4 +1,4 @@
1
- ![](images/topbit.png)
1
+ ![](images/topbit.webp)
2
2
 
3
3
  # Topbit
4
4
 
package/README.md CHANGED
@@ -1,4 +1,4 @@
1
- ![](images/topbit.png)
1
+ ![](images/topbit.webp)
2
2
 
3
3
  # Topbit
4
4
 
@@ -1478,4 +1478,4 @@ app.daemon(8008, 2);
1478
1478
 
1479
1479
  **Note: Requires `loadMonitor` option (enabled by default unless set to false).**
1480
1480
 
1481
- Service initialization automatically sets configuration based on available system memory. Unless necessary, stick to default configurations.
1481
+ Service initialization automatically sets configuration based on available system memory. Unless necessary, stick to default configurations.
package/demo/sni.js CHANGED
@@ -55,5 +55,5 @@ app.post('/upload', async c => {
55
55
  }
56
56
  }, '@upload');
57
57
 
58
- app.daemon(1990, 2);
58
+ app.daemon(1990, 3);
59
59
 
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "topbit",
3
- "version": "3.0.2",
3
+ "version": "3.0.3",
4
4
  "description": "A Server-side web framework support http/1.1 and http/2",
5
5
  "main": "src/topbit.js",
6
6
  "directories": {
package/src/ext.js CHANGED
@@ -41,7 +41,7 @@ ext.makeName = function(filename = '') {
41
41
  let orgname = `${tm.getFullYear()}-${fmtbits(tm.getMonth()+1)}-${fmtbits(tm.getDate())}_`
42
42
  + `${fmtbits(tm.getHours())}-${fmtbits(tm.getMinutes())}-${fmtbits(tm.getSeconds())}`
43
43
  + `_${tm.getMilliseconds()}`
44
- + `${parseInt(Math.random() * 1000) + 1}${parseInt(Math.random() * 100000) + 10000}`
44
+ + `${((Math.random() * 1000)|0) + 1}${((Math.random() * 100000)|0) + 10000}`
45
45
 
46
46
  if (filename) return (orgname + ext.extName(filename))
47
47
 
@@ -183,14 +183,26 @@ Object.defineProperty(ext, 'algorithm', {
183
183
  *key 必须是32位
184
184
  * */
185
185
  ext.aesEncrypt = function (data, key, encoding = 'base64url') {
186
- var h = crypto.createCipheriv(__aag, key, __aesIV)
186
+ let iv = randstring(16)
187
+ let h = crypto.createCipheriv(__aag, key, iv)
187
188
  let hd = h.update(data, 'utf8', encoding)
188
189
  hd += h.final(encoding)
189
- return hd
190
+ return [iv, hd]
190
191
  }
191
192
 
192
- ext.aesDecrypt = function (data, key, encoding = 'base64url') {
193
- var h = crypto.createDecipheriv(__aag, key, __aesIV)
193
+ ext.aesDecrypt = function (org_data, key, encoding = 'base64url') {
194
+ if (!org_data) throw new Error('data is wrong');
195
+
196
+ let data, iv
197
+
198
+ if (Array.isArray(org_data)) {
199
+ [iv, data] = org_data
200
+ } else {
201
+ iv = org_data.iv
202
+ data = org_data.data
203
+ }
204
+
205
+ let h = crypto.createDecipheriv(__aag, key, iv)
194
206
  let hd = h.update(data, encoding, 'utf8')
195
207
  hd += h.final('utf8')
196
208
  return hd
@@ -259,7 +271,7 @@ ext.timestr = function (m = 'long') {
259
271
 
260
272
  ext.nrand = function (f, t) {
261
273
  let discount = t - f
262
- return parseInt((Math.random() * discount) + f)
274
+ return Math.floor((Math.random() * discount) + f)
263
275
  }
264
276
 
265
277
  let uuidSerial = makeId.serialId
@@ -24,7 +24,7 @@ class Http2Pool {
24
24
  this.connectTimeout = options.connectTimeout || 15000
25
25
 
26
26
  this.max = (options.max && !isNaN(options.max) && options.max > 0) ? options.max : 50
27
- this.poolMax = parseInt(this.max * 1.5 + 0.5)
27
+ this.poolMax = Math.floor(this.max * 1.5 + 0.5)
28
28
  this.maxConnect = (options.maxConnect && !isNaN(options.maxConnect) && options.maxConnect > 0)
29
29
  ? options.maxConnect
30
30
  : this.poolMax + 500
@@ -129,7 +129,7 @@ class Http2Pool {
129
129
  if (this.failedCount < 10) {
130
130
  this.innerConnectDelay = this.failedCount
131
131
  } if (this.failedCount < 60000) {
132
- this.innerConnectDelay = parseInt(this.failedCount / 10)
132
+ this.innerConnectDelay = Math.floor(this.failedCount / 10)
133
133
  } else { this.innerConnectDelay = 6000 }
134
134
 
135
135
  !rejected && (rejected = true) && reject(err)
@@ -170,7 +170,7 @@ class Cors {
170
170
  if (lastSlash < host.length - 1) host = host.substring(0, lastSlash+1);
171
171
  if (!host.trim()) continue;
172
172
 
173
- midIndex = parseInt(host.length / 2);
173
+ midIndex = ((host.length / 2)|0);
174
174
  midChar = host[midIndex];
175
175
 
176
176
  this.allowTable[host] = {
@@ -22,7 +22,7 @@
22
22
  *
23
23
  */
24
24
 
25
- const randstring = require('./__randstring.js')
25
+ const randstring = require('../randstring.js')
26
26
 
27
27
  const crypto = require('node:crypto')
28
28
 
@@ -80,7 +80,7 @@ class Resource {
80
80
 
81
81
  this.prepath = ''
82
82
 
83
- this.routeGroup = `__static_${parseInt(Math.random()*10000)}_`
83
+ this.routeGroup = `__static_${Math.floor(Math.random() * 10000)}_`
84
84
 
85
85
  this.decodePath = false
86
86
 
@@ -366,7 +366,7 @@ class Resource {
366
366
 
367
367
  if (self.cacheFailed >= self.failedLimit) {
368
368
  //以{self.prob}%概率决定是否释放缓存。
369
- if (parseInt(Math.random() * 100) < self.prob) {
369
+ if (((Math.random() * 100) | 0) < self.prob) {
370
370
  self.clearCache()
371
371
  }
372
372
 
@@ -32,7 +32,7 @@ class Session {
32
32
 
33
33
  this.prefix = 'titbit_sess_'
34
34
 
35
- this.sessionKey = 'TITBIT_SESSID'
35
+ this.sessionKey = 'TOPBIT_SESSID'
36
36
 
37
37
  this.error = null
38
38
 
@@ -24,7 +24,7 @@ function makeName(filename = '') {
24
24
 
25
25
  let orgname = `${tm.getFullYear()}-${fmtbits(tm.getMonth()+1)}-${fmtbits(tm.getDate())}_`
26
26
  + `${fmtbits(tm.getHours())}-${fmtbits(tm.getMinutes())}-${fmtbits(tm.getSeconds())}`
27
- + `_${tm.getMilliseconds()}${parseInt(Math.random() * 1000) + 1}${parseInt(Math.random() * 100000) + 10000}`
27
+ + `_${tm.getMilliseconds()}${((Math.random() * 1000)|0) + 1}${((Math.random() * 100000)|0) + 10000}`
28
28
 
29
29
  if (filename) return (orgname + extName(filename))
30
30
 
package/src/makeId.js CHANGED
@@ -28,7 +28,7 @@ for (let x of loopch) {
28
28
  let sloopch = msloopch.slice(0, 100)
29
29
  let yloopch = msloopch.slice(36, 500)
30
30
 
31
- msloopch = msloopch.slice(parseInt(Math.random() * 100))
31
+ msloopch = msloopch.slice(Math.floor(Math.random() * 100))
32
32
 
33
33
  let loopLength = loopch.length
34
34
  let sloopLength = sloopch.length
@@ -47,7 +47,7 @@ class Clocks {
47
47
 
48
48
  rand() {
49
49
  for (let k in this.clocks) {
50
- this.clocks[k] = parseInt(loopLength * Math.random())
50
+ this.clocks[k] = (loopLength * Math.random()) | 0
51
51
  }
52
52
  }
53
53
 
@@ -153,7 +153,7 @@ function numId(obj) {
153
153
 
154
154
  function bigId(obj, a='', b='') {
155
155
  let fnum = numId(obj)
156
- return (BigInt(fnum) * 1000n + BigInt(parseInt(Math.random() * 1000))).toString()
156
+ return (BigInt(fnum) * 1000n + BigInt((Math.random() * 1000)|0)).toString()
157
157
  }
158
158
 
159
159
  Object.defineProperty(makeId, 'numId', {
@@ -161,7 +161,7 @@ Object.defineProperty(makeId, 'numId', {
161
161
  configurable: false,
162
162
  get: function () {
163
163
  let oo = {
164
- endnum: parseInt(Math.random() * 2000)
164
+ endnum: (Math.random() * 2000) | 0
165
165
  }
166
166
 
167
167
  return numId.bind(null, oo)
@@ -173,7 +173,7 @@ Object.defineProperty(makeId, 'bigId', {
173
173
  configurable: false,
174
174
  get: function () {
175
175
  let oo = {
176
- endnum: parseInt(Math.random() * 2000)
176
+ endnum: (Math.random() * 2000) | 0
177
177
  }
178
178
 
179
179
  return bigId.bind(null, oo)
package/src/midcore.js CHANGED
@@ -18,7 +18,7 @@ class MidCore {
18
18
 
19
19
  this.globalKey = `_GLOBAL_0129_${Math.random().toString(16).substring(2)}_`;
20
20
 
21
- this.midGroup = {};
21
+ this.midGroup = Object.create(null);
22
22
 
23
23
  this.midGroup[ this.globalKey ] = [
24
24
  async (ctx) => {
package/src/monitor.js CHANGED
@@ -98,7 +98,7 @@ class Monitor {
98
98
  } else {
99
99
  //此时升温,表示负载高,不要kill多余的进程。
100
100
  if (this.cooling < this.maxCooling) {
101
- this.cooling += 20 + parseInt( Math.random() * 60 )
101
+ this.cooling += 20 + ((Math.random() * 60) | 0)
102
102
  }
103
103
  }
104
104
 
package/src/randstring.js CHANGED
@@ -1,4 +1,5 @@
1
1
  'use strict'
2
+ const crypto = require('crypto')
2
3
 
3
4
  let saltArr = [
4
5
  'a','b','c','d','e','f','g',
@@ -6,18 +7,41 @@ let saltArr = [
6
7
  'o','p','q','r','s','t','u',
7
8
  'v','w','x','y','z','1','2',
8
9
  '3','4','5','6','7','8','9'
9
- ];
10
+ ]
11
+
12
+ function secureShuffle(arr) {
13
+ const newArr = [...arr]
14
+
15
+ // Fisher-Yates 洗牌算法
16
+ for (let i = newArr.length - 1; i > 0; i--) {
17
+ // 这里只在启动时运行一次,所以用性能较慢但绝对安全的 crypto
18
+ const j = crypto.randomInt(0, i + 1)
19
+ ;[newArr[i], newArr[j]] = [newArr[j], newArr[i]]
20
+ }
21
+
22
+ return newArr
23
+ }
24
+
25
+ const fastSecretChars = secureShuffle(saltArr)
26
+ const charsLen = fastSecretChars.length
10
27
 
11
28
  module.exports = (length = 8, sarr = null) => {
12
- let saltstr = '';
13
- let ind = 0;
29
+ let saltstr = ''
30
+
31
+ // 如果用户传了自定义数组,为了兼容性不得不降级处理 (性能稍慢,逻辑不变)
32
+ if (sarr) {
33
+ const customLen = sarr.length
14
34
 
15
- let arr = sarr || saltArr;
35
+ for (let i = 0; i < length; i++) {
36
+ saltstr += sarr[(Math.random() * customLen) | 0]
37
+ }
38
+
39
+ return saltstr
40
+ }
16
41
 
17
- for(let i = 0; i < length; i++) {
18
- ind = parseInt(Math.random() * arr.length);
19
- saltstr += arr[ind];
42
+ for (let i = 0; i < length; i++) {
43
+ saltstr += fastSecretChars[(Math.random() * charsLen) | 0]
20
44
  }
21
45
 
22
- return saltstr;
23
- }
46
+ return saltstr
47
+ }
@@ -2,26 +2,7 @@
2
2
 
3
3
  const crypto = require('node:crypto')
4
4
  const {Buffer} = require('node:buffer')
5
-
6
- let _randstrList = [
7
- 'a', 'b', 'c', 'd', 'e', 'f', 'g',
8
- 'h', 'i', 'j', 'k', 'l', 'm', 'n',
9
- 'o', 'p', 'q', 'r', 's', 't', 'u',
10
- 'v', 'w', 'x', 'y', 'z',
11
-
12
- '1', '2', '3', '4', '5', '6', '7', '8', '9'
13
- ]
14
-
15
- function randstring(length = 8) {
16
- let rstr = ''
17
- let ind = 0
18
-
19
- for (let i = 0; i < length; i++) {
20
- ind = parseInt(Math.random() * _randstrList.length)
21
- rstr += _randstrList[ind]
22
- }
23
- return rstr
24
- }
5
+ const randstring = require('../randstring.js')
25
6
 
26
7
  class TopbitToken {
27
8
 
@@ -116,7 +97,7 @@ class TopbitToken {
116
97
 
117
98
  }
118
99
 
119
- _aesEncrypt(data, key, iv, options = {}) {
100
+ aesEncrypt(data, key, iv, options = {}) {
120
101
  let h = crypto.createCipheriv(this.algorithm, key, iv, options)
121
102
  let hd = h.update(data, 'utf8')
122
103
  let final_data = h.final()
@@ -127,7 +108,7 @@ class TopbitToken {
127
108
  return Buffer.concat([hd, final_data, authtag])
128
109
  }
129
110
 
130
- _aesDecrypt(data, key, iv, options = {}) {
111
+ aesDecrypt(data, key, iv, options = {}) {
131
112
  let h = crypto.createDecipheriv(this.algorithm, key, iv, options)
132
113
  if (this.isGCM) {
133
114
  let bdata = Buffer.from(data, this.tokenEncoding)
@@ -255,7 +236,7 @@ class TopbitToken {
255
236
  return ''
256
237
  }
257
238
 
258
- let ind = parseInt( Math.random() * this.tokenIds.length)
239
+ let ind = (Math.random() * this.tokenIds.length) | 0
259
240
 
260
241
  return this.tokenIds[ind]
261
242
  }
@@ -292,7 +273,7 @@ class TopbitToken {
292
273
 
293
274
  setRefresh(flag = true) {
294
275
  if (flag) {
295
- this.refresh = parseInt(this.expires / 5)
276
+ this.refresh = Math.floor(this.expires / 5)
296
277
  } else {
297
278
  this.refresh = 0
298
279
  }
@@ -325,9 +306,9 @@ class TopbitToken {
325
306
  let ikv = tokenId ? this.idKeyIV.get(tokenId) : null
326
307
 
327
308
  if (tokenId && ikv) {
328
- tk = this._aesEncrypt(JSON.stringify(userinfo), ikv.key, ikv.iv)
309
+ tk = this.aesEncrypt(JSON.stringify(userinfo), ikv.key, ikv.iv)
329
310
  } else {
330
- tk = this._aesEncrypt(JSON.stringify(userinfo), this.key, this.iv)
311
+ tk = this.aesEncrypt(JSON.stringify(userinfo), this.key, this.iv)
331
312
  }
332
313
 
333
314
  return tk.toString(this.tokenEncoding)
@@ -375,7 +356,7 @@ class TopbitToken {
375
356
  userinfo.timestamp = Date.now()
376
357
  userinfo.__tokenId__ = ikv.id
377
358
 
378
- let tk = this._aesEncrypt(JSON.stringify(userinfo), ikv.key, ikv.iv)
359
+ let tk = this.aesEncrypt(JSON.stringify(userinfo), ikv.key, ikv.iv)
379
360
 
380
361
  return tk.toString(this.tokenEncoding)
381
362
  }
@@ -394,7 +375,7 @@ class TopbitToken {
394
375
 
395
376
  verify(edata, ikv={}) {
396
377
  try {
397
- let u = this._aesDecrypt(edata, ikv.key || this.key, ikv.iv || this.iv)
378
+ let u = this.aesDecrypt(edata, ikv.key || this.key, ikv.iv || this.iv)
398
379
  let uj = JSON.parse(u)
399
380
  let tm = Date.now()
400
381
 
package/src/topbit.js CHANGED
@@ -34,6 +34,7 @@ const TopbitToken = require('./token/token.js')
34
34
  const TopbitExtends = require('./_loadExtends.js')
35
35
  const npargv = require('./lib/npargv.js')
36
36
  const zipdata = require('./lib/zipdata.js')
37
+ const ErrorLog = require('./lib/errorlog.js')
37
38
 
38
39
  let __instance__ = 0;
39
40
 
@@ -457,18 +458,14 @@ class Topbit {
457
458
  this.topmem = 4345036800;
458
459
 
459
460
  if (this.topmem >= this.totalmem) {
460
- this.topmem = parseInt(this.totalmem * 0.9);
461
+ this.topmem = Math.floor(this.totalmem * 0.9);
461
462
  }
462
463
 
463
464
  this.secure = {
464
465
  //而超过diemem则直接kill 这限制的是对heap的使用
465
- //parseInt(this.topmem * (0.5 + this.config.memFactor) )
466
466
  diemem : this.topmem,
467
-
468
- //parseInt(this.topmem * (0.5 + this.config.memFactor) )
469
- maxmem : parseInt(this.topmem * (0.5 + this.config.memFactor)),
470
-
471
- maxrss : parseInt(this.totalmem * (0.52 + this.config.memFactor) )
467
+ maxmem : Math.floor(this.topmem * (0.5 + this.config.memFactor)),
468
+ maxrss : Math.floor(this.totalmem * (0.52 + this.config.memFactor) )
472
469
  };
473
470
 
474
471
  //运行时服务,需要在全局添加一些服务插件可以放在此处。
@@ -1226,7 +1223,7 @@ class Topbit {
1226
1223
  //根据num设定secure的内存限制。
1227
1224
  if (num > 1) {
1228
1225
  for (let k in this.secure) {
1229
- this.secure[k] = parseInt(this.secure[k] * (0.45 + 1 / num));
1226
+ this.secure[k] = Math.floor(this.secure[k] * (0.56 + 1 / num));
1230
1227
  }
1231
1228
  }
1232
1229
 
@@ -1288,6 +1285,7 @@ Topbit.Loader = TopbitLoader;
1288
1285
  Topbit.Token = TopbitToken;
1289
1286
  Topbit.npargv = npargv;
1290
1287
  Topbit.zipdata = zipdata;
1288
+ Topbit.ErrorLog = ErrorLog;
1291
1289
  Topbit.extensions = TopbitExtends;
1292
1290
 
1293
1291
  module.exports = Topbit;
@@ -0,0 +1,35 @@
1
+ 'use strict'
2
+
3
+ const longId = require('../src/makeId').serialId
4
+ const longId2 = require('../src/makeId').numId
5
+ const longId3 = require('../src/makeId').bigId
6
+ const longId4 = require('../src/makeId').serialId
7
+
8
+ let tid = {}
9
+ let id
10
+ let id2
11
+ let count = 0
12
+
13
+ function check(id) {
14
+ if (tid[id]) {
15
+ console.log(id, ++count)
16
+ return true
17
+ }
18
+ //console.log(id, typeof id)
19
+
20
+ tid[id] = true
21
+ return false
22
+ }
23
+
24
+ console.time('longid')
25
+
26
+ for (let i = 0; i < 1000000; i++) {
27
+ id = longId()
28
+ id2 = longId2(14)
29
+ check(id)
30
+ check(id2)
31
+ check(longId3())
32
+ check(longId4())
33
+ }
34
+
35
+ console.timeEnd('longid')
@@ -0,0 +1,44 @@
1
+ // benchmark.js
2
+ const generateSalt = require('../src/randstring.js');
3
+ const { performance } = require('perf_hooks');
4
+
5
+ const ITERATIONS = 1000000; // 100万次
6
+ const SALT_LENGTH = 16; // 生成 8 位
7
+
8
+ console.log('========================================');
9
+ console.log(`性能测试开始`);
10
+ console.log(`目标: 生成 ${ITERATIONS.toLocaleString()} 次, 长度 ${SALT_LENGTH}`);
11
+ console.log('========================================');
12
+
13
+ // 1. 预热 (Warm-up)
14
+ // 让 V8 引擎的 JIT (Just-In-Time) 编译器介入,把热点代码编译成机器码
15
+ // 这样测出来的才是服务器稳定运行时的真实性能
16
+ for(let i = 0; i < 10000; i++) {
17
+ generateSalt(SALT_LENGTH);
18
+ }
19
+ console.log('预热完成,开始计时...');
20
+
21
+ // 2. 正式测试
22
+ const startTime = performance.now();
23
+
24
+ for (let i = 0; i < ITERATIONS; i++) {
25
+ generateSalt(SALT_LENGTH);
26
+ }
27
+
28
+ const endTime = performance.now();
29
+
30
+ // 3. 计算结果
31
+ const totalTimeMs = endTime - startTime;
32
+ const qps = Math.floor(ITERATIONS / (totalTimeMs / 1000));
33
+
34
+ // 4. 验证一次输出 (确保功能正常)
35
+ const sample = generateSalt(SALT_LENGTH);
36
+
37
+ console.log('\n测试结果:');
38
+ console.log(`----------------------------------------`);
39
+ console.log(`总耗时 : ${totalTimeMs.toFixed(2)} ms`);
40
+ console.log(`平均耗时 : ${(totalTimeMs / ITERATIONS).toFixed(6)} ms/次`);
41
+ console.log(`QPS : ${qps.toLocaleString()} 次/秒`);
42
+ console.log(`----------------------------------------`);
43
+ console.log(`生成的样例: ${sample}`);
44
+ console.log('========================================');
@@ -0,0 +1,101 @@
1
+ 'use strict'
2
+
3
+ const token = require('../src/token/token.js')
4
+
5
+ const tok = new token({
6
+ urlencoded : true,
7
+ alg: 'aes-256-gcm'
8
+ })
9
+
10
+ console.log(tok.iv, tok.key)
11
+
12
+ //tok.setExpires(1)
13
+
14
+ tok.setEncoding('base64url')
15
+
16
+ let tidlist = ['t1','t2','t3','t4']
17
+
18
+ tok.addTokenId(tidlist)
19
+
20
+ tok.setMapId('tit')
21
+
22
+ let info = {
23
+ id : 1001,
24
+ name : 'brave'
25
+ }
26
+ console.log('加密处理···')
27
+ let edata = tok.make(info)
28
+
29
+ console.log('解密处理···')
30
+ let realData = tok.verify(edata)
31
+
32
+ console.log(edata)
33
+ console.log(realData)
34
+
35
+ let edataList = []
36
+
37
+ console.log('测试随机tokenId加密')
38
+ for (let i = 0 ; i < 10; i++) {
39
+ edata = tok.make(info)
40
+ edataList.push(edata)
41
+ }
42
+
43
+ if ( parseInt(Math.random() * 10) > 5 ) {
44
+ tok.removeTokenId('t2')
45
+ tok.removeTokenId('t3')
46
+ }
47
+
48
+ console.log('测试随机tokenId解密')
49
+ for (let i = 0; i < 10; i++) {
50
+ realData = tok.verify(edataList[i])
51
+ console.log(realData)
52
+ }
53
+
54
+ edata = tok.makeAccessToken(info, 'tit')
55
+ console.log(edata)
56
+
57
+ console.log(tok.verifyAccessToken(edata))
58
+
59
+ let total = 100000
60
+
61
+ tok.setIdKeyIv('xyz','qazxswedcfvrgthynujmkiolp0987654', 'qawsedrftgyhujik')
62
+ tok.setIdKeyIv('io', 'qazxswedcfvrgthynujmkiolp0e24565', 'qawsedrftgyhujik')
63
+ tok.setIdKeyIv('cd', 'qazxswedcfvrgthynujmkiolpr5tf765', 'qawsedrftgyhujie')
64
+ tok.setIdKeyIv('mk', 'qazxswedcfvrgthynujmkiolpw347f65', 'qawsedrftgyhujir')
65
+
66
+ let ikv = {
67
+ id : 'io',
68
+ key : tok.fixKey('qazxswedcfvrgthynujmkiolp0e24565'),
69
+ iv : 'qawsedrftgyhujik'
70
+ }
71
+ edata = tok.makeikv(info, ikv)
72
+
73
+ realData = tok.verifyikv(edata, ikv)
74
+
75
+ console.log('rand iv key token', tok.randIvToken(info))
76
+
77
+ console.log('--IKV-TEST--:', edata, realData)
78
+
79
+ console.log('测试指定key和iv', total, '次加解密性能')
80
+
81
+ let st = Date.now()
82
+
83
+ for (let i = 0; i < total; i++) {
84
+ //edata = tok.make(info, 'xyz')
85
+ //realData = tok.verify(edata, 'qazxswedcfvrgthynujmkiolp0987654', 'qawsedrftgyhujik', 'xyz')
86
+ //realData = tok.verifyId(edata, 'xyz')
87
+
88
+ //edata = tok.make(info, 'io')
89
+ //realData = tok.verifyid(edata, 'io')
90
+ //console.log(edata, realData)
91
+ info.expires = i % 7 ? i : '122133sdaf'
92
+ edata = tok.randIvToken(info)
93
+ realData = tok.verifyikv(edata.token, edata)
94
+ //console.log(edata, realData)
95
+ }
96
+
97
+ let et = Date.now()
98
+
99
+ console.log(et - st, 'ms')
100
+
101
+ console.log(tok.randIvToken(info))
package/images/topbit.png DELETED
Binary file
@@ -1,24 +0,0 @@
1
- 'use strict'
2
-
3
- let saltArr = [
4
- 'a','b','c','d','e','f','g',
5
- 'h','i','j','k','l','m','n',
6
- 'o','p','q','r','s','t','u',
7
- 'v','w','x','y','z','1','2',
8
- '3','4','5','6','7','8','9'
9
- ]
10
-
11
- function randstring (length = 8) {
12
-
13
- let saltstr = ''
14
- let ind = 0
15
-
16
- for(let i = 0; i < length; i++) {
17
- ind = parseInt( Math.random() * saltArr.length)
18
- saltstr += saltArr[ ind ]
19
- }
20
-
21
- return saltstr
22
- }
23
-
24
- module.exports = randstring
File without changes