You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
2.1 KiB

try {
var binding = process.binding('crypto');
var SecureContext = binding.SecureContext;
var Hmac = binding.Hmac;
var Hash = binding.Hash;
var Cipher = binding.Cipher;
var Decipher = binding.Decipher;
var Sign = binding.Sign;
var Verify = binding.Verify;
var crypto = true;
} catch (e) {
var crypto = false;
}
14 years ago
function Credentials(method) {
14 years ago
if (!(this instanceof Credentials)) {
return new Credentials(method);
}
if (!crypto) {
14 years ago
throw new Error('node.js not compiled with openssl crypto support.');
}
14 years ago
this.context = new SecureContext();
14 years ago
if (method) {
this.context.init(method);
} else {
this.context.init();
}
}
14 years ago
exports.Credentials = Credentials;
14 years ago
exports.createCredentials = function(options) {
14 years ago
if (!options) options = {};
var c = new Credentials(options.method);
14 years ago
14 years ago
if (options.key) c.context.setKey(options.key);
if (options.cert) c.context.setCert(options.cert);
if (options.ca) {
if (Array.isArray(options.ca)) {
14 years ago
for (var i = 0, len = options.ca.length; i < len; i++) {
c.context.addCACert(options.ca[i]);
}
} else {
14 years ago
c.context.addCACert(options.ca);
}
} else {
c.context.addRootCerts();
}
14 years ago
return c;
};
14 years ago
exports.Hash = Hash;
14 years ago
exports.createHash = function(hash) {
return new Hash(hash);
};
14 years ago
exports.Hmac = Hmac;
14 years ago
exports.createHmac = function(hmac, key) {
return (new Hmac).init(hmac, key);
};
14 years ago
exports.Cipher = Cipher;
14 years ago
exports.createCipher = function(cipher, key) {
return (new Cipher).init(cipher, key);
};
14 years ago
14 years ago
exports.createCipheriv = function(cipher, key, iv) {
return (new Cipher).initiv(cipher, key, iv);
};
14 years ago
exports.Decipher = Decipher;
14 years ago
exports.createDecipher = function(cipher, key) {
return (new Decipher).init(cipher, key);
};
14 years ago
14 years ago
exports.createDecipheriv = function(cipher, key, iv) {
return (new Decipher).initiv(cipher, key, iv);
};
14 years ago
exports.Sign = Sign;
14 years ago
exports.createSign = function(algorithm) {
return (new Sign).init(algorithm);
};
exports.Verify = Verify;
14 years ago
exports.createVerify = function(algorithm) {
return (new Verify).init(algorithm);
};