Skip to content

Commit 51364b7

Browse files
danbevMylesBorins
authored andcommitted
src: move crypto_bio/clienthello to crypto ns
Currently, node_crypto_bio and node_crypto_clienthello are not in the crypto namespace but simply in the node namespace. Not sure if this was intentional or not, but I think it would make sense to move them to be consistent. PR-URL: #13957 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Ben Noordhuis <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent bd8574c commit 51364b7

7 files changed

+25
-13
lines changed

src/node_crypto_bio.cc

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include <string.h>
77

88
namespace node {
9+
namespace crypto {
910

1011
const BIO_METHOD NodeBIO::method = {
1112
BIO_TYPE_MEM,
@@ -467,4 +468,5 @@ NodeBIO::~NodeBIO() {
467468
write_head_ = nullptr;
468469
}
469470

471+
} // namespace crypto
470472
} // namespace node

src/node_crypto_bio.h

+2
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "v8.h"
1212

1313
namespace node {
14+
namespace crypto {
1415

1516
class NodeBIO {
1617
public:
@@ -135,6 +136,7 @@ class NodeBIO {
135136
Buffer* write_head_;
136137
};
137138

139+
} // namespace crypto
138140
} // namespace node
139141

140142
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

src/node_crypto_clienthello-inl.h

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "util-inl.h"
88

99
namespace node {
10+
namespace crypto {
1011

1112
inline void ClientHelloParser::Reset() {
1213
frame_len_ = 0;
@@ -53,6 +54,7 @@ inline bool ClientHelloParser::IsPaused() const {
5354
return state_ == kPaused;
5455
}
5556

57+
} // namespace crypto
5658
} // namespace node
5759

5860
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

src/node_crypto_clienthello.cc

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "node_crypto_clienthello-inl.h"
33

44
namespace node {
5+
namespace crypto {
56

67
void ClientHelloParser::Parse(const uint8_t* data, size_t avail) {
78
switch (state_) {
@@ -223,4 +224,5 @@ bool ClientHelloParser::ParseTLSClientHello(const uint8_t* data, size_t avail) {
223224
return true;
224225
}
225226

227+
} // namespace crypto
226228
} // namespace node

src/node_crypto_clienthello.h

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <stdlib.h> // nullptr
1010

1111
namespace node {
12+
namespace crypto {
1213

1314
class ClientHelloParser {
1415
public:
@@ -112,6 +113,7 @@ class ClientHelloParser {
112113
const uint8_t* tls_ticket_;
113114
};
114115

116+
} // namespace crypto
115117
} // namespace node
116118

117119
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS

src/tls_wrap.cc

+13-11
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ void TLSWrap::NewSessionDoneCb() {
117117

118118
void TLSWrap::InitSSL() {
119119
// Initialize SSL
120-
enc_in_ = NodeBIO::New();
121-
enc_out_ = NodeBIO::New();
122-
NodeBIO::FromBIO(enc_in_)->AssignEnvironment(env());
123-
NodeBIO::FromBIO(enc_out_)->AssignEnvironment(env());
120+
enc_in_ = crypto::NodeBIO::New();
121+
enc_out_ = crypto::NodeBIO::New();
122+
crypto::NodeBIO::FromBIO(enc_in_)->AssignEnvironment(env());
123+
crypto::NodeBIO::FromBIO(enc_out_)->AssignEnvironment(env());
124124

125125
SSL_set_bio(ssl_, enc_in_, enc_out_);
126126

@@ -149,15 +149,15 @@ void TLSWrap::InitSSL() {
149149
SSL_set_accept_state(ssl_);
150150
} else if (is_client()) {
151151
// Enough space for server response (hello, cert)
152-
NodeBIO::FromBIO(enc_in_)->set_initial(kInitialClientBufferLength);
152+
crypto::NodeBIO::FromBIO(enc_in_)->set_initial(kInitialClientBufferLength);
153153
SSL_set_connect_state(ssl_);
154154
} else {
155155
// Unexpected
156156
ABORT();
157157
}
158158

159159
// Initialize ring for queud clear data
160-
clear_in_ = new NodeBIO();
160+
clear_in_ = new crypto::NodeBIO();
161161
clear_in_->AssignEnvironment(env());
162162
}
163163

@@ -289,7 +289,9 @@ void TLSWrap::EncOut() {
289289
char* data[kSimultaneousBufferCount];
290290
size_t size[arraysize(data)];
291291
size_t count = arraysize(data);
292-
write_size_ = NodeBIO::FromBIO(enc_out_)->PeekMultiple(data, size, &count);
292+
write_size_ = crypto::NodeBIO::FromBIO(enc_out_)->PeekMultiple(data,
293+
size,
294+
&count);
293295
CHECK(write_size_ != 0 && count != 0);
294296

295297
Local<Object> req_wrap_obj =
@@ -335,7 +337,7 @@ void TLSWrap::EncOutCb(WriteWrap* req_wrap, int status) {
335337
}
336338

337339
// Commit
338-
NodeBIO::FromBIO(wrap->enc_out_)->Read(nullptr, wrap->write_size_);
340+
crypto::NodeBIO::FromBIO(wrap->enc_out_)->Read(nullptr, wrap->write_size_);
339341

340342
// Ensure that the progress will be made and `InvokeQueued` will be called.
341343
wrap->ClearIn();
@@ -653,7 +655,7 @@ void TLSWrap::OnAllocImpl(size_t suggested_size, uv_buf_t* buf, void* ctx) {
653655
}
654656

655657
size_t size = 0;
656-
buf->base = NodeBIO::FromBIO(wrap->enc_in_)->PeekWritable(&size);
658+
buf->base = crypto::NodeBIO::FromBIO(wrap->enc_in_)->PeekWritable(&size);
657659
buf->len = size;
658660
}
659661

@@ -717,7 +719,7 @@ void TLSWrap::DoRead(ssize_t nread,
717719
}
718720

719721
// Commit read data
720-
NodeBIO* enc_in = NodeBIO::FromBIO(enc_in_);
722+
crypto::NodeBIO* enc_in = crypto::NodeBIO::FromBIO(enc_in_);
721723
enc_in->Commit(nread);
722724

723725
// Parse ClientHello first
@@ -788,7 +790,7 @@ void TLSWrap::EnableSessionCallbacks(
788790
"EnableSessionCallbacks after destroySSL");
789791
}
790792
wrap->enable_session_callbacks();
791-
NodeBIO::FromBIO(wrap->enc_in_)->set_initial(kMaxHelloLength);
793+
crypto::NodeBIO::FromBIO(wrap->enc_in_)->set_initial(kMaxHelloLength);
792794
wrap->hello_parser_.Start(SSLWrap<TLSWrap>::OnClientHello,
793795
OnClientHelloParseEnd,
794796
wrap);

src/tls_wrap.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
namespace node {
1818

1919
// Forward-declarations
20-
class NodeBIO;
2120
class WriteWrap;
2221
namespace crypto {
2322
class SecureContext;
23+
class NodeBIO;
2424
}
2525

2626
class TLSWrap : public AsyncWrap,
@@ -151,7 +151,7 @@ class TLSWrap : public AsyncWrap,
151151
StreamBase* stream_;
152152
BIO* enc_in_;
153153
BIO* enc_out_;
154-
NodeBIO* clear_in_;
154+
crypto::NodeBIO* clear_in_;
155155
size_t write_size_;
156156
typedef ListHead<WriteItem, &WriteItem::member_> WriteItemList;
157157
WriteItemList write_item_queue_;

0 commit comments

Comments
 (0)