|
|
@ -152,6 +152,9 @@ CryptoStream.prototype.end = function(d) { |
|
|
|
this._pending.push(END_OF_FILE); |
|
|
|
this._pendingCallbacks.push(null); |
|
|
|
|
|
|
|
// If this is an encrypted stream then we need to disable further 'data'
|
|
|
|
// events.
|
|
|
|
|
|
|
|
this.writable = false; |
|
|
|
|
|
|
|
this.pair._cycle(); |
|
|
@ -169,6 +172,18 @@ CryptoStream.prototype.destroy = function(err) { |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
CryptoStream.prototype._done = function() { |
|
|
|
this._doneFlag = true; |
|
|
|
|
|
|
|
if (this.pair.cleartext._doneFlag && |
|
|
|
this.pair.encrypted._doneFlag && |
|
|
|
!this.pair._done) { |
|
|
|
// If both streams are done:
|
|
|
|
this.pair._destroy(); |
|
|
|
} |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
CryptoStream.prototype.fd = -1; |
|
|
|
CryptoStream.prototype.__defineGetter__('readyState', |
|
|
|
net.Socket.prototype.__lookupGetter__('readyState')); |
|
|
@ -186,6 +201,11 @@ CryptoStream.prototype.__defineGetter__('readyState', |
|
|
|
// });
|
|
|
|
//
|
|
|
|
CryptoStream.prototype._push = function() { |
|
|
|
if (this == this.pair.encrypted && !this.writable) { |
|
|
|
// If the encrypted side got EOF, we do not attempt
|
|
|
|
// to write out data anymore.
|
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
while (this._writeState == true) { |
|
|
|
var bytesRead = 0; |
|
|
@ -211,7 +231,7 @@ CryptoStream.prototype._push = function() { |
|
|
|
// Bail out if we didn't read any data.
|
|
|
|
if (bytesRead == 0) { |
|
|
|
if (this._pendingBytes() == 0 && this._destroyAfterPush) { |
|
|
|
this.destroy(); |
|
|
|
this._done(); |
|
|
|
} |
|
|
|
return; |
|
|
|
} |
|
|
@ -256,17 +276,23 @@ CryptoStream.prototype._pull = function() { |
|
|
|
|
|
|
|
if (tmp === END_OF_FILE) { |
|
|
|
// Sending EOF
|
|
|
|
debug('end'); |
|
|
|
this.pair._ssl.shutdown(); |
|
|
|
if (this === this.pair.encrypted) { |
|
|
|
debug('end encrypted'); |
|
|
|
this.pair.cleartext._destroyAfterPush = true; |
|
|
|
} else { |
|
|
|
// CleartextStream
|
|
|
|
assert(this === this.pair.cleartext); |
|
|
|
debug('end cleartext'); |
|
|
|
|
|
|
|
// TODO check if we get EAGAIN From shutdown, would have to do it
|
|
|
|
// again. should unshift END_OF_FILE back onto pending and wait for
|
|
|
|
// next cycle.
|
|
|
|
this.pair._ssl.shutdown(); |
|
|
|
|
|
|
|
// TODO check if we get EAGAIN From shutdown, would have to do it
|
|
|
|
// again. should unshift END_OF_FILE back onto pending and wait for
|
|
|
|
// next cycle.
|
|
|
|
} |
|
|
|
this.pair.encrypted._destroyAfterPush = true; |
|
|
|
|
|
|
|
this.pair._cycle(); |
|
|
|
//this.pair._destroy();
|
|
|
|
this._done() |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|