Skip to content

Commit 9dc21a1

Browse files
bnoordhuisRafaelGSS
authored andcommitted
src: simplify ALPN code, remove indirection
PR-URL: #44875 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Tobias Nießen <[email protected]>
1 parent ec86830 commit 9dc21a1

File tree

3 files changed

+4
-12
lines changed

3 files changed

+4
-12
lines changed

src/crypto/crypto_common.cc

-6
Original file line numberDiff line numberDiff line change
@@ -89,12 +89,6 @@ void LogSecret(
8989
keylog_cb(ssl.get(), line.c_str());
9090
}
9191

92-
bool SetALPN(const SSLPointer& ssl, std::string_view alpn) {
93-
return SSL_set_alpn_protos(ssl.get(),
94-
reinterpret_cast<const uint8_t*>(alpn.data()),
95-
alpn.length()) == 0;
96-
}
97-
9892
MaybeLocal<Value> GetSSLOCSPResponse(
9993
Environment* env,
10094
SSL* ssl,

src/crypto/crypto_common.h

-3
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,6 @@ void LogSecret(
3333
const unsigned char* secret,
3434
size_t secretlen);
3535

36-
// TODO(tniessen): use std::u8string_view when we switch to C++20.
37-
bool SetALPN(const SSLPointer& ssl, std::string_view alpn);
38-
3936
v8::MaybeLocal<v8::Value> GetSSLOCSPResponse(
4037
Environment* env,
4138
SSL* ssl,

src/crypto/crypto_tls.cc

+4-3
Original file line numberDiff line numberDiff line change
@@ -1529,17 +1529,18 @@ void TLSWrap::SetALPNProtocols(const FunctionCallbackInfo<Value>& args) {
15291529
if (args.Length() < 1 || !Buffer::HasInstance(args[0]))
15301530
return env->ThrowTypeError("Must give a Buffer as first argument");
15311531

1532+
SSL* ssl = w->ssl_.get();
15321533
if (w->is_client()) {
1533-
ArrayBufferViewContents<char> protos(args[0].As<ArrayBufferView>());
1534-
CHECK(SetALPN(w->ssl_, {protos.data(), protos.length()}));
1534+
ArrayBufferViewContents<uint8_t> protos(args[0].As<ArrayBufferView>());
1535+
CHECK_EQ(0, SSL_set_alpn_protos(ssl, protos.data(), protos.length()));
15351536
} else {
15361537
CHECK(
15371538
w->object()->SetPrivate(
15381539
env->context(),
15391540
env->alpn_buffer_private_symbol(),
15401541
args[0]).FromJust());
15411542
// Server should select ALPN protocol from list of advertised by client
1542-
SSL_CTX_set_alpn_select_cb(SSL_get_SSL_CTX(w->ssl_.get()),
1543+
SSL_CTX_set_alpn_select_cb(SSL_get_SSL_CTX(ssl),
15431544
SelectALPNCallback,
15441545
nullptr);
15451546
}

0 commit comments

Comments
 (0)