Skip to content

Commit e208c95

Browse files
committed
src: reuse crypto GetCipherInfo in DTLS session
Signed-off-by: ishabi <ilyasshabi94@gmail.com>
1 parent de40414 commit e208c95

1 file changed

Lines changed: 3 additions & 25 deletions

File tree

src/dtls/dtls_session.cc

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <async_wrap-inl.h>
99
#include <base_object-inl.h>
1010
#include <crypto/crypto_x509.h>
11+
#include <crypto/crypto_common.h>
1112
#include <env-inl.h>
1213
#include <memory_tracker-inl.h>
1314
#include <node_buffer.h>
@@ -1037,31 +1038,8 @@ void DTLSSession::GetCipher(const FunctionCallbackInfo<Value>& args) {
10371038
ASSIGN_OR_RETURN_UNWRAP(&session, args.This());
10381039
Environment* env = session->env();
10391040

1040-
const SSL_CIPHER* cipher = SSL_get_current_cipher(session->ssl_.get());
1041-
if (cipher == nullptr) return;
1042-
1043-
// Build the three strings up front so a failure leaves the return value
1044-
// untouched rather than a half-populated object.
1045-
Local<Value> name;
1046-
Local<Value> standard_name;
1047-
Local<Value> version;
1048-
if (!ToV8Value(env->context(), SSL_CIPHER_get_name(cipher)).ToLocal(&name) ||
1049-
!ToV8Value(env->context(), SSL_CIPHER_standard_name(cipher))
1050-
.ToLocal(&standard_name) ||
1051-
!ToV8Value(env->context(), SSL_CIPHER_get_version(cipher))
1052-
.ToLocal(&version)) {
1053-
return;
1054-
}
1055-
1056-
Local<Object> info = Object::New(env->isolate());
1057-
info->Set(env->context(), env->name_string(), name).Check();
1058-
info->Set(env->context(),
1059-
FIXED_ONE_BYTE_STRING(env->isolate(), "standardName"),
1060-
standard_name)
1061-
.Check();
1062-
info->Set(env->context(), env->version_string(), version).Check();
1063-
1064-
args.GetReturnValue().Set(info);
1041+
args.GetReturnValue().Set(
1042+
crypto::GetCipherInfo(env, session->ssl_).FromMaybe(Local<Object>()));
10651043
}
10661044

10671045
void DTLSSession::GetPeerCertificate(const FunctionCallbackInfo<Value>& args) {

0 commit comments

Comments
 (0)