Browse Source

style

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
bf89872306
  1. 40
      lib/crypto.js
  2. 2
      lib/securepair.js
  3. 34
      src/node_crypto.cc

40
lib/crypto.js

@ -3599,17 +3599,24 @@ try {
} }
function Credentials(method) { function Credentials (method) {
if (!crypto) { if (!crypto) {
throw new Error('node.js not compiled with openssl crypto support.'); throw new Error('node.js not compiled with openssl crypto support.');
} }
this.context = new SecureContext(); this.context = new SecureContext();
if (method) this.context.init(method);
else this.context.init(); if (method) {
this.context.init(method);
} else {
this.context.init();
}
this.shouldVerify = false; this.shouldVerify = false;
} }
exports.createCredentials = function(cred) {
exports.createCredentials = function (cred) {
if (!cred) cred={}; if (!cred) cred={};
var c = new Credentials(cred.method); var c = new Credentials(cred.method);
if (cred.key) c.context.setKey(cred.key); if (cred.key) c.context.setKey(cred.key);
@ -3631,45 +3638,54 @@ exports.createCredentials = function(cred) {
}; };
exports.Credentials = Credentials; exports.Credentials = Credentials;
exports.Hash = Hash; exports.Hash = Hash;
exports.createHash = function(hash) { exports.createHash = function (hash) {
return new Hash(hash); return new Hash(hash);
}; };
exports.Hmac = Hmac; exports.Hmac = Hmac;
exports.createHmac = function(hmac, key) { exports.createHmac = function (hmac, key) {
return (new Hmac).init(hmac, key); return (new Hmac).init(hmac, key);
}; };
exports.Cipher = Cipher; exports.Cipher = Cipher;
exports.createCipher = function(cipher, key) { exports.createCipher = function (cipher, key) {
return (new Cipher).init(cipher, key); return (new Cipher).init(cipher, key);
}; };
exports.createCipheriv = function(cipher, key, iv) {
exports.createCipheriv = function (cipher, key, iv) {
return (new Cipher).initiv(cipher, key, iv); return (new Cipher).initiv(cipher, key, iv);
}; };
exports.Decipher = Decipher; exports.Decipher = Decipher;
exports.createDecipher = function(cipher, key) { exports.createDecipher = function (cipher, key) {
return (new Decipher).init(cipher, key); return (new Decipher).init(cipher, key);
}; };
exports.createDecipheriv = function(cipher, key, iv) {
exports.createDecipheriv = function (cipher, key, iv) {
return (new Decipher).initiv(cipher, key, iv); return (new Decipher).initiv(cipher, key, iv);
}; };
exports.Sign = Sign; exports.Sign = Sign;
exports.createSign = function(algorithm) { exports.createSign = function (algorithm) {
return (new Sign).init(algorithm); return (new Sign).init(algorithm);
}; };
exports.Verify = Verify; exports.Verify = Verify;
exports.createVerify = function(algorithm) { exports.createVerify = function (algorithm) {
return (new Verify).init(algorithm); return (new Verify).init(algorithm);
}; };
exports.RootCaCerts = RootCaCerts; exports.RootCaCerts = RootCaCerts;
var securepair = require('securepair'); var securepair = require('securepair');
exports.createPair = securepair.createSecurePair; exports.createPair = securepair.createSecurePair;

2
lib/securepair.js

@ -345,7 +345,7 @@ SecurePair.prototype._destroy = function (err) {
if (!this._done) { if (!this._done) {
this._done = true; this._done = true;
this._ssl.close(); this._ssl.close();
delete this._ssl; this._ssl = null;
this.emit('end', err); this.emit('end', err);
} }
}; };

34
src/node_crypto.cc

@ -69,36 +69,36 @@ Handle<Value> SecureContext::Init(const Arguments& args) {
OPENSSL_CONST SSL_METHOD *method = SSLv23_method(); OPENSSL_CONST SSL_METHOD *method = SSLv23_method();
if (args.Length() == 1) { if (args.Length() == 1 && args[0]->IsString()) {
if (!args[0]->IsString())
return ThrowException(Exception::TypeError(
String::New("Bad parameter")));
String::Utf8Value sslmethod(args[0]->ToString()); String::Utf8Value sslmethod(args[0]->ToString());
if (strcmp(*sslmethod, "SSLv2_method") == 0)
if (strcmp(*sslmethod, "SSLv2_method") == 0) {
method = SSLv2_method(); method = SSLv2_method();
if (strcmp(*sslmethod, "SSLv2_server_method") == 0) } else if (strcmp(*sslmethod, "SSLv2_server_method") == 0) {
method = SSLv2_server_method(); method = SSLv2_server_method();
if (strcmp(*sslmethod, "SSLv2_client_method") == 0) } else if (strcmp(*sslmethod, "SSLv2_client_method") == 0) {
method = SSLv2_client_method(); method = SSLv2_client_method();
if (strcmp(*sslmethod, "SSLv3_method") == 0) } else if (strcmp(*sslmethod, "SSLv3_method") == 0) {
method = SSLv3_method(); method = SSLv3_method();
if (strcmp(*sslmethod, "SSLv3_server_method") == 0) } else if (strcmp(*sslmethod, "SSLv3_server_method") == 0) {
method = SSLv3_server_method(); method = SSLv3_server_method();
if (strcmp(*sslmethod, "SSLv3_client_method") == 0) } else if (strcmp(*sslmethod, "SSLv3_client_method") == 0) {
method = SSLv3_client_method(); method = SSLv3_client_method();
if (strcmp(*sslmethod, "SSLv23_method") == 0) } else if (strcmp(*sslmethod, "SSLv23_method") == 0) {
method = SSLv23_method(); method = SSLv23_method();
if (strcmp(*sslmethod, "SSLv23_server_method") == 0) } else if (strcmp(*sslmethod, "SSLv23_server_method") == 0) {
method = SSLv23_server_method(); method = SSLv23_server_method();
if (strcmp(*sslmethod, "SSLv23_client_method") == 0) } else if (strcmp(*sslmethod, "SSLv23_client_method") == 0) {
method = SSLv23_client_method(); method = SSLv23_client_method();
if (strcmp(*sslmethod, "TLSv1_method") == 0) } else if (strcmp(*sslmethod, "TLSv1_method") == 0) {
method = TLSv1_method(); method = TLSv1_method();
if (strcmp(*sslmethod, "TLSv1_server_method") == 0) } else if (strcmp(*sslmethod, "TLSv1_server_method") == 0) {
method = TLSv1_server_method(); method = TLSv1_server_method();
if (strcmp(*sslmethod, "TLSv1_client_method") == 0) } else if (strcmp(*sslmethod, "TLSv1_client_method") == 0) {
method = TLSv1_client_method(); method = TLSv1_client_method();
} else {
return ThrowException(Exception::Error(String::New("Unknown method")));
}
} }
sc->ctx_ = SSL_CTX_new(method); sc->ctx_ = SSL_CTX_new(method);

Loading…
Cancel
Save