GeezerVison is showing github.com — src: deduplicate `SetALPN` implementations · nodejs/node@17cb272
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: src/crypto/crypto_common.cc +4-13Lines changed: 4 additions & 13 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -26,7 +26,6 @@ namespace node { |
26 | 26 |
|
27 | 27 | using v8::Array; |
28 | 28 | using v8::ArrayBuffer; |
29 | | -using v8::ArrayBufferView; |
30 | 29 | using v8::BackingStore; |
31 | 30 | using v8::Context; |
32 | 31 | using v8::EscapableHandleScope; |
@@ -87,18 +86,10 @@ void LogSecret( |
87 | 86 | keylog_cb(ssl.get(), line.c_str()); |
88 | 87 | } |
89 | 88 |
|
90 | | -bool SetALPN(const SSLPointer& ssl, const std::string& alpn) { |
91 | | - return SSL_set_alpn_protos( |
92 | | - ssl.get(), |
93 | | - reinterpret_cast<const uint8_t*>(alpn.c_str()), |
94 | | - alpn.length()) == 0; |
95 | | -} |
96 | | - |
97 | | -bool SetALPN(const SSLPointer& ssl, Local<Value> alpn) { |
98 | | - if (!alpn->IsArrayBufferView()) |
99 | | - return false; |
100 | | - ArrayBufferViewContents<unsigned char> protos(alpn.As<ArrayBufferView>()); |
101 | | - return SSL_set_alpn_protos(ssl.get(), protos.data(), protos.length()) == 0; |
| 89 | +bool SetALPN(const SSLPointer& ssl, std::string_view alpn) { |
| 90 | + return SSL_set_alpn_protos(ssl.get(), |
| 91 | + reinterpret_cast<const uint8_t*>(alpn.data()), |
| 92 | + alpn.length()) == 0; |
102 | 93 | } |
103 | 94 |
|
104 | 95 | MaybeLocal<Value> GetSSLOCSPResponse( |
|
Collapse file
Copy file name to clipboardExpand all lines: src/crypto/crypto_common.h +2-3Lines changed: 2 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -33,9 +33,8 @@ void LogSecret( |
33 | 33 | const unsigned char* secret, |
34 | 34 | size_t secretlen); |
35 | 35 |
|
36 | | -bool SetALPN(const SSLPointer& ssl, const std::string& alpn); |
37 | | - |
38 | | -bool SetALPN(const SSLPointer& ssl, v8::Local<v8::Value> alpn); |
| 36 | +// TODO(tniessen): use std::u8string_view when we switch to C++20. |
| 37 | +bool SetALPN(const SSLPointer& ssl, std::string_view alpn); |
39 | 38 |
|
40 | 39 | v8::MaybeLocal<v8::Value> GetSSLOCSPResponse( |
41 | 40 | Environment* env, |
|
Collapse file
Copy file name to clipboardExpand all lines: src/crypto/crypto_tls.cc +2-1Lines changed: 2 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -1530,7 +1530,8 @@ void TLSWrap::SetALPNProtocols(const FunctionCallbackInfo<Value>& args) { |
1530 | 1530 | return env->ThrowTypeError("Must give a Buffer as first argument"); |
1531 | 1531 |
|
1532 | 1532 | if (w->is_client()) { |
1533 | | - CHECK(SetALPN(w->ssl_, args[0])); |
| 1533 | + ArrayBufferViewContents<char> protos(args[0].As<ArrayBufferView>()); |
| 1534 | + CHECK(SetALPN(w->ssl_, {protos.data(), protos.length()})); |
1534 | 1535 | } else { |
1535 | 1536 | CHECK( |
1536 | 1537 | w->object()->SetPrivate( |
|