Skip to content

Commit f0558d8

Browse files
tniessensxa
authored andcommitted
src: simplify TLSWrap::SetSession
PR-URL: #42087 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Darshan Sen <[email protected]>
1 parent 97f5ced commit f0558d8

File tree

3 files changed

+3
-25
lines changed

3 files changed

+3
-25
lines changed

src/crypto/crypto_common.cc

-15
Original file line numberDiff line numberDiff line change
@@ -112,27 +112,12 @@ MaybeLocal<Value> GetSSLOCSPResponse(
112112
return ret;
113113
}
114114

115-
bool SetTLSSession(
116-
const SSLPointer& ssl,
117-
const unsigned char* buf,
118-
size_t length) {
119-
SSLSessionPointer s(d2i_SSL_SESSION(nullptr, &buf, length));
120-
return s == nullptr ? false : SetTLSSession(ssl, s);
121-
}
122-
123115
bool SetTLSSession(
124116
const SSLPointer& ssl,
125117
const SSLSessionPointer& session) {
126118
return session != nullptr && SSL_set_session(ssl.get(), session.get()) == 1;
127119
}
128120

129-
SSLSessionPointer GetTLSSession(Local<Value> val) {
130-
if (!val->IsArrayBufferView())
131-
return SSLSessionPointer();
132-
ArrayBufferViewContents<unsigned char> sbuf(val.As<ArrayBufferView>());
133-
return GetTLSSession(sbuf.data(), sbuf.length());
134-
}
135-
136121
SSLSessionPointer GetTLSSession(const unsigned char* buf, size_t length) {
137122
return SSLSessionPointer(d2i_SSL_SESSION(nullptr, &buf, length));
138123
}

src/crypto/crypto_common.h

-7
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,10 @@ v8::MaybeLocal<v8::Value> GetSSLOCSPResponse(
4242
SSL* ssl,
4343
v8::Local<v8::Value> default_value);
4444

45-
bool SetTLSSession(
46-
const SSLPointer& ssl,
47-
const unsigned char* buf,
48-
size_t length);
49-
5045
bool SetTLSSession(
5146
const SSLPointer& ssl,
5247
const SSLSessionPointer& session);
5348

54-
SSLSessionPointer GetTLSSession(v8::Local<v8::Value> val);
55-
5649
SSLSessionPointer GetTLSSession(const unsigned char* buf, size_t length);
5750

5851
long VerifyPeerCertificate( // NOLINT(runtime/int)

src/crypto/crypto_tls.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -1667,10 +1667,10 @@ void TLSWrap::SetSession(const FunctionCallbackInfo<Value>& args) {
16671667
return THROW_ERR_MISSING_ARGS(env, "Session argument is mandatory");
16681668

16691669
THROW_AND_RETURN_IF_NOT_BUFFER(env, args[0], "Session");
1670-
1671-
SSLSessionPointer sess = GetTLSSession(args[0]);
1670+
ArrayBufferViewContents<unsigned char> sbuf(args[0]);
1671+
SSLSessionPointer sess = GetTLSSession(sbuf.data(), sbuf.length());
16721672
if (sess == nullptr)
1673-
return;
1673+
return; // TODO(tniessen): figure out error handling
16741674

16751675
if (!SetTLSSession(w->ssl_, sess))
16761676
return env->ThrowError("SSL_set_session error");

0 commit comments

Comments
 (0)