node-firebird 2.3.3 → 2.4.0

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 (109) hide show
  1. package/README.md +544 -6
  2. package/lib/callback.d.ts +20 -0
  3. package/lib/callback.js +6 -16
  4. package/lib/firebird.msg.json +1370 -1370
  5. package/lib/gdscodes.d.ts +1519 -1520
  6. package/lib/gdscodes.js +5 -5
  7. package/lib/ieee754-decimal.d.ts +38 -0
  8. package/lib/ieee754-decimal.js +71 -118
  9. package/lib/index.d.ts +37 -338
  10. package/lib/index.js +97 -86
  11. package/lib/messages.d.ts +6 -0
  12. package/lib/messages.js +135 -162
  13. package/lib/pool.d.ts +23 -0
  14. package/lib/pool.js +34 -47
  15. package/lib/srp.d.ts +51 -0
  16. package/lib/srp.js +62 -72
  17. package/lib/types.d.ts +375 -0
  18. package/lib/types.js +22 -0
  19. package/lib/unix-crypt.d.ts +1 -0
  20. package/lib/unix-crypt.js +126 -152
  21. package/lib/utils.d.ts +16 -0
  22. package/lib/utils.js +24 -48
  23. package/lib/wire/connection.d.ts +100 -0
  24. package/lib/wire/connection.js +1029 -1009
  25. package/lib/wire/const.d.ts +567 -0
  26. package/lib/wire/const.js +620 -599
  27. package/lib/wire/database.d.ts +57 -0
  28. package/lib/wire/database.js +111 -108
  29. package/lib/wire/eventConnection.d.ts +16 -0
  30. package/lib/wire/eventConnection.js +29 -31
  31. package/lib/wire/fbEventManager.d.ts +45 -0
  32. package/lib/wire/fbEventManager.js +38 -57
  33. package/lib/wire/serialize.d.ts +97 -0
  34. package/lib/wire/serialize.js +42 -141
  35. package/lib/wire/service.d.ts +66 -0
  36. package/lib/wire/service.js +374 -401
  37. package/lib/wire/socket.d.ts +59 -0
  38. package/lib/wire/socket.js +79 -40
  39. package/lib/wire/statement.d.ts +25 -0
  40. package/lib/wire/statement.js +13 -9
  41. package/lib/wire/transaction.d.ts +21 -0
  42. package/lib/wire/transaction.js +33 -61
  43. package/lib/wire/xsqlvar.d.ts +175 -0
  44. package/lib/wire/xsqlvar.js +169 -269
  45. package/package.json +12 -4
  46. package/src/callback.ts +55 -0
  47. package/{poc/node_modules/node-firebird/lib/gdscodes.js → src/gdscodes.ts} +3 -3
  48. package/{poc/node_modules/node-firebird/lib/ieee754-decimal.js → src/ieee754-decimal.ts} +7 -14
  49. package/src/index.ts +157 -0
  50. package/{poc/node_modules/node-firebird/lib/messages.js → src/messages.ts} +163 -162
  51. package/src/pool.ts +209 -0
  52. package/{poc/node_modules/node-firebird/lib/srp.js → src/srp.ts} +74 -33
  53. package/src/types.ts +419 -0
  54. package/{poc/node_modules/node-firebird/lib/unix-crypt.js → src/unix-crypt.ts} +6 -12
  55. package/{poc/node_modules/node-firebird/lib/utils.js → src/utils.ts} +11 -20
  56. package/{poc/node_modules/node-firebird/lib/wire/connection.js → src/wire/connection.ts} +611 -129
  57. package/{poc/node_modules/node-firebird/lib/wire/const.js → src/wire/const.ts} +96 -9
  58. package/{poc/node_modules/node-firebird/lib/wire/database.js → src/wire/database.ts} +110 -44
  59. package/{poc/node_modules/node-firebird/lib/wire/eventConnection.js → src/wire/eventConnection.ts} +29 -14
  60. package/{poc/node_modules/node-firebird/lib/wire/fbEventManager.js → src/wire/fbEventManager.ts} +39 -30
  61. package/{poc/node_modules/node-firebird/lib/wire/serialize.js → src/wire/serialize.ts} +78 -59
  62. package/{poc/node_modules/node-firebird/lib/wire/service.js → src/wire/service.ts} +90 -88
  63. package/src/wire/socket.ts +262 -0
  64. package/src/wire/statement.ts +71 -0
  65. package/{poc/node_modules/node-firebird/lib/wire/transaction.js → src/wire/transaction.ts} +25 -19
  66. package/{poc/node_modules/node-firebird/lib/wire/xsqlvar.js → src/wire/xsqlvar.ts} +244 -143
  67. package/.eslintrc.json +0 -12
  68. package/.github/workflows/codeql.yml +0 -76
  69. package/.github/workflows/node.js.yml +0 -95
  70. package/BIGINT_MIGRATION.md +0 -374
  71. package/CI_DEBUGGING_GUIDE.md +0 -148
  72. package/ENCRYPTION_CALLBACK.md +0 -152
  73. package/FIREBIRD_LOG_FEATURE.md +0 -145
  74. package/MINIMAL_CHANGES_SUMMARY.md +0 -136
  75. package/PR_SUMMARY.md +0 -96
  76. package/ROADMAP.md +0 -223
  77. package/SRP_PROTOCOL.md +0 -482
  78. package/poc/README.md +0 -160
  79. package/poc/helpers.js +0 -59
  80. package/poc/node_modules/.package-lock.json +0 -14
  81. package/poc/node_modules/node-firebird/.eslintrc.json +0 -12
  82. package/poc/node_modules/node-firebird/.github/workflows/codeql.yml +0 -76
  83. package/poc/node_modules/node-firebird/.github/workflows/node.js.yml +0 -95
  84. package/poc/node_modules/node-firebird/BIGINT_MIGRATION.md +0 -374
  85. package/poc/node_modules/node-firebird/CI_DEBUGGING_GUIDE.md +0 -148
  86. package/poc/node_modules/node-firebird/ENCRYPTION_CALLBACK.md +0 -152
  87. package/poc/node_modules/node-firebird/FIREBIRD_LOG_FEATURE.md +0 -145
  88. package/poc/node_modules/node-firebird/LICENSE +0 -373
  89. package/poc/node_modules/node-firebird/MINIMAL_CHANGES_SUMMARY.md +0 -136
  90. package/poc/node_modules/node-firebird/PR_SUMMARY.md +0 -96
  91. package/poc/node_modules/node-firebird/README.md +0 -794
  92. package/poc/node_modules/node-firebird/ROADMAP.md +0 -223
  93. package/poc/node_modules/node-firebird/SRP_PROTOCOL.md +0 -482
  94. package/poc/node_modules/node-firebird/lib/callback.js +0 -38
  95. package/poc/node_modules/node-firebird/lib/gdscodes.d.ts +0 -1524
  96. package/poc/node_modules/node-firebird/lib/index.d.ts +0 -316
  97. package/poc/node_modules/node-firebird/lib/index.js +0 -128
  98. package/poc/node_modules/node-firebird/lib/pool.js +0 -108
  99. package/poc/node_modules/node-firebird/lib/wire/socket.js +0 -175
  100. package/poc/node_modules/node-firebird/lib/wire/statement.js +0 -48
  101. package/poc/node_modules/node-firebird/package.json +0 -38
  102. package/poc/node_modules/node-firebird/vitest.config.js +0 -24
  103. package/poc/package-lock.json +0 -21
  104. package/poc/package.json +0 -12
  105. package/poc/reproduce-fixed.js +0 -150
  106. package/poc/reproduce.js +0 -133
  107. package/vitest.config.js +0 -27
  108. /package/{poc/node_modules/node-firebird/lib → src}/firebird.msg +0 -0
  109. /package/{poc/node_modules/node-firebird/lib → src}/firebird.msg.json +0 -0
package/lib/types.js ADDED
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ // Public API type definitions for node-firebird.
3
+ //
4
+ // These types were previously maintained by hand in lib/index.d.ts
5
+ // (originally contributed by Marco Warm <https://github.com/MarcusCalidus>).
6
+ // They now live in the TypeScript source tree and are compiled into the
7
+ // published declaration files.
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.ShutdownKind = exports.ShutdownMode = void 0;
10
+ var ShutdownMode;
11
+ (function (ShutdownMode) {
12
+ ShutdownMode[ShutdownMode["NORMAL"] = 0] = "NORMAL";
13
+ ShutdownMode[ShutdownMode["MULTI"] = 1] = "MULTI";
14
+ ShutdownMode[ShutdownMode["SINGLE"] = 2] = "SINGLE";
15
+ ShutdownMode[ShutdownMode["FULL"] = 3] = "FULL";
16
+ })(ShutdownMode || (exports.ShutdownMode = ShutdownMode = {}));
17
+ var ShutdownKind;
18
+ (function (ShutdownKind) {
19
+ ShutdownKind[ShutdownKind["FORCED"] = 0] = "FORCED";
20
+ ShutdownKind[ShutdownKind["DENY_TRANSACTION"] = 1] = "DENY_TRANSACTION";
21
+ ShutdownKind[ShutdownKind["DENY_ATTACHMENT"] = 2] = "DENY_ATTACHMENT";
22
+ })(ShutdownKind || (exports.ShutdownKind = ShutdownKind = {}));
@@ -0,0 +1 @@
1
+ export declare function crypt(original: string | Buffer, salt: string): string;
package/lib/unix-crypt.js CHANGED
@@ -1,4 +1,5 @@
1
- /*
1
+ "use strict";
2
+ /*
2
3
  Licensed to the Apache Software Foundation (ASF) under one or more
3
4
  contributor license agreements. See the NOTICE file distributed with
4
5
  this work for additional information regarding copyright ownership.
@@ -19,7 +20,8 @@ This code was originally made available in the Apache Codec API.
19
20
  http://commons.apache.org/proper/commons-codec/
20
21
 
21
22
  */
22
-
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.crypt = crypt;
23
25
  var CON_SALT = [
24
26
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
25
27
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 5, 6,
@@ -27,149 +29,140 @@ var CON_SALT = [
27
29
  34, 35, 36, 37, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53,
28
30
  54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 0, 0, 0, 0, 0
29
31
  ];
30
-
31
- var COV2CHAR = [ 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70,
32
+ var COV2CHAR = [46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 65, 66, 67, 68, 69, 70,
32
33
  71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 97, 98, 99, 100, 101, 102,
33
34
  103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122
34
35
  ];
35
-
36
- var SHIFT2 = [ false, false, true, true, true, true, true, true, false, true, true, true, true, true, true, false ];
37
-
36
+ var SHIFT2 = [false, false, true, true, true, true, true, true, false, true, true, true, true, true, true, false];
38
37
  var SKB = [
39
- [ 0, 16, 0x20000000, 0x20000010, 0x10000, 0x10010, 0x20010000, 0x20010010, 2048, 2064, 0x20000800,
40
- 0x20000810, 0x10800, 0x10810, 0x20010800, 0x20010810, 32, 48, 0x20000020, 0x20000030, 0x10020,
41
- 0x10030, 0x20010020, 0x20010030, 2080, 2096, 0x20000820, 0x20000830, 0x10820, 0x10830, 0x20010820,
42
- 0x20010830, 0x80000, 0x80010, 0x20080000, 0x20080010, 0x90000, 0x90010, 0x20090000, 0x20090010,
43
- 0x80800, 0x80810, 0x20080800, 0x20080810, 0x90800, 0x90810, 0x20090800, 0x20090810, 0x80020,
44
- 0x80030, 0x20080020, 0x20080030, 0x90020, 0x90030, 0x20090020, 0x20090030, 0x80820, 0x80830,
45
- 0x20080820, 0x20080830, 0x90820, 0x90830, 0x20090820, 0x20090830 ],
46
- [ 0, 0x2000000, 8192, 0x2002000, 0x200000, 0x2200000, 0x202000, 0x2202000, 4, 0x2000004, 8196, 0x2002004,
47
- 0x200004, 0x2200004, 0x202004, 0x2202004, 1024, 0x2000400, 9216, 0x2002400, 0x200400, 0x2200400,
48
- 0x202400, 0x2202400, 1028, 0x2000404, 9220, 0x2002404, 0x200404, 0x2200404, 0x202404, 0x2202404,
49
- 0x10000000, 0x12000000, 0x10002000, 0x12002000, 0x10200000, 0x12200000, 0x10202000, 0x12202000,
50
- 0x10000004, 0x12000004, 0x10002004, 0x12002004, 0x10200004, 0x12200004, 0x10202004, 0x12202004,
51
- 0x10000400, 0x12000400, 0x10002400, 0x12002400, 0x10200400, 0x12200400, 0x10202400, 0x12202400,
52
- 0x10000404, 0x12000404, 0x10002404, 0x12002404, 0x10200404, 0x12200404, 0x10202404, 0x12202404 ],
53
- [ 0, 1, 0x40000, 0x40001, 0x1000000, 0x1000001, 0x1040000, 0x1040001, 2, 3, 0x40002, 0x40003, 0x1000002,
54
- 0x1000003, 0x1040002, 0x1040003, 512, 513, 0x40200, 0x40201, 0x1000200, 0x1000201, 0x1040200,
55
- 0x1040201, 514, 515, 0x40202, 0x40203, 0x1000202, 0x1000203, 0x1040202, 0x1040203, 0x8000000,
56
- 0x8000001, 0x8040000, 0x8040001, 0x9000000, 0x9000001, 0x9040000, 0x9040001, 0x8000002, 0x8000003,
57
- 0x8040002, 0x8040003, 0x9000002, 0x9000003, 0x9040002, 0x9040003, 0x8000200, 0x8000201, 0x8040200,
58
- 0x8040201, 0x9000200, 0x9000201, 0x9040200, 0x9040201, 0x8000202, 0x8000203, 0x8040202, 0x8040203,
59
- 0x9000202, 0x9000203, 0x9040202, 0x9040203 ],
60
- [ 0, 0x100000, 256, 0x100100, 8, 0x100008, 264, 0x100108, 4096, 0x101000, 4352, 0x101100, 4104, 0x101008,
61
- 4360, 0x101108, 0x4000000, 0x4100000, 0x4000100, 0x4100100, 0x4000008, 0x4100008, 0x4000108,
62
- 0x4100108, 0x4001000, 0x4101000, 0x4001100, 0x4101100, 0x4001008, 0x4101008, 0x4001108, 0x4101108,
63
- 0x20000, 0x120000, 0x20100, 0x120100, 0x20008, 0x120008, 0x20108, 0x120108, 0x21000, 0x121000,
64
- 0x21100, 0x121100, 0x21008, 0x121008, 0x21108, 0x121108, 0x4020000, 0x4120000, 0x4020100,
65
- 0x4120100, 0x4020008, 0x4120008, 0x4020108, 0x4120108, 0x4021000, 0x4121000, 0x4021100, 0x4121100,
66
- 0x4021008, 0x4121008, 0x4021108, 0x4121108 ],
67
- [ 0, 0x10000000, 0x10000, 0x10010000, 4, 0x10000004, 0x10004, 0x10010004, 0x20000000, 0x30000000,
68
- 0x20010000, 0x30010000, 0x20000004, 0x30000004, 0x20010004, 0x30010004, 0x100000, 0x10100000,
69
- 0x110000, 0x10110000, 0x100004, 0x10100004, 0x110004, 0x10110004, 0x20100000, 0x30100000,
70
- 0x20110000, 0x30110000, 0x20100004, 0x30100004, 0x20110004, 0x30110004, 4096, 0x10001000, 0x11000,
71
- 0x10011000, 4100, 0x10001004, 0x11004, 0x10011004, 0x20001000, 0x30001000, 0x20011000, 0x30011000,
72
- 0x20001004, 0x30001004, 0x20011004, 0x30011004, 0x101000, 0x10101000, 0x111000, 0x10111000,
73
- 0x101004, 0x10101004, 0x111004, 0x10111004, 0x20101000, 0x30101000, 0x20111000, 0x30111000,
74
- 0x20101004, 0x30101004, 0x20111004, 0x30111004 ],
75
- [ 0, 0x8000000, 8, 0x8000008, 1024, 0x8000400, 1032, 0x8000408, 0x20000, 0x8020000, 0x20008, 0x8020008,
76
- 0x20400, 0x8020400, 0x20408, 0x8020408, 1, 0x8000001, 9, 0x8000009, 1025, 0x8000401, 1033,
77
- 0x8000409, 0x20001, 0x8020001, 0x20009, 0x8020009, 0x20401, 0x8020401, 0x20409, 0x8020409,
78
- 0x2000000, 0xa000000, 0x2000008, 0xa000008, 0x2000400, 0xa000400, 0x2000408, 0xa000408, 0x2020000,
79
- 0xa020000, 0x2020008, 0xa020008, 0x2020400, 0xa020400, 0x2020408, 0xa020408, 0x2000001, 0xa000001,
80
- 0x2000009, 0xa000009, 0x2000401, 0xa000401, 0x2000409, 0xa000409, 0x2020001, 0xa020001, 0x2020009,
81
- 0xa020009, 0x2020401, 0xa020401, 0x2020409, 0xa020409 ],
82
- [ 0, 256, 0x80000, 0x80100, 0x1000000, 0x1000100, 0x1080000, 0x1080100, 16, 272, 0x80010, 0x80110,
83
- 0x1000010, 0x1000110, 0x1080010, 0x1080110, 0x200000, 0x200100, 0x280000, 0x280100, 0x1200000,
84
- 0x1200100, 0x1280000, 0x1280100, 0x200010, 0x200110, 0x280010, 0x280110, 0x1200010, 0x1200110,
85
- 0x1280010, 0x1280110, 512, 768, 0x80200, 0x80300, 0x1000200, 0x1000300, 0x1080200, 0x1080300, 528,
86
- 784, 0x80210, 0x80310, 0x1000210, 0x1000310, 0x1080210, 0x1080310, 0x200200, 0x200300, 0x280200,
87
- 0x280300, 0x1200200, 0x1200300, 0x1280200, 0x1280300, 0x200210, 0x200310, 0x280210, 0x280310,
88
- 0x1200210, 0x1200310, 0x1280210, 0x1280310 ],
89
- [ 0, 0x4000000, 0x40000, 0x4040000, 2, 0x4000002, 0x40002, 0x4040002, 8192, 0x4002000, 0x42000, 0x4042000,
90
- 8194, 0x4002002, 0x42002, 0x4042002, 32, 0x4000020, 0x40020, 0x4040020, 34, 0x4000022, 0x40022,
91
- 0x4040022, 8224, 0x4002020, 0x42020, 0x4042020, 8226, 0x4002022, 0x42022, 0x4042022, 2048,
92
- 0x4000800, 0x40800, 0x4040800, 2050, 0x4000802, 0x40802, 0x4040802, 10240, 0x4002800, 0x42800,
93
- 0x4042800, 10242, 0x4002802, 0x42802, 0x4042802, 2080, 0x4000820, 0x40820, 0x4040820, 2082,
94
- 0x4000822, 0x40822, 0x4040822, 10272, 0x4002820, 0x42820, 0x4042820, 10274, 0x4002822, 0x42822,
95
- 0x4042822 ]
38
+ [0, 16, 0x20000000, 0x20000010, 0x10000, 0x10010, 0x20010000, 0x20010010, 2048, 2064, 0x20000800,
39
+ 0x20000810, 0x10800, 0x10810, 0x20010800, 0x20010810, 32, 48, 0x20000020, 0x20000030, 0x10020,
40
+ 0x10030, 0x20010020, 0x20010030, 2080, 2096, 0x20000820, 0x20000830, 0x10820, 0x10830, 0x20010820,
41
+ 0x20010830, 0x80000, 0x80010, 0x20080000, 0x20080010, 0x90000, 0x90010, 0x20090000, 0x20090010,
42
+ 0x80800, 0x80810, 0x20080800, 0x20080810, 0x90800, 0x90810, 0x20090800, 0x20090810, 0x80020,
43
+ 0x80030, 0x20080020, 0x20080030, 0x90020, 0x90030, 0x20090020, 0x20090030, 0x80820, 0x80830,
44
+ 0x20080820, 0x20080830, 0x90820, 0x90830, 0x20090820, 0x20090830],
45
+ [0, 0x2000000, 8192, 0x2002000, 0x200000, 0x2200000, 0x202000, 0x2202000, 4, 0x2000004, 8196, 0x2002004,
46
+ 0x200004, 0x2200004, 0x202004, 0x2202004, 1024, 0x2000400, 9216, 0x2002400, 0x200400, 0x2200400,
47
+ 0x202400, 0x2202400, 1028, 0x2000404, 9220, 0x2002404, 0x200404, 0x2200404, 0x202404, 0x2202404,
48
+ 0x10000000, 0x12000000, 0x10002000, 0x12002000, 0x10200000, 0x12200000, 0x10202000, 0x12202000,
49
+ 0x10000004, 0x12000004, 0x10002004, 0x12002004, 0x10200004, 0x12200004, 0x10202004, 0x12202004,
50
+ 0x10000400, 0x12000400, 0x10002400, 0x12002400, 0x10200400, 0x12200400, 0x10202400, 0x12202400,
51
+ 0x10000404, 0x12000404, 0x10002404, 0x12002404, 0x10200404, 0x12200404, 0x10202404, 0x12202404],
52
+ [0, 1, 0x40000, 0x40001, 0x1000000, 0x1000001, 0x1040000, 0x1040001, 2, 3, 0x40002, 0x40003, 0x1000002,
53
+ 0x1000003, 0x1040002, 0x1040003, 512, 513, 0x40200, 0x40201, 0x1000200, 0x1000201, 0x1040200,
54
+ 0x1040201, 514, 515, 0x40202, 0x40203, 0x1000202, 0x1000203, 0x1040202, 0x1040203, 0x8000000,
55
+ 0x8000001, 0x8040000, 0x8040001, 0x9000000, 0x9000001, 0x9040000, 0x9040001, 0x8000002, 0x8000003,
56
+ 0x8040002, 0x8040003, 0x9000002, 0x9000003, 0x9040002, 0x9040003, 0x8000200, 0x8000201, 0x8040200,
57
+ 0x8040201, 0x9000200, 0x9000201, 0x9040200, 0x9040201, 0x8000202, 0x8000203, 0x8040202, 0x8040203,
58
+ 0x9000202, 0x9000203, 0x9040202, 0x9040203],
59
+ [0, 0x100000, 256, 0x100100, 8, 0x100008, 264, 0x100108, 4096, 0x101000, 4352, 0x101100, 4104, 0x101008,
60
+ 4360, 0x101108, 0x4000000, 0x4100000, 0x4000100, 0x4100100, 0x4000008, 0x4100008, 0x4000108,
61
+ 0x4100108, 0x4001000, 0x4101000, 0x4001100, 0x4101100, 0x4001008, 0x4101008, 0x4001108, 0x4101108,
62
+ 0x20000, 0x120000, 0x20100, 0x120100, 0x20008, 0x120008, 0x20108, 0x120108, 0x21000, 0x121000,
63
+ 0x21100, 0x121100, 0x21008, 0x121008, 0x21108, 0x121108, 0x4020000, 0x4120000, 0x4020100,
64
+ 0x4120100, 0x4020008, 0x4120008, 0x4020108, 0x4120108, 0x4021000, 0x4121000, 0x4021100, 0x4121100,
65
+ 0x4021008, 0x4121008, 0x4021108, 0x4121108],
66
+ [0, 0x10000000, 0x10000, 0x10010000, 4, 0x10000004, 0x10004, 0x10010004, 0x20000000, 0x30000000,
67
+ 0x20010000, 0x30010000, 0x20000004, 0x30000004, 0x20010004, 0x30010004, 0x100000, 0x10100000,
68
+ 0x110000, 0x10110000, 0x100004, 0x10100004, 0x110004, 0x10110004, 0x20100000, 0x30100000,
69
+ 0x20110000, 0x30110000, 0x20100004, 0x30100004, 0x20110004, 0x30110004, 4096, 0x10001000, 0x11000,
70
+ 0x10011000, 4100, 0x10001004, 0x11004, 0x10011004, 0x20001000, 0x30001000, 0x20011000, 0x30011000,
71
+ 0x20001004, 0x30001004, 0x20011004, 0x30011004, 0x101000, 0x10101000, 0x111000, 0x10111000,
72
+ 0x101004, 0x10101004, 0x111004, 0x10111004, 0x20101000, 0x30101000, 0x20111000, 0x30111000,
73
+ 0x20101004, 0x30101004, 0x20111004, 0x30111004],
74
+ [0, 0x8000000, 8, 0x8000008, 1024, 0x8000400, 1032, 0x8000408, 0x20000, 0x8020000, 0x20008, 0x8020008,
75
+ 0x20400, 0x8020400, 0x20408, 0x8020408, 1, 0x8000001, 9, 0x8000009, 1025, 0x8000401, 1033,
76
+ 0x8000409, 0x20001, 0x8020001, 0x20009, 0x8020009, 0x20401, 0x8020401, 0x20409, 0x8020409,
77
+ 0x2000000, 0xa000000, 0x2000008, 0xa000008, 0x2000400, 0xa000400, 0x2000408, 0xa000408, 0x2020000,
78
+ 0xa020000, 0x2020008, 0xa020008, 0x2020400, 0xa020400, 0x2020408, 0xa020408, 0x2000001, 0xa000001,
79
+ 0x2000009, 0xa000009, 0x2000401, 0xa000401, 0x2000409, 0xa000409, 0x2020001, 0xa020001, 0x2020009,
80
+ 0xa020009, 0x2020401, 0xa020401, 0x2020409, 0xa020409],
81
+ [0, 256, 0x80000, 0x80100, 0x1000000, 0x1000100, 0x1080000, 0x1080100, 16, 272, 0x80010, 0x80110,
82
+ 0x1000010, 0x1000110, 0x1080010, 0x1080110, 0x200000, 0x200100, 0x280000, 0x280100, 0x1200000,
83
+ 0x1200100, 0x1280000, 0x1280100, 0x200010, 0x200110, 0x280010, 0x280110, 0x1200010, 0x1200110,
84
+ 0x1280010, 0x1280110, 512, 768, 0x80200, 0x80300, 0x1000200, 0x1000300, 0x1080200, 0x1080300, 528,
85
+ 784, 0x80210, 0x80310, 0x1000210, 0x1000310, 0x1080210, 0x1080310, 0x200200, 0x200300, 0x280200,
86
+ 0x280300, 0x1200200, 0x1200300, 0x1280200, 0x1280300, 0x200210, 0x200310, 0x280210, 0x280310,
87
+ 0x1200210, 0x1200310, 0x1280210, 0x1280310],
88
+ [0, 0x4000000, 0x40000, 0x4040000, 2, 0x4000002, 0x40002, 0x4040002, 8192, 0x4002000, 0x42000, 0x4042000,
89
+ 8194, 0x4002002, 0x42002, 0x4042002, 32, 0x4000020, 0x40020, 0x4040020, 34, 0x4000022, 0x40022,
90
+ 0x4040022, 8224, 0x4002020, 0x42020, 0x4042020, 8226, 0x4002022, 0x42022, 0x4042022, 2048,
91
+ 0x4000800, 0x40800, 0x4040800, 2050, 0x4000802, 0x40802, 0x4040802, 10240, 0x4002800, 0x42800,
92
+ 0x4042800, 10242, 0x4002802, 0x42802, 0x4042802, 2080, 0x4000820, 0x40820, 0x4040820, 2082,
93
+ 0x4000822, 0x40822, 0x4040822, 10272, 0x4002820, 0x42820, 0x4042820, 10274, 0x4002822, 0x42822,
94
+ 0x4042822]
96
95
  ];
97
-
98
- var SPTRANS=
99
- [
100
- [ 0x820200, 0x20000, 0x80800000, 0x80820200, 0x800000, 0x80020200, 0x80020000, 0x80800000, 0x80020200,
101
- 0x820200, 0x820000, 0x80000200, 0x80800200, 0x800000, 0, 0x80020000, 0x20000, 0x80000000,
102
- 0x800200, 0x20200, 0x80820200, 0x820000, 0x80000200, 0x800200, 0x80000000, 512, 0x20200,
103
- 0x80820000, 512, 0x80800200, 0x80820000, 0, 0, 0x80820200, 0x800200, 0x80020000, 0x820200,
104
- 0x20000, 0x80000200, 0x800200, 0x80820000, 512, 0x20200, 0x80800000, 0x80020200, 0x80000000,
105
- 0x80800000, 0x820000, 0x80820200, 0x20200, 0x820000, 0x80800200, 0x800000, 0x80000200, 0x80020000,
106
- 0, 0x20000, 0x800000, 0x80800200, 0x820200, 0x80000000, 0x80820000, 512, 0x80020200 ],
107
- [ 0x10042004, 0, 0x42000, 0x10040000, 0x10000004, 8196, 0x10002000, 0x42000, 8192, 0x10040004, 4,
108
- 0x10002000, 0x40004, 0x10042000, 0x10040000, 4, 0x40000, 0x10002004, 0x10040004, 8192, 0x42004,
109
- 0x10000000, 0, 0x40004, 0x10002004, 0x42004, 0x10042000, 0x10000004, 0x10000000, 0x40000, 8196,
110
- 0x10042004, 0x40004, 0x10042000, 0x10002000, 0x42004, 0x10042004, 0x40004, 0x10000004, 0,
111
- 0x10000000, 8196, 0x40000, 0x10040004, 8192, 0x10000000, 0x42004, 0x10002004, 0x10042000, 8192, 0,
112
- 0x10000004, 4, 0x10042004, 0x42000, 0x10040000, 0x10040004, 0x40000, 8196, 0x10002000, 0x10002004,
113
- 4, 0x10040000, 0x42000 ],
114
- [ 0x41000000, 0x1010040, 64, 0x41000040, 0x40010000, 0x1000000, 0x41000040, 0x10040, 0x1000040, 0x10000,
115
- 0x1010000, 0x40000000, 0x41010040, 0x40000040, 0x40000000, 0x41010000, 0, 0x40010000, 0x1010040,
116
- 64, 0x40000040, 0x41010040, 0x10000, 0x41000000, 0x41010000, 0x1000040, 0x40010040, 0x1010000,
117
- 0x10040, 0, 0x1000000, 0x40010040, 0x1010040, 64, 0x40000000, 0x10000, 0x40000040, 0x40010000,
118
- 0x1010000, 0x41000040, 0, 0x1010040, 0x10040, 0x41010000, 0x40010000, 0x1000000, 0x41010040,
119
- 0x40000000, 0x40010040, 0x41000000, 0x1000000, 0x41010040, 0x10000, 0x1000040, 0x41000040,
120
- 0x10040, 0x1000040, 0, 0x41010000, 0x40000040, 0x41000000, 0x40010040, 64, 0x1010000 ],
121
- [ 0x100402, 0x4000400, 2, 0x4100402, 0, 0x4100000, 0x4000402, 0x100002, 0x4100400, 0x4000002, 0x4000000,
122
- 1026, 0x4000002, 0x100402, 0x100000, 0x4000000, 0x4100002, 0x100400, 1024, 2, 0x100400, 0x4000402,
123
- 0x4100000, 1024, 1026, 0, 0x100002, 0x4100400, 0x4000400, 0x4100002, 0x4100402, 0x100000,
124
- 0x4100002, 1026, 0x100000, 0x4000002, 0x100400, 0x4000400, 2, 0x4100000, 0x4000402, 0, 1024,
125
- 0x100002, 0, 0x4100002, 0x4100400, 1024, 0x4000000, 0x4100402, 0x100402, 0x100000, 0x4100402, 2,
126
- 0x4000400, 0x100402, 0x100002, 0x100400, 0x4100000, 0x4000402, 1026, 0x4000000, 0x4000002,
127
- 0x4100400 ],
128
- [ 0x2000000, 16384, 256, 0x2004108, 0x2004008, 0x2000100, 16648, 0x2004000, 16384, 8, 0x2000008, 16640,
129
- 0x2000108, 0x2004008, 0x2004100, 0, 16640, 0x2000000, 16392, 264, 0x2000100, 16648, 0, 0x2000008,
130
- 8, 0x2000108, 0x2004108, 16392, 0x2004000, 256, 264, 0x2004100, 0x2004100, 0x2000108, 16392,
131
- 0x2004000, 16384, 8, 0x2000008, 0x2000100, 0x2000000, 16640, 0x2004108, 0, 16648, 0x2000000, 256,
132
- 16392, 0x2000108, 256, 0, 0x2004108, 0x2004008, 0x2004100, 264, 16384, 16640, 0x2004008,
133
- 0x2000100, 264, 8, 16648, 0x2004000, 0x2000008 ],
134
- [ 0x20000010, 0x80010, 0, 0x20080800, 0x80010, 2048, 0x20000810, 0x80000, 2064, 0x20080810, 0x80800,
135
- 0x20000000, 0x20000800, 0x20000010, 0x20080000, 0x80810, 0x80000, 0x20000810, 0x20080010, 0, 2048,
136
- 16, 0x20080800, 0x20080010, 0x20080810, 0x20080000, 0x20000000, 2064, 16, 0x80800, 0x80810,
137
- 0x20000800, 2064, 0x20000000, 0x20000800, 0x80810, 0x20080800, 0x80010, 0, 0x20000800, 0x20000000,
138
- 2048, 0x20080010, 0x80000, 0x80010, 0x20080810, 0x80800, 16, 0x20080810, 0x80800, 0x80000,
139
- 0x20000810, 0x20000010, 0x20080000, 0x80810, 0, 2048, 0x20000010, 0x20000810, 0x20080800,
140
- 0x20080000, 2064, 16, 0x20080010 ],
141
- [ 4096, 128, 0x400080, 0x400001, 0x401081, 4097, 4224, 0, 0x400000, 0x400081, 129, 0x401000, 1, 0x401080,
142
- 0x401000, 129, 0x400081, 4096, 4097, 0x401081, 0, 0x400080, 0x400001, 4224, 0x401001, 4225,
143
- 0x401080, 1, 4225, 0x401001, 128, 0x400000, 4225, 0x401000, 0x401001, 129, 4096, 128, 0x400000,
144
- 0x401001, 0x400081, 4225, 4224, 0, 128, 0x400001, 1, 0x400080, 0, 0x400081, 0x400080, 4224, 129,
145
- 4096, 0x401081, 0x400000, 0x401080, 1, 4097, 0x401081, 0x400001, 0x401080, 0x401000, 4097 ],
146
- [ 0x8200020, 0x8208000, 32800, 0, 0x8008000, 0x200020, 0x8200000, 0x8208020, 32, 0x8000000, 0x208000,
147
- 32800, 0x208020, 0x8008020, 0x8000020, 0x8200000, 32768, 0x208020, 0x200020, 0x8008000, 0x8208020,
148
- 0x8000020, 0, 0x208000, 0x8000000, 0x200000, 0x8008020, 0x8200020, 0x200000, 32768, 0x8208000, 32,
149
- 0x200000, 32768, 0x8000020, 0x8208020, 32800, 0x8000000, 0, 0x208000, 0x8200020, 0x8008020,
150
- 0x8008000, 0x200020, 0x8208000, 32, 0x200020, 0x8008000, 0x8208020, 0x200000, 0x8200000,
151
- 0x8000020, 0x208000, 32800, 0x8008020, 0x8200000, 32, 0x8208000, 0x208020, 0, 0x8000000,
152
- 0x8200020, 32768, 0x208020 ]
96
+ var SPTRANS = [
97
+ [0x820200, 0x20000, 0x80800000, 0x80820200, 0x800000, 0x80020200, 0x80020000, 0x80800000, 0x80020200,
98
+ 0x820200, 0x820000, 0x80000200, 0x80800200, 0x800000, 0, 0x80020000, 0x20000, 0x80000000,
99
+ 0x800200, 0x20200, 0x80820200, 0x820000, 0x80000200, 0x800200, 0x80000000, 512, 0x20200,
100
+ 0x80820000, 512, 0x80800200, 0x80820000, 0, 0, 0x80820200, 0x800200, 0x80020000, 0x820200,
101
+ 0x20000, 0x80000200, 0x800200, 0x80820000, 512, 0x20200, 0x80800000, 0x80020200, 0x80000000,
102
+ 0x80800000, 0x820000, 0x80820200, 0x20200, 0x820000, 0x80800200, 0x800000, 0x80000200, 0x80020000,
103
+ 0, 0x20000, 0x800000, 0x80800200, 0x820200, 0x80000000, 0x80820000, 512, 0x80020200],
104
+ [0x10042004, 0, 0x42000, 0x10040000, 0x10000004, 8196, 0x10002000, 0x42000, 8192, 0x10040004, 4,
105
+ 0x10002000, 0x40004, 0x10042000, 0x10040000, 4, 0x40000, 0x10002004, 0x10040004, 8192, 0x42004,
106
+ 0x10000000, 0, 0x40004, 0x10002004, 0x42004, 0x10042000, 0x10000004, 0x10000000, 0x40000, 8196,
107
+ 0x10042004, 0x40004, 0x10042000, 0x10002000, 0x42004, 0x10042004, 0x40004, 0x10000004, 0,
108
+ 0x10000000, 8196, 0x40000, 0x10040004, 8192, 0x10000000, 0x42004, 0x10002004, 0x10042000, 8192, 0,
109
+ 0x10000004, 4, 0x10042004, 0x42000, 0x10040000, 0x10040004, 0x40000, 8196, 0x10002000, 0x10002004,
110
+ 4, 0x10040000, 0x42000],
111
+ [0x41000000, 0x1010040, 64, 0x41000040, 0x40010000, 0x1000000, 0x41000040, 0x10040, 0x1000040, 0x10000,
112
+ 0x1010000, 0x40000000, 0x41010040, 0x40000040, 0x40000000, 0x41010000, 0, 0x40010000, 0x1010040,
113
+ 64, 0x40000040, 0x41010040, 0x10000, 0x41000000, 0x41010000, 0x1000040, 0x40010040, 0x1010000,
114
+ 0x10040, 0, 0x1000000, 0x40010040, 0x1010040, 64, 0x40000000, 0x10000, 0x40000040, 0x40010000,
115
+ 0x1010000, 0x41000040, 0, 0x1010040, 0x10040, 0x41010000, 0x40010000, 0x1000000, 0x41010040,
116
+ 0x40000000, 0x40010040, 0x41000000, 0x1000000, 0x41010040, 0x10000, 0x1000040, 0x41000040,
117
+ 0x10040, 0x1000040, 0, 0x41010000, 0x40000040, 0x41000000, 0x40010040, 64, 0x1010000],
118
+ [0x100402, 0x4000400, 2, 0x4100402, 0, 0x4100000, 0x4000402, 0x100002, 0x4100400, 0x4000002, 0x4000000,
119
+ 1026, 0x4000002, 0x100402, 0x100000, 0x4000000, 0x4100002, 0x100400, 1024, 2, 0x100400, 0x4000402,
120
+ 0x4100000, 1024, 1026, 0, 0x100002, 0x4100400, 0x4000400, 0x4100002, 0x4100402, 0x100000,
121
+ 0x4100002, 1026, 0x100000, 0x4000002, 0x100400, 0x4000400, 2, 0x4100000, 0x4000402, 0, 1024,
122
+ 0x100002, 0, 0x4100002, 0x4100400, 1024, 0x4000000, 0x4100402, 0x100402, 0x100000, 0x4100402, 2,
123
+ 0x4000400, 0x100402, 0x100002, 0x100400, 0x4100000, 0x4000402, 1026, 0x4000000, 0x4000002,
124
+ 0x4100400],
125
+ [0x2000000, 16384, 256, 0x2004108, 0x2004008, 0x2000100, 16648, 0x2004000, 16384, 8, 0x2000008, 16640,
126
+ 0x2000108, 0x2004008, 0x2004100, 0, 16640, 0x2000000, 16392, 264, 0x2000100, 16648, 0, 0x2000008,
127
+ 8, 0x2000108, 0x2004108, 16392, 0x2004000, 256, 264, 0x2004100, 0x2004100, 0x2000108, 16392,
128
+ 0x2004000, 16384, 8, 0x2000008, 0x2000100, 0x2000000, 16640, 0x2004108, 0, 16648, 0x2000000, 256,
129
+ 16392, 0x2000108, 256, 0, 0x2004108, 0x2004008, 0x2004100, 264, 16384, 16640, 0x2004008,
130
+ 0x2000100, 264, 8, 16648, 0x2004000, 0x2000008],
131
+ [0x20000010, 0x80010, 0, 0x20080800, 0x80010, 2048, 0x20000810, 0x80000, 2064, 0x20080810, 0x80800,
132
+ 0x20000000, 0x20000800, 0x20000010, 0x20080000, 0x80810, 0x80000, 0x20000810, 0x20080010, 0, 2048,
133
+ 16, 0x20080800, 0x20080010, 0x20080810, 0x20080000, 0x20000000, 2064, 16, 0x80800, 0x80810,
134
+ 0x20000800, 2064, 0x20000000, 0x20000800, 0x80810, 0x20080800, 0x80010, 0, 0x20000800, 0x20000000,
135
+ 2048, 0x20080010, 0x80000, 0x80010, 0x20080810, 0x80800, 16, 0x20080810, 0x80800, 0x80000,
136
+ 0x20000810, 0x20000010, 0x20080000, 0x80810, 0, 2048, 0x20000010, 0x20000810, 0x20080800,
137
+ 0x20080000, 2064, 16, 0x20080010],
138
+ [4096, 128, 0x400080, 0x400001, 0x401081, 4097, 4224, 0, 0x400000, 0x400081, 129, 0x401000, 1, 0x401080,
139
+ 0x401000, 129, 0x400081, 4096, 4097, 0x401081, 0, 0x400080, 0x400001, 4224, 0x401001, 4225,
140
+ 0x401080, 1, 4225, 0x401001, 128, 0x400000, 4225, 0x401000, 0x401001, 129, 4096, 128, 0x400000,
141
+ 0x401001, 0x400081, 4225, 4224, 0, 128, 0x400001, 1, 0x400080, 0, 0x400081, 0x400080, 4224, 129,
142
+ 4096, 0x401081, 0x400000, 0x401080, 1, 4097, 0x401081, 0x400001, 0x401080, 0x401000, 4097],
143
+ [0x8200020, 0x8208000, 32800, 0, 0x8008000, 0x200020, 0x8200000, 0x8208020, 32, 0x8000000, 0x208000,
144
+ 32800, 0x208020, 0x8008020, 0x8000020, 0x8200000, 32768, 0x208020, 0x200020, 0x8008000, 0x8208020,
145
+ 0x8000020, 0, 0x208000, 0x8000000, 0x200000, 0x8008020, 0x8200020, 0x200000, 32768, 0x8208000, 32,
146
+ 0x200000, 32768, 0x8000020, 0x8208020, 32800, 0x8000000, 0, 0x208000, 0x8200020, 0x8008020,
147
+ 0x8008000, 0x200020, 0x8208000, 32, 0x200020, 0x8008000, 0x8208020, 0x200000, 0x8200000,
148
+ 0x8000020, 0x208000, 32800, 0x8008020, 0x8200000, 32, 0x8208000, 0x208020, 0, 0x8000000,
149
+ 0x8200020, 32768, 0x208020]
153
150
  ];
154
-
155
151
  function hPermOp(a, n, m) {
156
152
  var t = (a << 16 - n ^ a) & m;
157
153
  a = a ^ t ^ t >>> 16 - n;
158
154
  return a;
159
155
  }
160
-
161
156
  function intToFourBytes(iValue, b, offset) {
162
157
  b[offset++] = iValue & 0xff;
163
158
  b[offset++] = iValue >>> 8 & 0xff;
164
159
  b[offset++] = iValue >>> 16 & 0xff;
165
160
  b[offset++] = iValue >>> 24 & 0xff;
166
161
  }
167
-
168
162
  function byteToUnsigned(b) {
169
163
  var value = b;
170
164
  return value < 0 ? value + 256 : value;
171
165
  }
172
-
173
166
  function fourBytesToInt(b, offset) {
174
167
  var value = byteToUnsigned(b[offset++]);
175
168
  value |= byteToUnsigned(b[offset++]) << 8;
@@ -177,7 +170,6 @@ function fourBytesToInt(b, offset) {
177
170
  value |= byteToUnsigned(b[offset++]) << 24;
178
171
  return value;
179
172
  }
180
-
181
173
  function permOp(a, b, n, m, results) {
182
174
  var t = (a >>> n ^ b) & m;
183
175
  a ^= t << n;
@@ -185,7 +177,6 @@ function permOp(a, b, n, m, results) {
185
177
  results[0] = a;
186
178
  results[1] = b;
187
179
  }
188
-
189
180
  function desSetKey(key) {
190
181
  var schedule = [];
191
182
  var c = fourBytesToInt(key, 0);
@@ -212,7 +203,8 @@ function desSetKey(key) {
212
203
  if (SHIFT2[i]) {
213
204
  c = c >>> 2 | c << 26;
214
205
  d = d >>> 2 | d << 26;
215
- } else {
206
+ }
207
+ else {
216
208
  c = c >>> 1 | c << 27;
217
209
  d = d >>> 1 | d << 27;
218
210
  }
@@ -228,10 +220,8 @@ function desSetKey(key) {
228
220
  s = s << 4 | s >>> 28;
229
221
  schedule[j++] = s;
230
222
  }
231
-
232
223
  return schedule;
233
224
  }
234
-
235
225
  function dEncrypt(el, r, s, e0, e1, sArr) {
236
226
  var v = r ^ r >>> 16;
237
227
  var u = v & e0;
@@ -240,11 +230,10 @@ function dEncrypt(el, r, s, e0, e1, sArr) {
240
230
  var t = v ^ v << 16 ^ r ^ sArr[s + 1];
241
231
  t = t >>> 4 | t << 28;
242
232
  el ^= SPTRANS[1][t & 0x3f] | SPTRANS[3][t >>> 8 & 0x3f] | SPTRANS[5][t >>> 16 & 0x3f] |
243
- SPTRANS[7][t >>> 24 & 0x3f] | SPTRANS[0][u & 0x3f] | SPTRANS[2][u >>> 8 & 0x3f] |
244
- SPTRANS[4][u >>> 16 & 0x3f] | SPTRANS[6][u >>> 24 & 0x3f];
233
+ SPTRANS[7][t >>> 24 & 0x3f] | SPTRANS[0][u & 0x3f] | SPTRANS[2][u >>> 8 & 0x3f] |
234
+ SPTRANS[4][u >>> 16 & 0x3f] | SPTRANS[6][u >>> 24 & 0x3f];
245
235
  return el;
246
236
  }
247
-
248
237
  function body(schedule, eSwap0, eSwap1) {
249
238
  var left = 0;
250
239
  var right = 0;
@@ -254,12 +243,10 @@ function body(schedule, eSwap0, eSwap1) {
254
243
  left = dEncrypt(left, right, i, eSwap0, eSwap1, schedule);
255
244
  right = dEncrypt(right, left, i + 2, eSwap0, eSwap1, schedule);
256
245
  }
257
-
258
246
  t = left;
259
247
  left = right;
260
248
  right = t;
261
249
  }
262
-
263
250
  t = right;
264
251
  right = left >>> 1 | left << 31;
265
252
  left = t >>> 1 | t << 31;
@@ -284,36 +271,28 @@ function body(schedule, eSwap0, eSwap1) {
284
271
  out[1] = right;
285
272
  return out;
286
273
  }
287
-
288
274
  function crypt(original, salt) {
289
- if (!(original instanceof Buffer)) {
290
- original = Buffer.from(original);
291
- }
292
-
275
+ const orig = original instanceof Buffer ? original : Buffer.from(original);
293
276
  if (!salt) {
294
277
  throw new Error("Invalid salt value: " + salt);
295
278
  }
296
-
297
279
  var buffer = Buffer.alloc(13);
298
- var charZero = salt[0].charCodeAt();
299
- var charOne = salt[1].charCodeAt();
280
+ var charZero = salt[0].charCodeAt(0);
281
+ var charOne = salt[1].charCodeAt(0);
300
282
  buffer[0] = charZero;
301
283
  buffer[1] = charOne;
302
284
  var eSwap0 = CON_SALT[charZero];
303
285
  var eSwap1 = CON_SALT[charOne] << 4;
304
-
305
286
  var key = Buffer.alloc(8);
306
- for (var i = 0; i < key.length && i < original.length; i++) {
307
- var iChar = original[i];
287
+ for (var i = 0; i < key.length && i < orig.length; i++) {
288
+ var iChar = orig[i];
308
289
  key[i] = iChar << 1;
309
290
  }
310
-
311
291
  var schedule = desSetKey(key);
312
292
  var out = body(schedule, eSwap0, eSwap1);
313
293
  var b = Buffer.alloc(9);
314
294
  intToFourBytes(out[0], b, 0);
315
295
  intToFourBytes(out[1], b, 4);
316
-
317
296
  b[8] = 0;
318
297
  var i = 2;
319
298
  var y = 0;
@@ -334,10 +313,5 @@ function crypt(original, salt) {
334
313
  buffer[i] = COV2CHAR[c];
335
314
  }
336
315
  }
337
-
338
316
  return buffer.toString('ascii');
339
317
  }
340
-
341
- module.exports = {
342
- crypt : crypt
343
- }
package/lib/utils.d.ts ADDED
@@ -0,0 +1,16 @@
1
+ import type { FbStatusItem } from './callback';
2
+ /**
3
+ * Parse date from string
4
+ */
5
+ export declare const parseDate: (str: string) => Date;
6
+ /**
7
+ * Get Error Message per gdscode
8
+ */
9
+ export declare const lookupMessages: (status: FbStatusItem[]) => string;
10
+ /**
11
+ * Escape value
12
+ * @param value value to escape
13
+ * @param protocolVersion optional, default: PROTOCOL_VERSION13
14
+ */
15
+ export declare const escape: (value: any, protocolVersion?: number) => string;
16
+ export declare function noop(): void;
package/lib/utils.js CHANGED
@@ -1,29 +1,30 @@
1
- const MessagesError = require('./firebird.msg.json');
2
- const Const = require('./wire/const');
3
-
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.escape = exports.lookupMessages = exports.parseDate = void 0;
7
+ exports.noop = noop;
8
+ const firebird_msg_json_1 = __importDefault(require("./firebird.msg.json"));
9
+ const const_1 = __importDefault(require("./wire/const"));
10
+ const MessagesError = firebird_msg_json_1.default;
4
11
  /**
5
12
  * Parse date from string
6
- * @param {String} str
7
- * @return {Date}
8
13
  */
9
14
  const parseDate = (str) => {
10
15
  const self = str.trim();
11
16
  const arr = self.indexOf(' ') === -1 ? self.split('T') : self.split(' ');
12
17
  let index = arr[0].indexOf(':');
13
18
  const length = arr[0].length;
14
-
15
19
  if (index !== -1) {
16
20
  const tmp = arr[1];
17
21
  arr[1] = arr[0];
18
22
  arr[0] = tmp;
19
23
  }
20
-
21
24
  if (arr[0] === undefined) {
22
25
  arr[0] = '';
23
26
  }
24
-
25
27
  const noTime = arr[1] === undefined || arr[1].length === 0;
26
-
27
28
  for (let i = 0; i < length; i++) {
28
29
  const c = arr[0].charCodeAt(i);
29
30
  if (c > 47 && c < 58) {
@@ -36,30 +37,24 @@ const parseDate = (str) => {
36
37
  return new Date(self);
37
38
  }
38
39
  }
39
-
40
40
  if (arr[1] === undefined) {
41
41
  arr[1] = '00:00:00';
42
42
  }
43
-
44
43
  const firstDay = arr[0].indexOf('-') === -1;
45
-
46
44
  const date = (arr[0] || '').split(firstDay ? '.' : '-');
47
45
  const time = (arr[1] || '').split(':');
48
-
49
46
  if (date.length < 4 && time.length < 2) {
50
47
  return new Date(self);
51
48
  }
52
-
53
49
  index = (time[2] || '').indexOf('.');
54
-
55
50
  // milliseconds
56
51
  if (index !== -1) {
57
52
  time[3] = time[2].substring(index + 1);
58
53
  time[2] = time[2].substring(0, index);
59
- } else {
54
+ }
55
+ else {
60
56
  time[3] = '0';
61
57
  }
62
-
63
58
  const parsed = [
64
59
  parseInt(date[firstDay ? 2 : 0], 10), // year
65
60
  parseInt(date[1], 10), // month
@@ -69,19 +64,15 @@ const parseDate = (str) => {
69
64
  parseInt(time[2], 10), // seconds
70
65
  parseInt(time[3], 10) // miliseconds
71
66
  ];
72
-
73
67
  const def = new Date();
74
-
75
68
  for (let i = 0; i < parsed.length; i++) {
76
69
  if (isNaN(parsed[i])) {
77
70
  parsed[i] = 0;
78
71
  }
79
-
80
72
  const value = parsed[i];
81
73
  if (value !== 0) {
82
74
  continue;
83
75
  }
84
-
85
76
  switch (i) {
86
77
  case 0:
87
78
  if (value <= 0) {
@@ -100,14 +91,11 @@ const parseDate = (str) => {
100
91
  break;
101
92
  }
102
93
  }
103
-
104
94
  return new Date(parsed[0], parsed[1] - 1, parsed[2], parsed[3], parsed[4], parsed[5]);
105
- }
106
-
95
+ };
96
+ exports.parseDate = parseDate;
107
97
  /**
108
98
  * Get Error Message per gdscode
109
- * @param {{gdscode: Number, params: Any[]}[]} status
110
- * @returns {String} - Error message
111
99
  */
112
100
  const lookupMessages = (status) => {
113
101
  const messages = status.map((item) => {
@@ -123,22 +111,19 @@ const lookupMessages = (status) => {
123
111
  return text;
124
112
  });
125
113
  return messages.join(', ');
126
- }
127
-
114
+ };
115
+ exports.lookupMessages = lookupMessages;
128
116
  /**
129
117
  * Escape value
130
- * @param {Object} value
131
- * @param {Number} protocolVersion (optional, default: PROTOCOL_VERSION13)
132
- * @return {String}
118
+ * @param value value to escape
119
+ * @param protocolVersion optional, default: PROTOCOL_VERSION13
133
120
  */
134
- const escape = function(value, protocolVersion) {
135
-
121
+ const escape = function (value, protocolVersion) {
136
122
  if (value === null || value === undefined)
137
123
  return 'NULL';
138
-
139
- switch (typeof(value)) {
124
+ switch (typeof (value)) {
140
125
  case 'boolean':
141
- if ((protocolVersion || Const.PROTOCOL_VERSION13) >= Const.PROTOCOL_VERSION13)
126
+ if ((protocolVersion || const_1.default.PROTOCOL_VERSION13) >= const_1.default.PROTOCOL_VERSION13)
142
127
  return value ? 'true' : 'false';
143
128
  else
144
129
  return value ? '1' : '0';
@@ -147,18 +132,9 @@ const escape = function(value, protocolVersion) {
147
132
  case 'string':
148
133
  return "'" + value.replace(/'/g, "''").replace(/\\/g, '\\\\') + "'";
149
134
  }
150
-
151
135
  if (value instanceof Date)
152
- return "'" + value.getFullYear() + '-' + (value.getMonth()+1).toString().padStart(2, '0') + '-' + value.getDate().toString().padStart(2, '0') + ' ' + value.getHours().toString().padStart(2, '0') + ':' + value.getMinutes().toString().padStart(2, '0') + ':' + value.getSeconds().toString().padStart(2, '0') + '.' + value.getMilliseconds().toString().padStart(3, '0') + "'";
153
-
136
+ return "'" + value.getFullYear() + '-' + (value.getMonth() + 1).toString().padStart(2, '0') + '-' + value.getDate().toString().padStart(2, '0') + ' ' + value.getHours().toString().padStart(2, '0') + ':' + value.getMinutes().toString().padStart(2, '0') + ':' + value.getSeconds().toString().padStart(2, '0') + '.' + value.getMilliseconds().toString().padStart(3, '0') + "'";
154
137
  throw new Error('Escape supports only primitive values.');
155
138
  };
156
-
157
- function noop() {}
158
-
159
- module.exports = {
160
- escape,
161
- lookupMessages,
162
- noop,
163
- parseDate,
164
- };
139
+ exports.escape = escape;
140
+ function noop() { }