dsh-ssh-workbench 0.0.0-stage → 1.7.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 (98) hide show
  1. package/CHANGELOG.md +552 -0
  2. package/CONTRIBUTING.md +63 -0
  3. package/LICENSE +21 -0
  4. package/README.md +178 -2
  5. package/SECURITY.md +27 -0
  6. package/cordis.patch.yml +5 -0
  7. package/docs/architecture.md +146 -0
  8. package/docs/execution-model.md +83 -0
  9. package/docs/images/chat-at-resource.png +0 -0
  10. package/docs/images/plugin.png +0 -0
  11. package/docs/images/remote-workbench.png +0 -0
  12. package/docs/images/workbench.png +0 -0
  13. package/docs/quickstart.md +106 -0
  14. package/lib/client.js +4991 -0
  15. package/lib/core/activity.js +88 -0
  16. package/lib/core/background.js +69 -0
  17. package/lib/core/broker.js +802 -0
  18. package/lib/core/dialect.js +28 -0
  19. package/lib/core/errors.js +138 -0
  20. package/lib/core/execution-stats.js +88 -0
  21. package/lib/core/gate-pwsh.js +88 -0
  22. package/lib/core/gate.js +572 -0
  23. package/lib/core/guard.js +123 -0
  24. package/lib/core/known-hosts.js +74 -0
  25. package/lib/core/live-executions.js +101 -0
  26. package/lib/core/local-file-api.js +174 -0
  27. package/lib/core/localfs.js +381 -0
  28. package/lib/core/managed-context.js +276 -0
  29. package/lib/core/mentions.js +216 -0
  30. package/lib/core/paths.js +104 -0
  31. package/lib/core/posix-quote.js +4 -0
  32. package/lib/core/posix-shell.js +89 -0
  33. package/lib/core/prefs.js +38 -0
  34. package/lib/core/remote-exec-tool.js +394 -0
  35. package/lib/core/remote-file-tools.js +559 -0
  36. package/lib/core/remote-shell-tool.js +310 -0
  37. package/lib/core/secrets.js +95 -0
  38. package/lib/core/server-ref.js +61 -0
  39. package/lib/core/shell-adapters.js +48 -0
  40. package/lib/core/ssh.js +761 -0
  41. package/lib/core/store.js +83 -0
  42. package/lib/core/terminals.js +299 -0
  43. package/lib/core/win32-adapter.js +141 -0
  44. package/lib/index.js +409 -0
  45. package/lib/routes.js +759 -0
  46. package/locale/en.json +6 -0
  47. package/locale/zh.json +6 -0
  48. package/package.json +89 -4
  49. package/vendor/NOTICE.md +50 -0
  50. package/vendor/XTERM-LICENSE +21 -0
  51. package/vendor/node_modules/asn1/LICENSE +19 -0
  52. package/vendor/node_modules/asn1/README.md +50 -0
  53. package/vendor/node_modules/asn1/lib/ber/errors.js +13 -0
  54. package/vendor/node_modules/asn1/lib/ber/index.js +27 -0
  55. package/vendor/node_modules/asn1/lib/ber/reader.js +262 -0
  56. package/vendor/node_modules/asn1/lib/ber/types.js +36 -0
  57. package/vendor/node_modules/asn1/lib/ber/writer.js +317 -0
  58. package/vendor/node_modules/asn1/lib/index.js +20 -0
  59. package/vendor/node_modules/asn1/package.json +31 -0
  60. package/vendor/node_modules/bcrypt-pbkdf/CONTRIBUTING.md +13 -0
  61. package/vendor/node_modules/bcrypt-pbkdf/LICENSE +66 -0
  62. package/vendor/node_modules/bcrypt-pbkdf/README.md +45 -0
  63. package/vendor/node_modules/bcrypt-pbkdf/index.js +556 -0
  64. package/vendor/node_modules/bcrypt-pbkdf/package.json +15 -0
  65. package/vendor/node_modules/safer-buffer/LICENSE +21 -0
  66. package/vendor/node_modules/safer-buffer/Readme.md +156 -0
  67. package/vendor/node_modules/safer-buffer/dangerous.js +58 -0
  68. package/vendor/node_modules/safer-buffer/package.json +34 -0
  69. package/vendor/node_modules/safer-buffer/safer.js +77 -0
  70. package/vendor/node_modules/tweetnacl/AUTHORS.md +28 -0
  71. package/vendor/node_modules/tweetnacl/LICENSE +24 -0
  72. package/vendor/node_modules/tweetnacl/README.md +459 -0
  73. package/vendor/node_modules/tweetnacl/nacl-fast.js +2388 -0
  74. package/vendor/node_modules/tweetnacl/nacl.js +1175 -0
  75. package/vendor/node_modules/tweetnacl/package.json +58 -0
  76. package/vendor/ssh2/LICENSE +19 -0
  77. package/vendor/ssh2/lib/Channel.js +295 -0
  78. package/vendor/ssh2/lib/agent.js +1123 -0
  79. package/vendor/ssh2/lib/client.js +2176 -0
  80. package/vendor/ssh2/lib/http-agents.js +84 -0
  81. package/vendor/ssh2/lib/index.js +44 -0
  82. package/vendor/ssh2/lib/keygen.js +582 -0
  83. package/vendor/ssh2/lib/protocol/Protocol.js +2136 -0
  84. package/vendor/ssh2/lib/protocol/SFTP.js +4052 -0
  85. package/vendor/ssh2/lib/protocol/constants.js +356 -0
  86. package/vendor/ssh2/lib/protocol/crypto/poly1305.js +43 -0
  87. package/vendor/ssh2/lib/protocol/crypto.js +1602 -0
  88. package/vendor/ssh2/lib/protocol/handlers.js +16 -0
  89. package/vendor/ssh2/lib/protocol/handlers.misc.js +1285 -0
  90. package/vendor/ssh2/lib/protocol/kex.js +1908 -0
  91. package/vendor/ssh2/lib/protocol/keyParser.js +1484 -0
  92. package/vendor/ssh2/lib/protocol/node-fs-compat.js +115 -0
  93. package/vendor/ssh2/lib/protocol/utils.js +356 -0
  94. package/vendor/ssh2/lib/protocol/zlib.js +255 -0
  95. package/vendor/ssh2/lib/server.js +1380 -0
  96. package/vendor/ssh2/lib/utils.js +336 -0
  97. package/vendor/ssh2/package.json +34 -0
  98. package/vendor/xterm.js +53 -0
package/locale/en.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "SSH Workbench",
4
+ "description": "SSH terminals, local and remote files, and @server command execution — on Windows hosts and Windows targets."
5
+ }
6
+ }
package/locale/zh.json ADDED
@@ -0,0 +1,6 @@
1
+ {
2
+ "meta": {
3
+ "title": "远程工作台",
4
+ "description": "SSH 终端、本地与远程文件、@服务器 对话执行,Windows 宿主和目标都能用。"
5
+ }
6
+ }
package/package.json CHANGED
@@ -1,6 +1,91 @@
1
1
  {
2
2
  "name": "dsh-ssh-workbench",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "1.7.0",
4
+ "description": "远程工作台:SSH 终端、本地与远程文件、@服务器 对话执行;显式目标的远程 shell 与 read/glob/grep,Windows 宿主和目标都能用。DeepSeek Harness SSH workbench plugin.",
5
+ "type": "module",
6
+ "main": "lib/index.js",
7
+ "exports": {
8
+ ".": "./lib/index.js",
9
+ "./client": "./lib/client.js",
10
+ "./package.json": "./package.json",
11
+ "./cordis.patch.yml": "./cordis.patch.yml",
12
+ "./locale/*": "./locale/*"
13
+ },
14
+ "files": [
15
+ "lib",
16
+ "cordis.patch.yml",
17
+ "README.md",
18
+ "LICENSE",
19
+ "CHANGELOG.md",
20
+ "CONTRIBUTING.md",
21
+ "SECURITY.md",
22
+ "locale",
23
+ "vendor",
24
+ "docs/quickstart.md",
25
+ "docs/architecture.md",
26
+ "docs/execution-model.md",
27
+ "docs/images"
28
+ ],
29
+ "dsh": {
30
+ "manifestVersion": 1,
31
+ "engines": {
32
+ "dsh": ">=0.2.1-rc.1 <0.3.0"
33
+ },
34
+ "bundle": {
35
+ "patch": "./cordis.patch.yml"
36
+ },
37
+ "client": {
38
+ "platform": "web",
39
+ "inject": [
40
+ "@deepseek-ai/dsh-client-ui-renderer",
41
+ "@deepseek-ai/dsh-client-locale"
42
+ ]
43
+ }
44
+ },
45
+ "peerDependencies": {
46
+ "@deepseek-ai/cordis": "^4.0.5",
47
+ "@deepseek-ai/dsh-tools": ">=0.2.1-rc.1 <0.3.0",
48
+ "@deepseek-ai/schemastery": "^3.18.5",
49
+ "@deepseek-ai/dsh-client-ui-renderer": ">=0.2.1-rc.1 <0.3.0",
50
+ "@deepseek-ai/dsh-client-locale": ">=0.2.1-rc.1 <0.3.0",
51
+ "react": "^18.3.1",
52
+ "react-dom": "^18.3.1"
53
+ },
54
+ "peerDependenciesMeta": {
55
+ "@deepseek-ai/dsh-client-ui-renderer": {
56
+ "optional": true
57
+ },
58
+ "@deepseek-ai/dsh-client-locale": {
59
+ "optional": true
60
+ }
61
+ },
62
+ "scripts": {
63
+ "test": "node --import ./test/register.mjs --test test/*.test.js",
64
+ "pack": "node -e \"require('node:fs').mkdirSync('dist',{recursive:true})\" && npm pack --ignore-scripts --pack-destination dist",
65
+ "test:ssh": "node --import ./test/ssh.register.mjs test/ssh.integration.mjs",
66
+ "test:ssh:sftp": "node --import ./test/ssh.register.mjs test/sftp.integration.mjs",
67
+ "bench": "node --import ./test/ssh.register.mjs test/bench/latency.mjs"
68
+ },
69
+ "license": "MIT",
70
+ "keywords": [
71
+ "deepseek-harness",
72
+ "dsh",
73
+ "dsh-plugin",
74
+ "ssh",
75
+ "remote-execution",
76
+ "server-management",
77
+ "remote-workbench",
78
+ "sftp",
79
+ "terminal",
80
+ "windows"
81
+ ],
82
+ "author": "duobaobox",
83
+ "repository": {
84
+ "type": "git",
85
+ "url": "git+https://github.com/duobaobox/dsh-ssh-workbench.git"
86
+ },
87
+ "homepage": "https://github.com/duobaobox/dsh-ssh-workbench",
88
+ "bugs": {
89
+ "url": "https://github.com/duobaobox/dsh-ssh-workbench/issues"
90
+ }
91
+ }
@@ -0,0 +1,50 @@
1
+ # Vendored dependencies
2
+
3
+ This directory ships the pure-JS runtime for the SSH transport inside the plugin
4
+ package. It is **not** installed from npm at plugin-install time: keeping the
5
+ dependency graph in-tree means installing `dsh-ssh-workbench` never runs `node-gyp`,
6
+ never needs Xcode Command Line Tools / a C++ toolchain, and never downloads
7
+ packages. This intentionally trades a slightly larger tarball for an
8
+ out-of-the-box install on any machine.
9
+
10
+ | Component | Version | License | Upstream |
11
+ |---|---|---|---|
12
+ | ssh2 | 1.17.0 | MIT | https://github.com/mscdex/ssh2 |
13
+ | asn1 | 0.2.6 | MIT | https://github.com/joyent/node-asn1 |
14
+ | bcrypt-pbkdf | 1.0.2 | BSD-3-Clause | https://github.com/joyent/node-bcrypt-pbkdf |
15
+ | safer-buffer | 2.1.2 | MIT | https://github.com/ChALkeR/safer-buffer |
16
+ | tweetnacl | 0.14.5 | Unlicense | https://github.com/dchest/tweetnacl-js |
17
+ | xterm.js (browser bundle) | see `XTERM-LICENSE` / `xterm.js` | MIT | https://github.com/xtermjs/xterm.js |
18
+
19
+ Licence texts are kept next to each component (`vendor/ssh2/LICENSE`,
20
+ `vendor/node_modules/<name>/LICENSE`, ...).
21
+
22
+ ## Layout
23
+
24
+ ```
25
+ vendor/ssh2/ ssh2 package (lib/, package.json, LICENSE)
26
+ vendor/node_modules/asn1/ runtime deps resolved by Node from vendor/ssh2
27
+ vendor/node_modules/bcrypt-pbkdf/
28
+ vendor/node_modules/safer-buffer/
29
+ vendor/node_modules/tweetnacl/
30
+ ```
31
+
32
+ `vendor/ssh2/install.js`, tests, examples and the optional native crypto
33
+ binding sources have been removed: ssh2 falls back to its pure-JS crypto
34
+ implementation when the native binding is absent. `cpu-features` and `nan`
35
+ (ssh2's optional native dependencies) are intentionally not vendored; ssh2
36
+ guards both requires with `try/catch`.
37
+
38
+ ## Updating the vendored copy
39
+
40
+ The tree is generated from the npm packages listed above. To refresh it:
41
+
42
+ 1. Install the target versions in a scratch directory, e.g.
43
+ `npm install --no-save ssh2@1.17.0`.
44
+ 2. Copy `ssh2/lib` + `ssh2/package.json` + `ssh2/LICENSE` to `vendor/ssh2/`;
45
+ remove `lib/protocol/crypto/src` and `lib/protocol/crypto/binding.gyp`.
46
+ 3. Copy `asn1`, `bcrypt-pbkdf`, `safer-buffer` and `tweetnacl` (only the files
47
+ their `package.json` entry points need, plus `LICENSE`) to
48
+ `vendor/node_modules/<name>/`.
49
+ 4. Run `npm test`, `npm run test:ssh` and `npm run test:ssh:sftp`; all three
50
+ suites exercise the vendored transport.
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2017-2019, The xterm.js authors (https://github.com/xtermjs/xterm.js)
2
+ Copyright (c) 2014-2016, SourceLair Private Company (https://www.sourcelair.com)
3
+ Copyright (c) 2012-2013, Christopher Jeffrey (https://github.com/chjj/)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2011 Mark Cavage, All rights reserved.
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE
@@ -0,0 +1,50 @@
1
+ node-asn1 is a library for encoding and decoding ASN.1 datatypes in pure JS.
2
+ Currently BER encoding is supported; at some point I'll likely have to do DER.
3
+
4
+ ## Usage
5
+
6
+ Mostly, if you're *actually* needing to read and write ASN.1, you probably don't
7
+ need this readme to explain what and why. If you have no idea what ASN.1 is,
8
+ see this: ftp://ftp.rsa.com/pub/pkcs/ascii/layman.asc
9
+
10
+ The source is pretty much self-explanatory, and has read/write methods for the
11
+ common types out there.
12
+
13
+ ### Decoding
14
+
15
+ The following reads an ASN.1 sequence with a boolean.
16
+
17
+ var Ber = require('asn1').Ber;
18
+
19
+ var reader = new Ber.Reader(Buffer.from([0x30, 0x03, 0x01, 0x01, 0xff]));
20
+
21
+ reader.readSequence();
22
+ console.log('Sequence len: ' + reader.length);
23
+ if (reader.peek() === Ber.Boolean)
24
+ console.log(reader.readBoolean());
25
+
26
+ ### Encoding
27
+
28
+ The following generates the same payload as above.
29
+
30
+ var Ber = require('asn1').Ber;
31
+
32
+ var writer = new Ber.Writer();
33
+
34
+ writer.startSequence();
35
+ writer.writeBoolean(true);
36
+ writer.endSequence();
37
+
38
+ console.log(writer.buffer);
39
+
40
+ ## Installation
41
+
42
+ npm install asn1
43
+
44
+ ## License
45
+
46
+ MIT.
47
+
48
+ ## Bugs
49
+
50
+ See <https://github.com/joyent/node-asn1/issues>.
@@ -0,0 +1,13 @@
1
+ // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
2
+
3
+
4
+ module.exports = {
5
+
6
+ newInvalidAsn1Error: function (msg) {
7
+ var e = new Error();
8
+ e.name = 'InvalidAsn1Error';
9
+ e.message = msg || '';
10
+ return e;
11
+ }
12
+
13
+ };
@@ -0,0 +1,27 @@
1
+ // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
2
+
3
+ var errors = require('./errors');
4
+ var types = require('./types');
5
+
6
+ var Reader = require('./reader');
7
+ var Writer = require('./writer');
8
+
9
+
10
+ // --- Exports
11
+
12
+ module.exports = {
13
+
14
+ Reader: Reader,
15
+
16
+ Writer: Writer
17
+
18
+ };
19
+
20
+ for (var t in types) {
21
+ if (types.hasOwnProperty(t))
22
+ module.exports[t] = types[t];
23
+ }
24
+ for (var e in errors) {
25
+ if (errors.hasOwnProperty(e))
26
+ module.exports[e] = errors[e];
27
+ }
@@ -0,0 +1,262 @@
1
+ // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
2
+
3
+ var assert = require('assert');
4
+ var Buffer = require('safer-buffer').Buffer;
5
+
6
+ var ASN1 = require('./types');
7
+ var errors = require('./errors');
8
+
9
+
10
+ // --- Globals
11
+
12
+ var newInvalidAsn1Error = errors.newInvalidAsn1Error;
13
+
14
+
15
+
16
+ // --- API
17
+
18
+ function Reader(data) {
19
+ if (!data || !Buffer.isBuffer(data))
20
+ throw new TypeError('data must be a node Buffer');
21
+
22
+ this._buf = data;
23
+ this._size = data.length;
24
+
25
+ // These hold the "current" state
26
+ this._len = 0;
27
+ this._offset = 0;
28
+ }
29
+
30
+ Object.defineProperty(Reader.prototype, 'length', {
31
+ enumerable: true,
32
+ get: function () { return (this._len); }
33
+ });
34
+
35
+ Object.defineProperty(Reader.prototype, 'offset', {
36
+ enumerable: true,
37
+ get: function () { return (this._offset); }
38
+ });
39
+
40
+ Object.defineProperty(Reader.prototype, 'remain', {
41
+ get: function () { return (this._size - this._offset); }
42
+ });
43
+
44
+ Object.defineProperty(Reader.prototype, 'buffer', {
45
+ get: function () { return (this._buf.slice(this._offset)); }
46
+ });
47
+
48
+
49
+ /**
50
+ * Reads a single byte and advances offset; you can pass in `true` to make this
51
+ * a "peek" operation (i.e., get the byte, but don't advance the offset).
52
+ *
53
+ * @param {Boolean} peek true means don't move offset.
54
+ * @return {Number} the next byte, null if not enough data.
55
+ */
56
+ Reader.prototype.readByte = function (peek) {
57
+ if (this._size - this._offset < 1)
58
+ return null;
59
+
60
+ var b = this._buf[this._offset] & 0xff;
61
+
62
+ if (!peek)
63
+ this._offset += 1;
64
+
65
+ return b;
66
+ };
67
+
68
+
69
+ Reader.prototype.peek = function () {
70
+ return this.readByte(true);
71
+ };
72
+
73
+
74
+ /**
75
+ * Reads a (potentially) variable length off the BER buffer. This call is
76
+ * not really meant to be called directly, as callers have to manipulate
77
+ * the internal buffer afterwards.
78
+ *
79
+ * As a result of this call, you can call `Reader.length`, until the
80
+ * next thing called that does a readLength.
81
+ *
82
+ * @return {Number} the amount of offset to advance the buffer.
83
+ * @throws {InvalidAsn1Error} on bad ASN.1
84
+ */
85
+ Reader.prototype.readLength = function (offset) {
86
+ if (offset === undefined)
87
+ offset = this._offset;
88
+
89
+ if (offset >= this._size)
90
+ return null;
91
+
92
+ var lenB = this._buf[offset++] & 0xff;
93
+ if (lenB === null)
94
+ return null;
95
+
96
+ if ((lenB & 0x80) === 0x80) {
97
+ lenB &= 0x7f;
98
+
99
+ if (lenB === 0)
100
+ throw newInvalidAsn1Error('Indefinite length not supported');
101
+
102
+ if (lenB > 4)
103
+ throw newInvalidAsn1Error('encoding too long');
104
+
105
+ if (this._size - offset < lenB)
106
+ return null;
107
+
108
+ this._len = 0;
109
+ for (var i = 0; i < lenB; i++)
110
+ this._len = (this._len << 8) + (this._buf[offset++] & 0xff);
111
+
112
+ } else {
113
+ // Wasn't a variable length
114
+ this._len = lenB;
115
+ }
116
+
117
+ return offset;
118
+ };
119
+
120
+
121
+ /**
122
+ * Parses the next sequence in this BER buffer.
123
+ *
124
+ * To get the length of the sequence, call `Reader.length`.
125
+ *
126
+ * @return {Number} the sequence's tag.
127
+ */
128
+ Reader.prototype.readSequence = function (tag) {
129
+ var seq = this.peek();
130
+ if (seq === null)
131
+ return null;
132
+ if (tag !== undefined && tag !== seq)
133
+ throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) +
134
+ ': got 0x' + seq.toString(16));
135
+
136
+ var o = this.readLength(this._offset + 1); // stored in `length`
137
+ if (o === null)
138
+ return null;
139
+
140
+ this._offset = o;
141
+ return seq;
142
+ };
143
+
144
+
145
+ Reader.prototype.readInt = function () {
146
+ return this._readTag(ASN1.Integer);
147
+ };
148
+
149
+
150
+ Reader.prototype.readBoolean = function () {
151
+ return (this._readTag(ASN1.Boolean) === 0 ? false : true);
152
+ };
153
+
154
+
155
+ Reader.prototype.readEnumeration = function () {
156
+ return this._readTag(ASN1.Enumeration);
157
+ };
158
+
159
+
160
+ Reader.prototype.readString = function (tag, retbuf) {
161
+ if (!tag)
162
+ tag = ASN1.OctetString;
163
+
164
+ var b = this.peek();
165
+ if (b === null)
166
+ return null;
167
+
168
+ if (b !== tag)
169
+ throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) +
170
+ ': got 0x' + b.toString(16));
171
+
172
+ var o = this.readLength(this._offset + 1); // stored in `length`
173
+
174
+ if (o === null)
175
+ return null;
176
+
177
+ if (this.length > this._size - o)
178
+ return null;
179
+
180
+ this._offset = o;
181
+
182
+ if (this.length === 0)
183
+ return retbuf ? Buffer.alloc(0) : '';
184
+
185
+ var str = this._buf.slice(this._offset, this._offset + this.length);
186
+ this._offset += this.length;
187
+
188
+ return retbuf ? str : str.toString('utf8');
189
+ };
190
+
191
+ Reader.prototype.readOID = function (tag) {
192
+ if (!tag)
193
+ tag = ASN1.OID;
194
+
195
+ var b = this.readString(tag, true);
196
+ if (b === null)
197
+ return null;
198
+
199
+ var values = [];
200
+ var value = 0;
201
+
202
+ for (var i = 0; i < b.length; i++) {
203
+ var byte = b[i] & 0xff;
204
+
205
+ value <<= 7;
206
+ value += byte & 0x7f;
207
+ if ((byte & 0x80) === 0) {
208
+ values.push(value);
209
+ value = 0;
210
+ }
211
+ }
212
+
213
+ value = values.shift();
214
+ values.unshift(value % 40);
215
+ values.unshift((value / 40) >> 0);
216
+
217
+ return values.join('.');
218
+ };
219
+
220
+
221
+ Reader.prototype._readTag = function (tag) {
222
+ assert.ok(tag !== undefined);
223
+
224
+ var b = this.peek();
225
+
226
+ if (b === null)
227
+ return null;
228
+
229
+ if (b !== tag)
230
+ throw newInvalidAsn1Error('Expected 0x' + tag.toString(16) +
231
+ ': got 0x' + b.toString(16));
232
+
233
+ var o = this.readLength(this._offset + 1); // stored in `length`
234
+ if (o === null)
235
+ return null;
236
+
237
+ if (this.length > 4)
238
+ throw newInvalidAsn1Error('Integer too long: ' + this.length);
239
+
240
+ if (this.length > this._size - o)
241
+ return null;
242
+ this._offset = o;
243
+
244
+ var fb = this._buf[this._offset];
245
+ var value = 0;
246
+
247
+ for (var i = 0; i < this.length; i++) {
248
+ value <<= 8;
249
+ value |= (this._buf[this._offset++] & 0xff);
250
+ }
251
+
252
+ if ((fb & 0x80) === 0x80 && i !== 4)
253
+ value -= (1 << (i * 8));
254
+
255
+ return value >> 0;
256
+ };
257
+
258
+
259
+
260
+ // --- Exported API
261
+
262
+ module.exports = Reader;
@@ -0,0 +1,36 @@
1
+ // Copyright 2011 Mark Cavage <mcavage@gmail.com> All rights reserved.
2
+
3
+
4
+ module.exports = {
5
+ EOC: 0,
6
+ Boolean: 1,
7
+ Integer: 2,
8
+ BitString: 3,
9
+ OctetString: 4,
10
+ Null: 5,
11
+ OID: 6,
12
+ ObjectDescriptor: 7,
13
+ External: 8,
14
+ Real: 9, // float
15
+ Enumeration: 10,
16
+ PDV: 11,
17
+ Utf8String: 12,
18
+ RelativeOID: 13,
19
+ Sequence: 16,
20
+ Set: 17,
21
+ NumericString: 18,
22
+ PrintableString: 19,
23
+ T61String: 20,
24
+ VideotexString: 21,
25
+ IA5String: 22,
26
+ UTCTime: 23,
27
+ GeneralizedTime: 24,
28
+ GraphicString: 25,
29
+ VisibleString: 26,
30
+ GeneralString: 28,
31
+ UniversalString: 29,
32
+ CharacterString: 30,
33
+ BMPString: 31,
34
+ Constructor: 32,
35
+ Context: 128
36
+ };