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.
 
 
 
 
 
 

78 lines
1.9 KiB

var sys = require("sys");
try {
var binding = process.binding('crypto');
var SecureContext = binding.SecureContext;
var SecureStream = binding.SecureStream;
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;
}
function Credentials(method) {
if (!crypto) {
throw new Error('node.js not compiled with openssl crypto support.');
}
this.context = new SecureContext();
if (method) this.context.init(method);
else this.context.init();
}
exports.createCredentials = function(cred) {
var c = new Credentials(cred.method);
if (cred.key) c.context.setKey(cred.key);
if (cred.cert) c.context.setCert(cred.cert);
if (cred.ca) {
if ( (typeof(cred.ca) == 'object') && cred.ca.length ) {
for(var i=0; i<cred.ca.length; i++)
c.context.addCACert(cred.ca[i]);
} else {
c.context.addCACert(cred.ca);
}
}
return c;
}
exports.Credentials = Credentials;
exports.Hash = Hash;
exports.createHash = function(hash) {
return (new Hash).init(hash);
}
exports.Hmac = Hmac;
exports.createHmac = function(hmac, key) {
return (new Hmac).init(hmac, key);
}
exports.Cipher = Cipher;
exports.createCipher = function(cipher, key) {
return (new Cipher).init(cipher, key);
}
exports.createCipheriv = function(cipher, key, iv) {
return (new Cipher).initiv(cipher, key, iv);
}
exports.Decipher = Decipher;
exports.createDecipher = function(cipher, key) {
return (new Decipher).init(cipher, key);
}
exports.createDecipheriv = function(cipher, key, iv) {
return (new Decipher).initiv(cipher, key, iv);
}
exports.Sign = Sign;
exports.createSign = function(algorithm) {
return (new Sign).init(algorithm);
}
exports.Verify = Verify;
exports.createVerify = function(algorithm) {
return (new Verify).init(algorithm);
}