macgyver 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/Gemfile +4 -0
- data/LICENSE +20 -0
- data/README.md +45 -0
- data/Rakefile +1 -0
- data/assets/MacGap.app/Contents/Frameworks/Growl.framework/Growl +0 -0
- data/assets/MacGap.app/Contents/Frameworks/Growl.framework/Versions/A/Growl +0 -0
- data/assets/MacGap.app/Contents/Frameworks/Growl.framework/Versions/A/Headers/Growl.h +5 -0
- data/assets/MacGap.app/Contents/Frameworks/Growl.framework/Versions/A/Headers/GrowlApplicationBridge.h +551 -0
- data/assets/MacGap.app/Contents/Frameworks/Growl.framework/Versions/A/Headers/GrowlDefines.h +341 -0
- data/assets/MacGap.app/Contents/Frameworks/Growl.framework/Versions/A/Resources/Info.plist +40 -0
- data/assets/MacGap.app/Contents/Frameworks/Growl.framework/Versions/A/_CodeSignature/CodeResources +34 -0
- data/assets/MacGap.app/Contents/Info.plist +48 -0
- data/assets/MacGap.app/Contents/MacOS/MacGap +0 -0
- data/assets/MacGap.app/Contents/PkgInfo +1 -0
- data/assets/MacGap.app/Contents/Resources/_debugger.js +1718 -0
- data/assets/MacGap.app/Contents/Resources/_http_agent.js +310 -0
- data/assets/MacGap.app/Contents/Resources/_http_client.js +533 -0
- data/assets/MacGap.app/Contents/Resources/_http_common.js +222 -0
- data/assets/MacGap.app/Contents/Resources/_http_incoming.js +194 -0
- data/assets/MacGap.app/Contents/Resources/_http_outgoing.js +597 -0
- data/assets/MacGap.app/Contents/Resources/_http_server.js +510 -0
- data/assets/MacGap.app/Contents/Resources/_linklist.js +76 -0
- data/assets/MacGap.app/Contents/Resources/_stream_duplex.js +69 -0
- data/assets/MacGap.app/Contents/Resources/_stream_passthrough.js +41 -0
- data/assets/MacGap.app/Contents/Resources/_stream_readable.js +900 -0
- data/assets/MacGap.app/Contents/Resources/_stream_transform.js +204 -0
- data/assets/MacGap.app/Contents/Resources/_stream_writable.js +456 -0
- data/assets/MacGap.app/Contents/Resources/_tls_legacy.js +887 -0
- data/assets/MacGap.app/Contents/Resources/_tls_wrap.js +831 -0
- data/assets/MacGap.app/Contents/Resources/application.icns +0 -0
- data/assets/MacGap.app/Contents/Resources/assert.js +326 -0
- data/assets/MacGap.app/Contents/Resources/buffer.js +724 -0
- data/assets/MacGap.app/Contents/Resources/child_process.js +1107 -0
- data/assets/MacGap.app/Contents/Resources/cluster.js +613 -0
- data/assets/MacGap.app/Contents/Resources/console.js +108 -0
- data/assets/MacGap.app/Contents/Resources/constants.js +22 -0
- data/assets/MacGap.app/Contents/Resources/crypto.js +691 -0
- data/assets/MacGap.app/Contents/Resources/dgram.js +459 -0
- data/assets/MacGap.app/Contents/Resources/dns.js +274 -0
- data/assets/MacGap.app/Contents/Resources/domain.js +292 -0
- data/assets/MacGap.app/Contents/Resources/en.lproj/Credits.rtf +29 -0
- data/assets/MacGap.app/Contents/Resources/en.lproj/InfoPlist.strings +0 -0
- data/assets/MacGap.app/Contents/Resources/en.lproj/MainMenu.nib +0 -0
- data/assets/MacGap.app/Contents/Resources/en.lproj/Window.nib +0 -0
- data/assets/MacGap.app/Contents/Resources/events.js +312 -0
- data/assets/MacGap.app/Contents/Resources/freelist.js +43 -0
- data/assets/MacGap.app/Contents/Resources/fs.js +1732 -0
- data/assets/MacGap.app/Contents/Resources/http.js +119 -0
- data/assets/MacGap.app/Contents/Resources/https.js +134 -0
- data/assets/MacGap.app/Contents/Resources/module.js +529 -0
- data/assets/MacGap.app/Contents/Resources/net.js +1378 -0
- data/assets/MacGap.app/Contents/Resources/nodelike.js +195 -0
- data/assets/MacGap.app/Contents/Resources/os.js +64 -0
- data/assets/MacGap.app/Contents/Resources/path.js +517 -0
- data/assets/MacGap.app/Contents/Resources/public/index.html +38 -0
- data/assets/MacGap.app/Contents/Resources/punycode.js +507 -0
- data/assets/MacGap.app/Contents/Resources/querystring.js +206 -0
- data/assets/MacGap.app/Contents/Resources/readline.js +1311 -0
- data/assets/MacGap.app/Contents/Resources/repl.js +945 -0
- data/assets/MacGap.app/Contents/Resources/smalloc.js +90 -0
- data/assets/MacGap.app/Contents/Resources/stream.js +127 -0
- data/assets/MacGap.app/Contents/Resources/string_decoder.js +189 -0
- data/assets/MacGap.app/Contents/Resources/sys.js +24 -0
- data/assets/MacGap.app/Contents/Resources/timers.js +568 -0
- data/assets/MacGap.app/Contents/Resources/tls.js +220 -0
- data/assets/MacGap.app/Contents/Resources/tty.js +129 -0
- data/assets/MacGap.app/Contents/Resources/url.js +693 -0
- data/assets/MacGap.app/Contents/Resources/util.js +688 -0
- data/assets/MacGap.app/Contents/Resources/vm.js +73 -0
- data/assets/MacGap.app/Contents/Resources/zlib.js +524 -0
- data/assets/index.html +38 -0
- data/bin/macgyver +104 -0
- data/macgyver.gemspec +19 -0
- data/test/public/index.html +27 -0
- metadata +121 -0
@@ -0,0 +1,108 @@
|
|
1
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
2
|
+
//
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
4
|
+
// copy of this software and associated documentation files (the
|
5
|
+
// "Software"), to deal in the Software without restriction, including
|
6
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
8
|
+
// persons to whom the Software is furnished to do so, subject to the
|
9
|
+
// following conditions:
|
10
|
+
//
|
11
|
+
// The above copyright notice and this permission notice shall be included
|
12
|
+
// in all copies or substantial portions of the Software.
|
13
|
+
//
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
15
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
17
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
18
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
19
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
20
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
var util = require('util');
|
23
|
+
|
24
|
+
function Console(stdout, stderr) {
|
25
|
+
if (!(this instanceof Console)) {
|
26
|
+
return new Console(stdout, stderr);
|
27
|
+
}
|
28
|
+
if (!stdout || !util.isFunction(stdout.write)) {
|
29
|
+
throw new TypeError('Console expects a writable stream instance');
|
30
|
+
}
|
31
|
+
if (!stderr) {
|
32
|
+
stderr = stdout;
|
33
|
+
}
|
34
|
+
var prop = {
|
35
|
+
writable: true,
|
36
|
+
enumerable: false,
|
37
|
+
configurable: true
|
38
|
+
};
|
39
|
+
prop.value = stdout;
|
40
|
+
Object.defineProperty(this, '_stdout', prop);
|
41
|
+
prop.value = stderr;
|
42
|
+
Object.defineProperty(this, '_stderr', prop);
|
43
|
+
prop.value = {};
|
44
|
+
Object.defineProperty(this, '_times', prop);
|
45
|
+
|
46
|
+
// bind the prototype functions to this Console instance
|
47
|
+
Object.keys(Console.prototype).forEach(function(k) {
|
48
|
+
this[k] = this[k].bind(this);
|
49
|
+
}, this);
|
50
|
+
}
|
51
|
+
|
52
|
+
Console.prototype.log = function() {
|
53
|
+
this._stdout.write(util.format.apply(this, arguments) + '\n');
|
54
|
+
};
|
55
|
+
|
56
|
+
|
57
|
+
Console.prototype.info = Console.prototype.log;
|
58
|
+
|
59
|
+
|
60
|
+
Console.prototype.warn = function() {
|
61
|
+
this._stderr.write(util.format.apply(this, arguments) + '\n');
|
62
|
+
};
|
63
|
+
|
64
|
+
|
65
|
+
Console.prototype.error = Console.prototype.warn;
|
66
|
+
|
67
|
+
|
68
|
+
Console.prototype.dir = function(object) {
|
69
|
+
this._stdout.write(util.inspect(object, { customInspect: false }) + '\n');
|
70
|
+
};
|
71
|
+
|
72
|
+
|
73
|
+
Console.prototype.time = function(label) {
|
74
|
+
this._times[label] = Date.now();
|
75
|
+
};
|
76
|
+
|
77
|
+
|
78
|
+
Console.prototype.timeEnd = function(label) {
|
79
|
+
var time = this._times[label];
|
80
|
+
if (!time) {
|
81
|
+
throw new Error('No such label: ' + label);
|
82
|
+
}
|
83
|
+
var duration = Date.now() - time;
|
84
|
+
this.log('%s: %dms', label, duration);
|
85
|
+
};
|
86
|
+
|
87
|
+
|
88
|
+
Console.prototype.trace = function() {
|
89
|
+
// TODO probably can to do this better with V8's debug object once that is
|
90
|
+
// exposed.
|
91
|
+
var err = new Error;
|
92
|
+
err.name = 'Trace';
|
93
|
+
err.message = util.format.apply(this, arguments);
|
94
|
+
Error.captureStackTrace(err, arguments.callee);
|
95
|
+
this.error(err.stack);
|
96
|
+
};
|
97
|
+
|
98
|
+
|
99
|
+
Console.prototype.assert = function(expression) {
|
100
|
+
if (!expression) {
|
101
|
+
var arr = Array.prototype.slice.call(arguments, 1);
|
102
|
+
require('assert').ok(false, util.format.apply(this, arr));
|
103
|
+
}
|
104
|
+
};
|
105
|
+
|
106
|
+
|
107
|
+
module.exports = new Console(process.stdout, process.stderr);
|
108
|
+
module.exports.Console = Console;
|
@@ -0,0 +1,22 @@
|
|
1
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
2
|
+
//
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
4
|
+
// copy of this software and associated documentation files (the
|
5
|
+
// "Software"), to deal in the Software without restriction, including
|
6
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
8
|
+
// persons to whom the Software is furnished to do so, subject to the
|
9
|
+
// following conditions:
|
10
|
+
//
|
11
|
+
// The above copyright notice and this permission notice shall be included
|
12
|
+
// in all copies or substantial portions of the Software.
|
13
|
+
//
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
15
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
17
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
18
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
19
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
20
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
module.exports = process.binding('constants');
|
@@ -0,0 +1,691 @@
|
|
1
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
2
|
+
//
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
4
|
+
// copy of this software and associated documentation files (the
|
5
|
+
// "Software"), to deal in the Software without restriction, including
|
6
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
8
|
+
// persons to whom the Software is furnished to do so, subject to the
|
9
|
+
// following conditions:
|
10
|
+
//
|
11
|
+
// The above copyright notice and this permission notice shall be included
|
12
|
+
// in all copies or substantial portions of the Software.
|
13
|
+
//
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
15
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
17
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
18
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
19
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
20
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
+
|
22
|
+
// Note: In 0.8 and before, crypto functions all defaulted to using
|
23
|
+
// binary-encoded strings rather than buffers.
|
24
|
+
|
25
|
+
exports.DEFAULT_ENCODING = 'buffer';
|
26
|
+
|
27
|
+
try {
|
28
|
+
var binding = process.binding('crypto');
|
29
|
+
var SecureContext = binding.SecureContext;
|
30
|
+
var randomBytes = binding.randomBytes;
|
31
|
+
var pseudoRandomBytes = binding.pseudoRandomBytes;
|
32
|
+
var getCiphers = binding.getCiphers;
|
33
|
+
var getHashes = binding.getHashes;
|
34
|
+
} catch (e) {
|
35
|
+
throw new Error('node.js not compiled with openssl crypto support.');
|
36
|
+
}
|
37
|
+
|
38
|
+
var constants = require('constants');
|
39
|
+
var stream = require('stream');
|
40
|
+
var util = require('util');
|
41
|
+
|
42
|
+
// This is here because many functions accepted binary strings without
|
43
|
+
// any explicit encoding in older versions of node, and we don't want
|
44
|
+
// to break them unnecessarily.
|
45
|
+
function toBuf(str, encoding) {
|
46
|
+
encoding = encoding || 'binary';
|
47
|
+
if (util.isString(str)) {
|
48
|
+
if (encoding === 'buffer')
|
49
|
+
encoding = 'binary';
|
50
|
+
str = new Buffer(str, encoding);
|
51
|
+
}
|
52
|
+
return str;
|
53
|
+
}
|
54
|
+
|
55
|
+
|
56
|
+
var assert = require('assert');
|
57
|
+
var StringDecoder = require('string_decoder').StringDecoder;
|
58
|
+
|
59
|
+
function Credentials(secureProtocol, flags, context) {
|
60
|
+
if (!(this instanceof Credentials)) {
|
61
|
+
return new Credentials(secureProtocol, flags, context);
|
62
|
+
}
|
63
|
+
|
64
|
+
if (context) {
|
65
|
+
this.context = context;
|
66
|
+
} else {
|
67
|
+
this.context = new SecureContext();
|
68
|
+
|
69
|
+
if (secureProtocol) {
|
70
|
+
this.context.init(secureProtocol);
|
71
|
+
} else {
|
72
|
+
this.context.init();
|
73
|
+
}
|
74
|
+
}
|
75
|
+
|
76
|
+
if (flags) this.context.setOptions(flags);
|
77
|
+
}
|
78
|
+
|
79
|
+
exports.Credentials = Credentials;
|
80
|
+
|
81
|
+
function addNewline(buf) {
|
82
|
+
var last = buf[buf.length - 1];
|
83
|
+
var isBuf = Buffer.isBuffer(buf);
|
84
|
+
|
85
|
+
if (!isBuf && !util.isString(buf))
|
86
|
+
throw new Error('Certificate should be of type Buffer or string');
|
87
|
+
|
88
|
+
if (isBuf ? last !== 10 : last !== '\n')
|
89
|
+
return buf.toString().trim() + '\n';
|
90
|
+
else
|
91
|
+
return buf;
|
92
|
+
}
|
93
|
+
|
94
|
+
exports.createCredentials = function(options, context) {
|
95
|
+
if (!options) options = {};
|
96
|
+
|
97
|
+
var c = new Credentials(options.secureProtocol,
|
98
|
+
options.secureOptions,
|
99
|
+
context);
|
100
|
+
|
101
|
+
if (context) return c;
|
102
|
+
|
103
|
+
if (options.key) {
|
104
|
+
var key = addNewline(options.key);
|
105
|
+
if (options.passphrase) {
|
106
|
+
c.context.setKey(key, options.passphrase);
|
107
|
+
} else {
|
108
|
+
c.context.setKey(key);
|
109
|
+
}
|
110
|
+
}
|
111
|
+
|
112
|
+
if (options.cert) c.context.setCert(addNewline(options.cert));
|
113
|
+
|
114
|
+
if (options.ciphers) c.context.setCiphers(options.ciphers);
|
115
|
+
|
116
|
+
if (options.ecdhCurve) c.context.setECDHCurve(options.ecdhCurve);
|
117
|
+
|
118
|
+
if (options.ca) {
|
119
|
+
if (util.isArray(options.ca)) {
|
120
|
+
for (var i = 0, len = options.ca.length; i < len; i++) {
|
121
|
+
c.context.addCACert(options.ca[i]);
|
122
|
+
}
|
123
|
+
} else {
|
124
|
+
c.context.addCACert(options.ca);
|
125
|
+
}
|
126
|
+
} else {
|
127
|
+
c.context.addRootCerts();
|
128
|
+
}
|
129
|
+
|
130
|
+
if (options.crl) {
|
131
|
+
if (util.isArray(options.crl)) {
|
132
|
+
for (var i = 0, len = options.crl.length; i < len; i++) {
|
133
|
+
c.context.addCRL(options.crl[i]);
|
134
|
+
}
|
135
|
+
} else {
|
136
|
+
c.context.addCRL(options.crl);
|
137
|
+
}
|
138
|
+
}
|
139
|
+
|
140
|
+
if (options.sessionIdContext) {
|
141
|
+
c.context.setSessionIdContext(options.sessionIdContext);
|
142
|
+
}
|
143
|
+
|
144
|
+
if (options.pfx) {
|
145
|
+
var pfx = options.pfx;
|
146
|
+
var passphrase = options.passphrase;
|
147
|
+
|
148
|
+
pfx = toBuf(pfx);
|
149
|
+
if (passphrase)
|
150
|
+
passphrase = toBuf(passphrase);
|
151
|
+
|
152
|
+
if (passphrase) {
|
153
|
+
c.context.loadPKCS12(pfx, passphrase);
|
154
|
+
} else {
|
155
|
+
c.context.loadPKCS12(pfx);
|
156
|
+
}
|
157
|
+
}
|
158
|
+
|
159
|
+
return c;
|
160
|
+
};
|
161
|
+
|
162
|
+
|
163
|
+
function LazyTransform(options) {
|
164
|
+
this._options = options;
|
165
|
+
}
|
166
|
+
util.inherits(LazyTransform, stream.Transform);
|
167
|
+
|
168
|
+
[
|
169
|
+
'_readableState',
|
170
|
+
'_writableState',
|
171
|
+
'_transformState'
|
172
|
+
].forEach(function(prop, i, props) {
|
173
|
+
Object.defineProperty(LazyTransform.prototype, prop, {
|
174
|
+
get: function() {
|
175
|
+
stream.Transform.call(this, this._options);
|
176
|
+
this._writableState.decodeStrings = false;
|
177
|
+
this._writableState.defaultEncoding = 'binary';
|
178
|
+
return this[prop];
|
179
|
+
},
|
180
|
+
set: function(val) {
|
181
|
+
Object.defineProperty(this, prop, {
|
182
|
+
value: val,
|
183
|
+
enumerable: true,
|
184
|
+
configurable: true,
|
185
|
+
writable: true
|
186
|
+
});
|
187
|
+
},
|
188
|
+
configurable: true,
|
189
|
+
enumerable: true
|
190
|
+
});
|
191
|
+
});
|
192
|
+
|
193
|
+
|
194
|
+
exports.createHash = exports.Hash = Hash;
|
195
|
+
function Hash(algorithm, options) {
|
196
|
+
if (!(this instanceof Hash))
|
197
|
+
return new Hash(algorithm, options);
|
198
|
+
this._binding = new binding.Hash(algorithm);
|
199
|
+
LazyTransform.call(this, options);
|
200
|
+
}
|
201
|
+
|
202
|
+
util.inherits(Hash, LazyTransform);
|
203
|
+
|
204
|
+
Hash.prototype._transform = function(chunk, encoding, callback) {
|
205
|
+
this._binding.update(chunk, encoding);
|
206
|
+
callback();
|
207
|
+
};
|
208
|
+
|
209
|
+
Hash.prototype._flush = function(callback) {
|
210
|
+
var encoding = this._readableState.encoding || 'buffer';
|
211
|
+
this.push(this._binding.digest(encoding), encoding);
|
212
|
+
callback();
|
213
|
+
};
|
214
|
+
|
215
|
+
Hash.prototype.update = function(data, encoding) {
|
216
|
+
encoding = encoding || exports.DEFAULT_ENCODING;
|
217
|
+
if (encoding === 'buffer' && util.isString(data))
|
218
|
+
encoding = 'binary';
|
219
|
+
this._binding.update(data, encoding);
|
220
|
+
return this;
|
221
|
+
};
|
222
|
+
|
223
|
+
|
224
|
+
Hash.prototype.digest = function(outputEncoding) {
|
225
|
+
outputEncoding = outputEncoding || exports.DEFAULT_ENCODING;
|
226
|
+
return this._binding.digest(outputEncoding);
|
227
|
+
};
|
228
|
+
|
229
|
+
|
230
|
+
exports.createHmac = exports.Hmac = Hmac;
|
231
|
+
|
232
|
+
function Hmac(hmac, key, options) {
|
233
|
+
if (!(this instanceof Hmac))
|
234
|
+
return new Hmac(hmac, key, options);
|
235
|
+
this._binding = new binding.Hmac();
|
236
|
+
this._binding.init(hmac, toBuf(key));
|
237
|
+
LazyTransform.call(this, options);
|
238
|
+
}
|
239
|
+
|
240
|
+
util.inherits(Hmac, LazyTransform);
|
241
|
+
|
242
|
+
Hmac.prototype.update = Hash.prototype.update;
|
243
|
+
Hmac.prototype.digest = Hash.prototype.digest;
|
244
|
+
Hmac.prototype._flush = Hash.prototype._flush;
|
245
|
+
Hmac.prototype._transform = Hash.prototype._transform;
|
246
|
+
|
247
|
+
|
248
|
+
function getDecoder(decoder, encoding) {
|
249
|
+
if (encoding === 'utf-8') encoding = 'utf8'; // Normalize encoding.
|
250
|
+
decoder = decoder || new StringDecoder(encoding);
|
251
|
+
assert(decoder.encoding === encoding, 'Cannot change encoding');
|
252
|
+
return decoder;
|
253
|
+
}
|
254
|
+
|
255
|
+
|
256
|
+
exports.createCipher = exports.Cipher = Cipher;
|
257
|
+
function Cipher(cipher, password, options) {
|
258
|
+
if (!(this instanceof Cipher))
|
259
|
+
return new Cipher(cipher, password, options);
|
260
|
+
this._binding = new binding.CipherBase(true);
|
261
|
+
|
262
|
+
this._binding.init(cipher, toBuf(password));
|
263
|
+
this._decoder = null;
|
264
|
+
|
265
|
+
LazyTransform.call(this, options);
|
266
|
+
}
|
267
|
+
|
268
|
+
util.inherits(Cipher, LazyTransform);
|
269
|
+
|
270
|
+
Cipher.prototype._transform = function(chunk, encoding, callback) {
|
271
|
+
this.push(this._binding.update(chunk, encoding));
|
272
|
+
callback();
|
273
|
+
};
|
274
|
+
|
275
|
+
Cipher.prototype._flush = function(callback) {
|
276
|
+
try {
|
277
|
+
this.push(this._binding.final());
|
278
|
+
} catch (e) {
|
279
|
+
callback(e);
|
280
|
+
return;
|
281
|
+
}
|
282
|
+
callback();
|
283
|
+
};
|
284
|
+
|
285
|
+
Cipher.prototype.update = function(data, inputEncoding, outputEncoding) {
|
286
|
+
inputEncoding = inputEncoding || exports.DEFAULT_ENCODING;
|
287
|
+
outputEncoding = outputEncoding || exports.DEFAULT_ENCODING;
|
288
|
+
|
289
|
+
var ret = this._binding.update(data, inputEncoding);
|
290
|
+
|
291
|
+
if (outputEncoding && outputEncoding !== 'buffer') {
|
292
|
+
this._decoder = getDecoder(this._decoder, outputEncoding);
|
293
|
+
ret = this._decoder.write(ret);
|
294
|
+
}
|
295
|
+
|
296
|
+
return ret;
|
297
|
+
};
|
298
|
+
|
299
|
+
|
300
|
+
Cipher.prototype.final = function(outputEncoding) {
|
301
|
+
outputEncoding = outputEncoding || exports.DEFAULT_ENCODING;
|
302
|
+
var ret = this._binding.final();
|
303
|
+
|
304
|
+
if (outputEncoding && outputEncoding !== 'buffer') {
|
305
|
+
this._decoder = getDecoder(this._decoder, outputEncoding);
|
306
|
+
ret = this._decoder.end(ret);
|
307
|
+
}
|
308
|
+
|
309
|
+
return ret;
|
310
|
+
};
|
311
|
+
|
312
|
+
|
313
|
+
Cipher.prototype.setAutoPadding = function(ap) {
|
314
|
+
this._binding.setAutoPadding(ap);
|
315
|
+
return this;
|
316
|
+
};
|
317
|
+
|
318
|
+
|
319
|
+
|
320
|
+
exports.createCipheriv = exports.Cipheriv = Cipheriv;
|
321
|
+
function Cipheriv(cipher, key, iv, options) {
|
322
|
+
if (!(this instanceof Cipheriv))
|
323
|
+
return new Cipheriv(cipher, key, iv, options);
|
324
|
+
this._binding = new binding.CipherBase(true);
|
325
|
+
this._binding.initiv(cipher, toBuf(key), toBuf(iv));
|
326
|
+
this._decoder = null;
|
327
|
+
|
328
|
+
LazyTransform.call(this, options);
|
329
|
+
}
|
330
|
+
|
331
|
+
util.inherits(Cipheriv, LazyTransform);
|
332
|
+
|
333
|
+
Cipheriv.prototype._transform = Cipher.prototype._transform;
|
334
|
+
Cipheriv.prototype._flush = Cipher.prototype._flush;
|
335
|
+
Cipheriv.prototype.update = Cipher.prototype.update;
|
336
|
+
Cipheriv.prototype.final = Cipher.prototype.final;
|
337
|
+
Cipheriv.prototype.setAutoPadding = Cipher.prototype.setAutoPadding;
|
338
|
+
|
339
|
+
Cipheriv.prototype.getAuthTag = function() {
|
340
|
+
return this._binding.getAuthTag();
|
341
|
+
};
|
342
|
+
|
343
|
+
|
344
|
+
Cipheriv.prototype.setAuthTag = function(tagbuf) {
|
345
|
+
this._binding.setAuthTag(tagbuf);
|
346
|
+
};
|
347
|
+
|
348
|
+
|
349
|
+
|
350
|
+
exports.createDecipher = exports.Decipher = Decipher;
|
351
|
+
function Decipher(cipher, password, options) {
|
352
|
+
if (!(this instanceof Decipher))
|
353
|
+
return new Decipher(cipher, password, options);
|
354
|
+
|
355
|
+
this._binding = new binding.CipherBase(false);
|
356
|
+
this._binding.init(cipher, toBuf(password));
|
357
|
+
this._decoder = null;
|
358
|
+
|
359
|
+
LazyTransform.call(this, options);
|
360
|
+
}
|
361
|
+
|
362
|
+
util.inherits(Decipher, LazyTransform);
|
363
|
+
|
364
|
+
Decipher.prototype._transform = Cipher.prototype._transform;
|
365
|
+
Decipher.prototype._flush = Cipher.prototype._flush;
|
366
|
+
Decipher.prototype.update = Cipher.prototype.update;
|
367
|
+
Decipher.prototype.final = Cipher.prototype.final;
|
368
|
+
Decipher.prototype.finaltol = Cipher.prototype.final;
|
369
|
+
Decipher.prototype.setAutoPadding = Cipher.prototype.setAutoPadding;
|
370
|
+
|
371
|
+
|
372
|
+
|
373
|
+
exports.createDecipheriv = exports.Decipheriv = Decipheriv;
|
374
|
+
function Decipheriv(cipher, key, iv, options) {
|
375
|
+
if (!(this instanceof Decipheriv))
|
376
|
+
return new Decipheriv(cipher, key, iv, options);
|
377
|
+
|
378
|
+
this._binding = new binding.CipherBase(false);
|
379
|
+
this._binding.initiv(cipher, toBuf(key), toBuf(iv));
|
380
|
+
this._decoder = null;
|
381
|
+
|
382
|
+
LazyTransform.call(this, options);
|
383
|
+
}
|
384
|
+
|
385
|
+
util.inherits(Decipheriv, LazyTransform);
|
386
|
+
|
387
|
+
Decipheriv.prototype._transform = Cipher.prototype._transform;
|
388
|
+
Decipheriv.prototype._flush = Cipher.prototype._flush;
|
389
|
+
Decipheriv.prototype.update = Cipher.prototype.update;
|
390
|
+
Decipheriv.prototype.final = Cipher.prototype.final;
|
391
|
+
Decipheriv.prototype.finaltol = Cipher.prototype.final;
|
392
|
+
Decipheriv.prototype.setAutoPadding = Cipher.prototype.setAutoPadding;
|
393
|
+
Decipheriv.prototype.getAuthTag = Cipheriv.prototype.getAuthTag;
|
394
|
+
Decipheriv.prototype.setAuthTag = Cipheriv.prototype.setAuthTag;
|
395
|
+
|
396
|
+
|
397
|
+
|
398
|
+
exports.createSign = exports.Sign = Sign;
|
399
|
+
function Sign(algorithm, options) {
|
400
|
+
if (!(this instanceof Sign))
|
401
|
+
return new Sign(algorithm, options);
|
402
|
+
this._binding = new binding.Sign();
|
403
|
+
this._binding.init(algorithm);
|
404
|
+
|
405
|
+
stream.Writable.call(this, options);
|
406
|
+
}
|
407
|
+
|
408
|
+
util.inherits(Sign, stream.Writable);
|
409
|
+
|
410
|
+
Sign.prototype._write = function(chunk, encoding, callback) {
|
411
|
+
this._binding.update(chunk, encoding);
|
412
|
+
callback();
|
413
|
+
};
|
414
|
+
|
415
|
+
Sign.prototype.update = Hash.prototype.update;
|
416
|
+
|
417
|
+
Sign.prototype.sign = function(options, encoding) {
|
418
|
+
if (!options)
|
419
|
+
throw new Error('No key provided to sign');
|
420
|
+
|
421
|
+
var key = options.key || options;
|
422
|
+
var passphrase = options.passphrase || null;
|
423
|
+
var ret = this._binding.sign(toBuf(key), null, passphrase);
|
424
|
+
|
425
|
+
encoding = encoding || exports.DEFAULT_ENCODING;
|
426
|
+
if (encoding && encoding !== 'buffer')
|
427
|
+
ret = ret.toString(encoding);
|
428
|
+
|
429
|
+
return ret;
|
430
|
+
};
|
431
|
+
|
432
|
+
|
433
|
+
|
434
|
+
exports.createVerify = exports.Verify = Verify;
|
435
|
+
function Verify(algorithm, options) {
|
436
|
+
if (!(this instanceof Verify))
|
437
|
+
return new Verify(algorithm, options);
|
438
|
+
|
439
|
+
this._binding = new binding.Verify;
|
440
|
+
this._binding.init(algorithm);
|
441
|
+
|
442
|
+
stream.Writable.call(this, options);
|
443
|
+
}
|
444
|
+
|
445
|
+
util.inherits(Verify, stream.Writable);
|
446
|
+
|
447
|
+
Verify.prototype._write = Sign.prototype._write;
|
448
|
+
Verify.prototype.update = Sign.prototype.update;
|
449
|
+
|
450
|
+
Verify.prototype.verify = function(object, signature, sigEncoding) {
|
451
|
+
sigEncoding = sigEncoding || exports.DEFAULT_ENCODING;
|
452
|
+
return this._binding.verify(toBuf(object), toBuf(signature, sigEncoding));
|
453
|
+
};
|
454
|
+
|
455
|
+
|
456
|
+
|
457
|
+
exports.createDiffieHellman = exports.DiffieHellman = DiffieHellman;
|
458
|
+
|
459
|
+
function DiffieHellman(sizeOrKey, encoding) {
|
460
|
+
if (!(this instanceof DiffieHellman))
|
461
|
+
return new DiffieHellman(sizeOrKey, encoding);
|
462
|
+
|
463
|
+
if (!sizeOrKey)
|
464
|
+
this._binding = new binding.DiffieHellman();
|
465
|
+
else {
|
466
|
+
encoding = encoding || exports.DEFAULT_ENCODING;
|
467
|
+
sizeOrKey = toBuf(sizeOrKey, encoding);
|
468
|
+
this._binding = new binding.DiffieHellman(sizeOrKey);
|
469
|
+
}
|
470
|
+
}
|
471
|
+
|
472
|
+
|
473
|
+
exports.DiffieHellmanGroup =
|
474
|
+
exports.createDiffieHellmanGroup =
|
475
|
+
exports.getDiffieHellman = DiffieHellmanGroup;
|
476
|
+
|
477
|
+
function DiffieHellmanGroup(name) {
|
478
|
+
if (!(this instanceof DiffieHellmanGroup))
|
479
|
+
return new DiffieHellmanGroup(name);
|
480
|
+
this._binding = new binding.DiffieHellmanGroup(name);
|
481
|
+
}
|
482
|
+
|
483
|
+
|
484
|
+
DiffieHellmanGroup.prototype.generateKeys =
|
485
|
+
DiffieHellman.prototype.generateKeys =
|
486
|
+
dhGenerateKeys;
|
487
|
+
|
488
|
+
function dhGenerateKeys(encoding) {
|
489
|
+
var keys = this._binding.generateKeys();
|
490
|
+
encoding = encoding || exports.DEFAULT_ENCODING;
|
491
|
+
if (encoding && encoding !== 'buffer')
|
492
|
+
keys = keys.toString(encoding);
|
493
|
+
return keys;
|
494
|
+
}
|
495
|
+
|
496
|
+
|
497
|
+
DiffieHellmanGroup.prototype.computeSecret =
|
498
|
+
DiffieHellman.prototype.computeSecret =
|
499
|
+
dhComputeSecret;
|
500
|
+
|
501
|
+
function dhComputeSecret(key, inEnc, outEnc) {
|
502
|
+
inEnc = inEnc || exports.DEFAULT_ENCODING;
|
503
|
+
outEnc = outEnc || exports.DEFAULT_ENCODING;
|
504
|
+
var ret = this._binding.computeSecret(toBuf(key, inEnc));
|
505
|
+
if (outEnc && outEnc !== 'buffer')
|
506
|
+
ret = ret.toString(outEnc);
|
507
|
+
return ret;
|
508
|
+
}
|
509
|
+
|
510
|
+
|
511
|
+
DiffieHellmanGroup.prototype.getPrime =
|
512
|
+
DiffieHellman.prototype.getPrime =
|
513
|
+
dhGetPrime;
|
514
|
+
|
515
|
+
function dhGetPrime(encoding) {
|
516
|
+
var prime = this._binding.getPrime();
|
517
|
+
encoding = encoding || exports.DEFAULT_ENCODING;
|
518
|
+
if (encoding && encoding !== 'buffer')
|
519
|
+
prime = prime.toString(encoding);
|
520
|
+
return prime;
|
521
|
+
}
|
522
|
+
|
523
|
+
|
524
|
+
DiffieHellmanGroup.prototype.getGenerator =
|
525
|
+
DiffieHellman.prototype.getGenerator =
|
526
|
+
dhGetGenerator;
|
527
|
+
|
528
|
+
function dhGetGenerator(encoding) {
|
529
|
+
var generator = this._binding.getGenerator();
|
530
|
+
encoding = encoding || exports.DEFAULT_ENCODING;
|
531
|
+
if (encoding && encoding !== 'buffer')
|
532
|
+
generator = generator.toString(encoding);
|
533
|
+
return generator;
|
534
|
+
}
|
535
|
+
|
536
|
+
|
537
|
+
DiffieHellmanGroup.prototype.getPublicKey =
|
538
|
+
DiffieHellman.prototype.getPublicKey =
|
539
|
+
dhGetPublicKey;
|
540
|
+
|
541
|
+
function dhGetPublicKey(encoding) {
|
542
|
+
var key = this._binding.getPublicKey();
|
543
|
+
encoding = encoding || exports.DEFAULT_ENCODING;
|
544
|
+
if (encoding && encoding !== 'buffer')
|
545
|
+
key = key.toString(encoding);
|
546
|
+
return key;
|
547
|
+
}
|
548
|
+
|
549
|
+
|
550
|
+
DiffieHellmanGroup.prototype.getPrivateKey =
|
551
|
+
DiffieHellman.prototype.getPrivateKey =
|
552
|
+
dhGetPrivateKey;
|
553
|
+
|
554
|
+
function dhGetPrivateKey(encoding) {
|
555
|
+
var key = this._binding.getPrivateKey();
|
556
|
+
encoding = encoding || exports.DEFAULT_ENCODING;
|
557
|
+
if (encoding && encoding !== 'buffer')
|
558
|
+
key = key.toString(encoding);
|
559
|
+
return key;
|
560
|
+
}
|
561
|
+
|
562
|
+
|
563
|
+
DiffieHellman.prototype.setPublicKey = function(key, encoding) {
|
564
|
+
encoding = encoding || exports.DEFAULT_ENCODING;
|
565
|
+
this._binding.setPublicKey(toBuf(key, encoding));
|
566
|
+
return this;
|
567
|
+
};
|
568
|
+
|
569
|
+
|
570
|
+
DiffieHellman.prototype.setPrivateKey = function(key, encoding) {
|
571
|
+
encoding = encoding || exports.DEFAULT_ENCODING;
|
572
|
+
this._binding.setPrivateKey(toBuf(key, encoding));
|
573
|
+
return this;
|
574
|
+
};
|
575
|
+
|
576
|
+
|
577
|
+
|
578
|
+
exports.pbkdf2 = function(password,
|
579
|
+
salt,
|
580
|
+
iterations,
|
581
|
+
keylen,
|
582
|
+
digest,
|
583
|
+
callback) {
|
584
|
+
if (util.isFunction(digest)) {
|
585
|
+
callback = digest;
|
586
|
+
digest = undefined;
|
587
|
+
}
|
588
|
+
|
589
|
+
if (!util.isFunction(callback))
|
590
|
+
throw new Error('No callback provided to pbkdf2');
|
591
|
+
|
592
|
+
return pbkdf2(password, salt, iterations, keylen, digest, callback);
|
593
|
+
};
|
594
|
+
|
595
|
+
|
596
|
+
exports.pbkdf2Sync = function(password, salt, iterations, keylen, digest) {
|
597
|
+
return pbkdf2(password, salt, iterations, keylen, digest);
|
598
|
+
};
|
599
|
+
|
600
|
+
|
601
|
+
function pbkdf2(password, salt, iterations, keylen, digest, callback) {
|
602
|
+
password = toBuf(password);
|
603
|
+
salt = toBuf(salt);
|
604
|
+
|
605
|
+
if (exports.DEFAULT_ENCODING === 'buffer')
|
606
|
+
return binding.PBKDF2(password, salt, iterations, keylen, digest, callback);
|
607
|
+
|
608
|
+
// at this point, we need to handle encodings.
|
609
|
+
var encoding = exports.DEFAULT_ENCODING;
|
610
|
+
if (callback) {
|
611
|
+
function next(er, ret) {
|
612
|
+
if (ret)
|
613
|
+
ret = ret.toString(encoding);
|
614
|
+
callback(er, ret);
|
615
|
+
}
|
616
|
+
binding.PBKDF2(password, salt, iterations, keylen, digest, next);
|
617
|
+
} else {
|
618
|
+
var ret = binding.PBKDF2(password, salt, iterations, keylen, digest);
|
619
|
+
return ret.toString(encoding);
|
620
|
+
}
|
621
|
+
}
|
622
|
+
|
623
|
+
|
624
|
+
exports.Certificate = Certificate;
|
625
|
+
|
626
|
+
function Certificate() {
|
627
|
+
if (!(this instanceof Certificate))
|
628
|
+
return new Certificate();
|
629
|
+
|
630
|
+
this._binding = new binding.Certificate();
|
631
|
+
}
|
632
|
+
|
633
|
+
|
634
|
+
Certificate.prototype.verifySpkac = function(object) {
|
635
|
+
return this._binding.verifySpkac(object);
|
636
|
+
};
|
637
|
+
|
638
|
+
|
639
|
+
Certificate.prototype.exportPublicKey = function(object, encoding) {
|
640
|
+
return this._binding.exportPublicKey(toBuf(object, encoding));
|
641
|
+
};
|
642
|
+
|
643
|
+
|
644
|
+
Certificate.prototype.exportChallenge = function(object, encoding) {
|
645
|
+
return this._binding.exportChallenge(toBuf(object, encoding));
|
646
|
+
};
|
647
|
+
|
648
|
+
|
649
|
+
exports.setEngine = function setEngine(id, flags) {
|
650
|
+
if (!util.isString(id))
|
651
|
+
throw new TypeError('id should be a string');
|
652
|
+
|
653
|
+
if (flags && !util.isNumber(flags))
|
654
|
+
throw new TypeError('flags should be a number, if present');
|
655
|
+
flags = flags >>> 0;
|
656
|
+
|
657
|
+
// Use provided engine for everything by default
|
658
|
+
if (flags === 0)
|
659
|
+
flags = constants.ENGINE_METHOD_ALL;
|
660
|
+
|
661
|
+
return binding.setEngine(id, flags);
|
662
|
+
};
|
663
|
+
|
664
|
+
exports.randomBytes = randomBytes;
|
665
|
+
exports.pseudoRandomBytes = pseudoRandomBytes;
|
666
|
+
|
667
|
+
exports.rng = randomBytes;
|
668
|
+
exports.prng = pseudoRandomBytes;
|
669
|
+
|
670
|
+
|
671
|
+
exports.getCiphers = function() {
|
672
|
+
return filterDuplicates(getCiphers.call(null, arguments));
|
673
|
+
};
|
674
|
+
|
675
|
+
|
676
|
+
exports.getHashes = function() {
|
677
|
+
return filterDuplicates(getHashes.call(null, arguments));
|
678
|
+
|
679
|
+
};
|
680
|
+
|
681
|
+
|
682
|
+
function filterDuplicates(names) {
|
683
|
+
// Drop all-caps names in favor of their lowercase aliases,
|
684
|
+
// for example, 'sha1' instead of 'SHA1'.
|
685
|
+
var ctx = {};
|
686
|
+
names.forEach(function(name) {
|
687
|
+
if (/^[0-9A-Z\-]+$/.test(name)) name = name.toLowerCase();
|
688
|
+
ctx[name] = true;
|
689
|
+
});
|
690
|
+
return Object.getOwnPropertyNames(ctx).sort();
|
691
|
+
}
|