summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTim-Smart <tim@fostle.com>2010-10-26 17:05:04 +1300
committerRyan Dahl <ry@tinyclouds.org>2010-10-26 18:47:46 -0700
commit79ecc8e9b7f82b5159e04a42118f6d8b87dee2ee (patch)
treec72bea0dba322f05f1282ef4b5b4b0c63236fab0
parentbc47353bbe1836e4415cb08f1b6619839bff4d82 (diff)
downloadnode-new-79ecc8e9b7f82b5159e04a42118f6d8b87dee2ee.tar.gz
Style changes.
-rw-r--r--lib/securepair.js64
-rw-r--r--src/node_crypto.cc16
2 files changed, 39 insertions, 41 deletions
diff --git a/lib/securepair.js b/lib/securepair.js
index f03b3472f0..64b3e5dcb5 100644
--- a/lib/securepair.js
+++ b/lib/securepair.js
@@ -18,10 +18,9 @@ var SecureStream = null;
* Provides a pair of streams to do encrypted communication.
*/
-function SecurePair(credentials, is_server)
-{
+function SecurePair(credentials, isServer) {
if (!(this instanceof SecurePair)) {
- return new SecurePair(credentials, is_server);
+ return new SecurePair(credentials, isServer);
}
var self = this;
@@ -36,9 +35,9 @@ function SecurePair(credentials, is_server)
events.EventEmitter.call(this);
this._secureEstablished = false;
- this._is_server = is_server ? true : false;
- this._enc_write_state = true;
- this._clear_write_state = true;
+ this._isServer = isServer ? true : false;
+ this._encWriteState = true;
+ this._clearWriteState = true;
this._done = false;
var crypto = require("crypto");
@@ -49,17 +48,17 @@ function SecurePair(credentials, is_server)
this.credentials = credentials;
}
- if (!this._is_server) {
+ if (!this._isServer) {
/* For clients, we will always have either a given ca list or be using default one */
this.credentials.shouldVerify = true;
}
this._secureEstablished = false;
- this._encIn_pending = [];
- this._clearIn_pending = [];
+ this._encInPending = [];
+ this._clearInPending = [];
this._ssl = new SecureStream(this.credentials.context,
- this._is_server ? true : false,
+ this._isServer ? true : false,
this.credentials.shouldVerify);
@@ -72,19 +71,19 @@ function SecurePair(credentials, is_server)
this.cleartext.write = function(data) {
debug('clearIn data');
- self._clearIn_pending.push(data);
+ self._clearInPending.push(data);
self._cycle();
- return self._cleartext_write_state;
+ return self._cleartextWriteState;
};
this.cleartext.pause = function() {
debug('paused cleartext');
- self._cleartext_write_state = false;
+ self._cleartextWriteState = false;
};
this.cleartext.resume = function() {
debug('resumed cleartext');
- self._cleartext_write_state = true;
+ self._cleartextWriteState = true;
};
this.cleartext.end = function(err) {
@@ -98,19 +97,19 @@ function SecurePair(credentials, is_server)
this.encrypted.write = function(data) {
debug('encIn data');
- self._encIn_pending.push(data);
+ self._encInPending.push(data);
self._cycle();
- return self._encrypted_write_state;
+ return self._encryptedWriteState;
};
this.encrypted.pause = function() {
debug('pause encrypted');
- self._encrypted_write_state = false;
+ self._encryptedWriteState = false;
};
this.encrypted.resume = function() {
debug('resume encrypted');
- self._encrypted_write_state = true;
+ self._encryptedWriteState = true;
};
this.encrypted.end = function(err) {
@@ -169,9 +168,8 @@ function SecurePair(credentials, is_server)
util.inherits(SecurePair, events.EventEmitter);
-exports.createSecurePair = function(credentials, is_server)
-{
- var pair = new SecurePair(credentials, is_server);
+exports.createSecurePair = function(credentials, isServer) {
+ var pair = new SecurePair(credentials, isServer);
return pair;
};
@@ -181,7 +179,7 @@ exports.createSecurePair = function(credentials, is_server)
* An SSL Connection can be viewed as four separate piplines,
* interacting with one has no connection to the behavoir of
* any of the other 3 -- This might not sound reasonable,
- * but consider things like mid-stream renegotiation of
+ * but consider things like mid-stream renegotiation of
* the ciphers.
*
* The four pipelines, using terminology of the client (server is just reversed):
@@ -199,7 +197,7 @@ exports.createSecurePair = function(credentials, is_server)
* trying to flush, trying to change ciphers, or shutting down the connection.
*
* Because it is also called everywhere, we also check if the connection
- * has completed negotiation and emit 'secure' from here if it has.
+ * has completed negotiation and emit 'secure' from here if it has.
*/
SecurePair.prototype._cycle = function() {
if (this._done) {
@@ -215,8 +213,8 @@ SecurePair.prototype._cycle = function() {
var chunk = null;
var pool = null;
- while (this._encIn_pending.length > 0) {
- tmp = this._encIn_pending.shift();
+ while (this._encInPending.length > 0) {
+ tmp = this._encInPending.shift();
try {
debug('writng from encIn');
@@ -226,15 +224,15 @@ SecurePair.prototype._cycle = function() {
}
if (rv === 0) {
- this._encIn_pending.unshift(tmp);
+ this._encInPending.unshift(tmp);
break;
}
assert(rv === tmp.length);
}
- while (this._clearIn_pending.length > 0) {
- tmp = this._clearIn_pending.shift();
+ while (this._clearInPending.length > 0) {
+ tmp = this._clearInPending.shift();
try {
debug('writng from clearIn');
rv = this._ssl.clearIn(tmp, 0, tmp.length);
@@ -243,7 +241,7 @@ SecurePair.prototype._cycle = function() {
}
if (rv === 0) {
- this._clearIn_pending.unshift(tmp);
+ this._clearInPending.unshift(tmp);
break;
}
@@ -277,7 +275,7 @@ SecurePair.prototype._cycle = function() {
chunk = pool.slice(0, bytesRead);
writer(chunk);
}
- } while (checker(bytesRead));
+ } while (checker(bytesRead));
}
mover(
@@ -286,10 +284,10 @@ SecurePair.prototype._cycle = function() {
return self._ssl.clearOut(pool, offset, length);
},
function(chunk) {
- self.cleartext.emit('data', chunk);
+ self.cleartext.emit('data', chunk);
},
function(bytesRead) {
- return bytesRead > 0 && self._cleartext_write_state === true;
+ return bytesRead > 0 && self._cleartextWriteState === true;
});
mover(
@@ -301,7 +299,7 @@ SecurePair.prototype._cycle = function() {
self.encrypted.emit('data', chunk);
},
function(bytesRead) {
- return bytesRead > 0 && self._encrypted_write_state === true;
+ return bytesRead > 0 && self._encryptedWriteState === true;
});
if (!this._secureEstablished && this._ssl.isInitFinished()) {
diff --git a/src/node_crypto.cc b/src/node_crypto.cc
index fd0605b0fc..d8cb2183b8 100644
--- a/src/node_crypto.cc
+++ b/src/node_crypto.cc
@@ -244,8 +244,7 @@ Handle<Value> SecureContext::Close(const Arguments& args) {
char ssl_error_buf[512];
-static int serr(SSL *ssl, const char* func, int rv)
-{
+static int serr(SSL *ssl, const char* func, int rv) {
if (rv >= 0) {
return rv;
}
@@ -256,11 +255,9 @@ static int serr(SSL *ssl, const char* func, int rv)
ERR_error_string_n(ERR_get_error(), &ssl_error_buf[0], sizeof(ssl_error_buf));
/* fprintf(stderr, "[%p] SSL: %s failed: (%d:%d) %s\n", ssl, func, err, rv, buf); */
return rv;
- }
- else if (err == SSL_ERROR_WANT_WRITE) {
+ } else if (err == SSL_ERROR_WANT_WRITE) {
/* fprintf(stderr, "[%p] SSL: %s want write\n", ssl, func); */
- }
- else if (err == SSL_ERROR_WANT_READ) {
+ } else if (err == SSL_ERROR_WANT_READ) {
/* fprintf(stderr, "[%p] SSL: %s want read\n", ssl, func); */
}
@@ -516,9 +513,11 @@ Handle<Value> SecureStream::ClearIn(const Arguments& args) {
} else {
s = serr(ss->ssl_, "SSL_connect:ClearIn", SSL_connect(ss->ssl_));
}
+
if (s < 0) {
return ThrowException(Exception::Error(v8::String::New(ssl_error_buf)));
}
+
return scope.Close(Integer::New(0));
}
@@ -602,13 +601,14 @@ Handle<Value> SecureStream::Start(const Arguments& args) {
} else {
rv = serr(ss->ssl_, "SSL_connect:Start", SSL_connect(ss->ssl_));
}
+
if (rv < 0) {
return ThrowException(Exception::Error(v8::String::New(ssl_error_buf)));
}
+
if (rv == 1) {
return True();
- }
- else {
+ } else {
return False();
}
}