Skip to content

Commit e3d1808

Browse files
committed
Rename node::SecureStream to node::crypto::Connection
node::SecureStream is definitely not a "stream" in the Node sense. Renaming it to avoid ambiguity. (Adding namespace to not confuse with some other Connection object.)
1 parent 6636bfa commit e3d1808

4 files changed

Lines changed: 74 additions & 71 deletions

File tree

lib/crypto.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
try {
33
var binding = process.binding('crypto');
44
var SecureContext = binding.SecureContext;
5-
var SecureStream = binding.SecureStream;
65
var Hmac = binding.Hmac;
76
var Hash = binding.Hash;
87
var Cipher = binding.Cipher;

lib/tls.js

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,14 @@ if (debugLevel & 0x2) {
1515
}
1616

1717

18-
/* Lazy Loaded crypto object */
19-
var SecureStream = null; // note SecureStream is not a "real" stream.
18+
var Connection = null;
19+
try {
20+
Connection = process.binding('crypto').Connection;
21+
}
22+
catch (e) {
23+
throw new Error('node.js not compiled with openssl crypto support.');
24+
}
25+
2026

2127
// Base class of both CleartextStream and EncryptedStream
2228
function CryptoStream (pair) {
@@ -231,13 +237,6 @@ function SecurePair(credentials, isServer, requestCert, rejectUnauthorized) {
231237

232238
var self = this;
233239

234-
try {
235-
SecureStream = process.binding('crypto').SecureStream;
236-
}
237-
catch (e) {
238-
throw new Error('node.js not compiled with openssl crypto support.');
239-
}
240-
241240
events.EventEmitter.call(this);
242241

243242
this._secureEstablished = false;
@@ -264,10 +263,10 @@ function SecurePair(credentials, isServer, requestCert, rejectUnauthorized) {
264263
this._rejectUnauthorized = rejectUnauthorized ? true : false;
265264
this._requestCert = requestCert ? true : false;
266265

267-
this._ssl = new SecureStream(this.credentials.context,
268-
this._isServer ? true : false,
269-
this._requestCert,
270-
this._rejectUnauthorized);
266+
this._ssl = new Connection(this.credentials.context,
267+
this._isServer ? true : false,
268+
this._requestCert,
269+
this._rejectUnauthorized);
271270

272271

273272
/* Acts as a r/w stream to the cleartext side of the stream. */

src/node_crypto.cc

Lines changed: 55 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#endif
1818

1919
namespace node {
20+
namespace crypto {
2021

2122
using namespace v8;
2223

@@ -307,29 +308,29 @@ static int serr(SSL *ssl, const char* func, int rv) {
307308
return 0;
308309
}
309310

310-
void SecureStream::Initialize(Handle<Object> target) {
311+
void Connection::Initialize(Handle<Object> target) {
311312
HandleScope scope;
312313

313-
Local<FunctionTemplate> t = FunctionTemplate::New(SecureStream::New);
314+
Local<FunctionTemplate> t = FunctionTemplate::New(Connection::New);
314315
t->InstanceTemplate()->SetInternalFieldCount(1);
315-
t->SetClassName(String::NewSymbol("SecureStream"));
316-
317-
NODE_SET_PROTOTYPE_METHOD(t, "encIn", SecureStream::EncIn);
318-
NODE_SET_PROTOTYPE_METHOD(t, "clearOut", SecureStream::ClearOut);
319-
NODE_SET_PROTOTYPE_METHOD(t, "clearIn", SecureStream::ClearIn);
320-
NODE_SET_PROTOTYPE_METHOD(t, "encOut", SecureStream::EncOut);
321-
NODE_SET_PROTOTYPE_METHOD(t, "clearPending", SecureStream::ClearPending);
322-
NODE_SET_PROTOTYPE_METHOD(t, "encPending", SecureStream::EncPending);
323-
NODE_SET_PROTOTYPE_METHOD(t, "getPeerCertificate", SecureStream::GetPeerCertificate);
324-
NODE_SET_PROTOTYPE_METHOD(t, "isInitFinished", SecureStream::IsInitFinished);
325-
NODE_SET_PROTOTYPE_METHOD(t, "verifyError", SecureStream::VerifyError);
326-
NODE_SET_PROTOTYPE_METHOD(t, "getCurrentCipher", SecureStream::GetCurrentCipher);
327-
NODE_SET_PROTOTYPE_METHOD(t, "start", SecureStream::Start);
328-
NODE_SET_PROTOTYPE_METHOD(t, "shutdown", SecureStream::Shutdown);
329-
NODE_SET_PROTOTYPE_METHOD(t, "receivedShutdown", SecureStream::ReceivedShutdown);
330-
NODE_SET_PROTOTYPE_METHOD(t, "close", SecureStream::Close);
331-
332-
target->Set(String::NewSymbol("SecureStream"), t->GetFunction());
316+
t->SetClassName(String::NewSymbol("Connection"));
317+
318+
NODE_SET_PROTOTYPE_METHOD(t, "encIn", Connection::EncIn);
319+
NODE_SET_PROTOTYPE_METHOD(t, "clearOut", Connection::ClearOut);
320+
NODE_SET_PROTOTYPE_METHOD(t, "clearIn", Connection::ClearIn);
321+
NODE_SET_PROTOTYPE_METHOD(t, "encOut", Connection::EncOut);
322+
NODE_SET_PROTOTYPE_METHOD(t, "clearPending", Connection::ClearPending);
323+
NODE_SET_PROTOTYPE_METHOD(t, "encPending", Connection::EncPending);
324+
NODE_SET_PROTOTYPE_METHOD(t, "getPeerCertificate", Connection::GetPeerCertificate);
325+
NODE_SET_PROTOTYPE_METHOD(t, "isInitFinished", Connection::IsInitFinished);
326+
NODE_SET_PROTOTYPE_METHOD(t, "verifyError", Connection::VerifyError);
327+
NODE_SET_PROTOTYPE_METHOD(t, "getCurrentCipher", Connection::GetCurrentCipher);
328+
NODE_SET_PROTOTYPE_METHOD(t, "start", Connection::Start);
329+
NODE_SET_PROTOTYPE_METHOD(t, "shutdown", Connection::Shutdown);
330+
NODE_SET_PROTOTYPE_METHOD(t, "receivedShutdown", Connection::ReceivedShutdown);
331+
NODE_SET_PROTOTYPE_METHOD(t, "close", Connection::Close);
332+
333+
target->Set(String::NewSymbol("Connection"), t->GetFunction());
333334
}
334335

335336

@@ -373,16 +374,16 @@ static int VerifyCallback(int preverify_ok, X509_STORE_CTX *ctx) {
373374
//
374375
// Since we cannot perform I/O quickly enough in this callback, we ignore
375376
// all preverify_ok errors and let the handshake continue. It is
376-
// imparative that the user use SecureStream::VerifyError after the
377+
// imparative that the user use Connection::VerifyError after the
377378
// 'secure' callback has been made.
378379
return 1;
379380
}
380381

381382

382-
Handle<Value> SecureStream::New(const Arguments& args) {
383+
Handle<Value> Connection::New(const Arguments& args) {
383384
HandleScope scope;
384385

385-
SecureStream *p = new SecureStream();
386+
Connection *p = new Connection();
386387
p->Wrap(args.Holder());
387388

388389
if (args.Length() < 1 || !args[0]->IsObject()) {
@@ -435,10 +436,10 @@ Handle<Value> SecureStream::New(const Arguments& args) {
435436
}
436437

437438

438-
Handle<Value> SecureStream::EncIn(const Arguments& args) {
439+
Handle<Value> Connection::EncIn(const Arguments& args) {
439440
HandleScope scope;
440441

441-
SecureStream *ss = ObjectWrap::Unwrap<SecureStream>(args.Holder());
442+
Connection *ss = ObjectWrap::Unwrap<Connection>(args.Holder());
442443

443444
if (args.Length() < 3) {
444445
return ThrowException(Exception::TypeError(
@@ -477,10 +478,10 @@ Handle<Value> SecureStream::EncIn(const Arguments& args) {
477478
}
478479

479480

480-
Handle<Value> SecureStream::ClearOut(const Arguments& args) {
481+
Handle<Value> Connection::ClearOut(const Arguments& args) {
481482
HandleScope scope;
482483

483-
SecureStream *ss = ObjectWrap::Unwrap<SecureStream>(args.Holder());
484+
Connection *ss = ObjectWrap::Unwrap<Connection>(args.Holder());
484485

485486
if (args.Length() < 3) {
486487
return ThrowException(Exception::TypeError(
@@ -531,28 +532,28 @@ Handle<Value> SecureStream::ClearOut(const Arguments& args) {
531532
}
532533

533534

534-
Handle<Value> SecureStream::ClearPending(const Arguments& args) {
535+
Handle<Value> Connection::ClearPending(const Arguments& args) {
535536
HandleScope scope;
536537

537-
SecureStream *ss = ObjectWrap::Unwrap<SecureStream>(args.Holder());
538+
Connection *ss = ObjectWrap::Unwrap<Connection>(args.Holder());
538539
int bytes_pending = BIO_pending(ss->bio_read_);
539540
return scope.Close(Integer::New(bytes_pending));
540541
}
541542

542543

543-
Handle<Value> SecureStream::EncPending(const Arguments& args) {
544+
Handle<Value> Connection::EncPending(const Arguments& args) {
544545
HandleScope scope;
545546

546-
SecureStream *ss = ObjectWrap::Unwrap<SecureStream>(args.Holder());
547+
Connection *ss = ObjectWrap::Unwrap<Connection>(args.Holder());
547548
int bytes_pending = BIO_pending(ss->bio_write_);
548549
return scope.Close(Integer::New(bytes_pending));
549550
}
550551

551552

552-
Handle<Value> SecureStream::EncOut(const Arguments& args) {
553+
Handle<Value> Connection::EncOut(const Arguments& args) {
553554
HandleScope scope;
554555

555-
SecureStream *ss = ObjectWrap::Unwrap<SecureStream>(args.Holder());
556+
Connection *ss = ObjectWrap::Unwrap<Connection>(args.Holder());
556557

557558
if (args.Length() < 3) {
558559
return ThrowException(Exception::TypeError(
@@ -586,10 +587,10 @@ Handle<Value> SecureStream::EncOut(const Arguments& args) {
586587
}
587588

588589

589-
Handle<Value> SecureStream::ClearIn(const Arguments& args) {
590+
Handle<Value> Connection::ClearIn(const Arguments& args) {
590591
HandleScope scope;
591592

592-
SecureStream *ss = ObjectWrap::Unwrap<SecureStream>(args.Holder());
593+
Connection *ss = ObjectWrap::Unwrap<Connection>(args.Holder());
593594

594595
if (args.Length() < 3) {
595596
return ThrowException(Exception::TypeError(
@@ -642,10 +643,10 @@ Handle<Value> SecureStream::ClearIn(const Arguments& args) {
642643
}
643644

644645

645-
Handle<Value> SecureStream::GetPeerCertificate(const Arguments& args) {
646+
Handle<Value> Connection::GetPeerCertificate(const Arguments& args) {
646647
HandleScope scope;
647648

648-
SecureStream *ss = ObjectWrap::Unwrap<SecureStream>(args.Holder());
649+
Connection *ss = ObjectWrap::Unwrap<Connection>(args.Holder());
649650

650651
if (ss->ssl_ == NULL) return Undefined();
651652
Local<Object> info = Object::New();
@@ -700,11 +701,11 @@ Handle<Value> SecureStream::GetPeerCertificate(const Arguments& args) {
700701
return scope.Close(info);
701702
}
702703

703-
Handle<Value> SecureStream::Start(const Arguments& args) {
704+
Handle<Value> Connection::Start(const Arguments& args) {
704705
HandleScope scope;
705706
int rv;
706707

707-
SecureStream *ss = ObjectWrap::Unwrap<SecureStream>(args.Holder());
708+
Connection *ss = ObjectWrap::Unwrap<Connection>(args.Holder());
708709

709710
if (!SSL_is_init_finished(ss->ssl_)) {
710711
if (ss->is_server_) {
@@ -728,10 +729,10 @@ Handle<Value> SecureStream::Start(const Arguments& args) {
728729
}
729730

730731

731-
Handle<Value> SecureStream::Shutdown(const Arguments& args) {
732+
Handle<Value> Connection::Shutdown(const Arguments& args) {
732733
HandleScope scope;
733734

734-
SecureStream *ss = ObjectWrap::Unwrap<SecureStream>(args.Holder());
735+
Connection *ss = ObjectWrap::Unwrap<Connection>(args.Holder());
735736

736737
if (ss->ssl_ == NULL) return False();
737738
int r = SSL_shutdown(ss->ssl_);
@@ -740,10 +741,10 @@ Handle<Value> SecureStream::Shutdown(const Arguments& args) {
740741
}
741742

742743

743-
Handle<Value> SecureStream::ReceivedShutdown(const Arguments& args) {
744+
Handle<Value> Connection::ReceivedShutdown(const Arguments& args) {
744745
HandleScope scope;
745746

746-
SecureStream *ss = ObjectWrap::Unwrap<SecureStream>(args.Holder());
747+
Connection *ss = ObjectWrap::Unwrap<Connection>(args.Holder());
747748

748749
if (ss->ssl_ == NULL) return False();
749750
int r = SSL_get_shutdown(ss->ssl_);
@@ -754,18 +755,18 @@ Handle<Value> SecureStream::ReceivedShutdown(const Arguments& args) {
754755
}
755756

756757

757-
Handle<Value> SecureStream::IsInitFinished(const Arguments& args) {
758+
Handle<Value> Connection::IsInitFinished(const Arguments& args) {
758759
HandleScope scope;
759-
SecureStream *ss = ObjectWrap::Unwrap<SecureStream>(args.Holder());
760+
Connection *ss = ObjectWrap::Unwrap<Connection>(args.Holder());
760761
if (ss->ssl_ == NULL) return False();
761762
return SSL_is_init_finished(ss->ssl_) ? True() : False();
762763
}
763764

764765

765-
Handle<Value> SecureStream::VerifyError(const Arguments& args) {
766+
Handle<Value> Connection::VerifyError(const Arguments& args) {
766767
HandleScope scope;
767768

768-
SecureStream *ss = ObjectWrap::Unwrap<SecureStream>(args.Holder());
769+
Connection *ss = ObjectWrap::Unwrap<Connection>(args.Holder());
769770

770771
if (ss->ssl_ == NULL) return Null();
771772

@@ -906,10 +907,10 @@ Handle<Value> SecureStream::VerifyError(const Arguments& args) {
906907
}
907908

908909

909-
Handle<Value> SecureStream::GetCurrentCipher(const Arguments& args) {
910+
Handle<Value> Connection::GetCurrentCipher(const Arguments& args) {
910911
HandleScope scope;
911912

912-
SecureStream *ss = ObjectWrap::Unwrap<SecureStream>(args.Holder());
913+
Connection *ss = ObjectWrap::Unwrap<Connection>(args.Holder());
913914
OPENSSL_CONST SSL_CIPHER *c;
914915

915916
if ( ss->ssl_ == NULL ) return Undefined();
@@ -923,10 +924,10 @@ Handle<Value> SecureStream::GetCurrentCipher(const Arguments& args) {
923924
return scope.Close(info);
924925
}
925926

926-
Handle<Value> SecureStream::Close(const Arguments& args) {
927+
Handle<Value> Connection::Close(const Arguments& args) {
927928
HandleScope scope;
928929

929-
SecureStream *ss = ObjectWrap::Unwrap<SecureStream>(args.Holder());
930+
Connection *ss = ObjectWrap::Unwrap<Connection>(args.Holder());
930931

931932
if (ss->ssl_ != NULL) {
932933
SSL_free(ss->ssl_);
@@ -2667,7 +2668,7 @@ void InitCrypto(Handle<Object> target) {
26672668
ERR_load_crypto_strings();
26682669

26692670
SecureContext::Initialize(target);
2670-
SecureStream::Initialize(target);
2671+
Connection::Initialize(target);
26712672
Cipher::Initialize(target);
26722673
Decipher::Initialize(target);
26732674
Hmac::Initialize(target);
@@ -2684,7 +2685,8 @@ void InitCrypto(Handle<Object> target) {
26842685
version_symbol = NODE_PSYMBOL("version");
26852686
}
26862687

2688+
} // namespace crypto
26872689
} // namespace node
26882690

2689-
NODE_MODULE(node_crypto, node::InitCrypto);
2691+
NODE_MODULE(node_crypto, node::crypto::InitCrypto);
26902692

src/node_crypto.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717

1818
namespace node {
19+
namespace crypto {
1920

2021
class SecureContext : ObjectWrap {
2122
public:
@@ -52,7 +53,7 @@ class SecureContext : ObjectWrap {
5253
private:
5354
};
5455

55-
class SecureStream : ObjectWrap {
56+
class Connection : ObjectWrap {
5657
public:
5758
static void Initialize(v8::Handle<v8::Object> target);
5859

@@ -73,12 +74,12 @@ class SecureStream : ObjectWrap {
7374
static v8::Handle<v8::Value> Start(const v8::Arguments& args);
7475
static v8::Handle<v8::Value> Close(const v8::Arguments& args);
7576

76-
SecureStream() : ObjectWrap() {
77+
Connection() : ObjectWrap() {
7778
bio_read_ = bio_write_ = NULL;
7879
ssl_ = NULL;
7980
}
8081

81-
~SecureStream() {
82+
~Connection() {
8283
if (ssl_ != NULL) {
8384
SSL_free(ssl_);
8485
ssl_ = NULL;
@@ -93,6 +94,8 @@ class SecureStream : ObjectWrap {
9394
};
9495

9596
void InitCrypto(v8::Handle<v8::Object> target);
96-
}
97+
98+
} // namespace crypto
99+
} // namespace node
97100

98101
#endif // SRC_NODE_CRYPTO_H_

0 commit comments

Comments
 (0)