diff --git a/src/crypto/crypto_common.cc b/src/crypto/crypto_common.cc index 3341859e04c890..eab144cfdf663b 100644 --- a/src/crypto/crypto_common.cc +++ b/src/crypto/crypto_common.cc @@ -26,7 +26,6 @@ namespace node { using v8::Array; using v8::ArrayBuffer; -using v8::ArrayBufferView; using v8::BackingStore; using v8::Context; using v8::EscapableHandleScope; @@ -87,18 +86,10 @@ void LogSecret( keylog_cb(ssl.get(), line.c_str()); } -bool SetALPN(const SSLPointer& ssl, const std::string& alpn) { - return SSL_set_alpn_protos( - ssl.get(), - reinterpret_cast(alpn.c_str()), - alpn.length()) == 0; -} - -bool SetALPN(const SSLPointer& ssl, Local alpn) { - if (!alpn->IsArrayBufferView()) - return false; - ArrayBufferViewContents protos(alpn.As()); - return SSL_set_alpn_protos(ssl.get(), protos.data(), protos.length()) == 0; +bool SetALPN(const SSLPointer& ssl, std::string_view alpn) { + return SSL_set_alpn_protos(ssl.get(), + reinterpret_cast(alpn.data()), + alpn.length()) == 0; } MaybeLocal GetSSLOCSPResponse( diff --git a/src/crypto/crypto_common.h b/src/crypto/crypto_common.h index 792760e9707328..55401252cffc1f 100644 --- a/src/crypto/crypto_common.h +++ b/src/crypto/crypto_common.h @@ -33,9 +33,8 @@ void LogSecret( const unsigned char* secret, size_t secretlen); -bool SetALPN(const SSLPointer& ssl, const std::string& alpn); - -bool SetALPN(const SSLPointer& ssl, v8::Local alpn); +// TODO(tniessen): use std::u8string_view when we switch to C++20. +bool SetALPN(const SSLPointer& ssl, std::string_view alpn); v8::MaybeLocal GetSSLOCSPResponse( Environment* env, diff --git a/src/crypto/crypto_tls.cc b/src/crypto/crypto_tls.cc index a192956f0f7cfe..6e6ef5251fca0e 100644 --- a/src/crypto/crypto_tls.cc +++ b/src/crypto/crypto_tls.cc @@ -1530,7 +1530,8 @@ void TLSWrap::SetALPNProtocols(const FunctionCallbackInfo& args) { return env->ThrowTypeError("Must give a Buffer as first argument"); if (w->is_client()) { - CHECK(SetALPN(w->ssl_, args[0])); + ArrayBufferViewContents protos(args[0].As()); + CHECK(SetALPN(w->ssl_, {protos.data(), protos.length()})); } else { CHECK( w->object()->SetPrivate(