Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 17cb272

Browse filesBrowse files
tniessendanielleadams
authored andcommitted
src: deduplicate SetALPN implementations
Instead of accepting either a std::string or a mysterious Local<Value>, accept any std::string_view, which can trivially be constructed from both strings and ArrayBufferViews. This also removes the need to check IsArrayBufferView() inside of SetALPN, which was dead code anyway. PR-URL: #43756 Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
1 parent b4c75a9 commit 17cb272
Copy full SHA for 17cb272

File tree

Expand file treeCollapse file tree

3 files changed

+8
-17
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+8
-17
lines changed
Open diff view settings
Collapse file

‎src/crypto/crypto_common.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_common.cc
+4-13Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ namespace node {
2626

2727
using v8::Array;
2828
using v8::ArrayBuffer;
29-
using v8::ArrayBufferView;
3029
using v8::BackingStore;
3130
using v8::Context;
3231
using v8::EscapableHandleScope;
@@ -87,18 +86,10 @@ void LogSecret(
8786
keylog_cb(ssl.get(), line.c_str());
8887
}
8988

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;
10293
}
10394

10495
MaybeLocal<Value> GetSSLOCSPResponse(
Collapse file

‎src/crypto/crypto_common.h‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_common.h
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,8 @@ void LogSecret(
3333
const unsigned char* secret,
3434
size_t secretlen);
3535

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);
3938

4039
v8::MaybeLocal<v8::Value> GetSSLOCSPResponse(
4140
Environment* env,
Collapse file

‎src/crypto/crypto_tls.cc‎

Copy file name to clipboardExpand all lines: src/crypto/crypto_tls.cc
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,8 @@ void TLSWrap::SetALPNProtocols(const FunctionCallbackInfo<Value>& args) {
15301530
return env->ThrowTypeError("Must give a Buffer as first argument");
15311531

15321532
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()}));
15341535
} else {
15351536
CHECK(
15361537
w->object()->SetPrivate(

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.