GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — src: deduplicate `SetALPN` implementations · nodejs/node@17cb272

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • src/crypto
    • crypto_common.cc
    • crypto_common.h
    • crypto_tls.cc
Expand file treeCollapse file tree
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)
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.