Skip to content

Commit

Permalink
src: return undefined when validation err == 0
Browse files Browse the repository at this point in the history
Extracted from the QUIC PR. Not specific to QUIC even if the
behavior is currently only used there.

Signed-off-by: James M Snell <jasnell@gmail.com>

PR-URL: #33107
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
  • Loading branch information
jasnell committed Apr 29, 2020
1 parent 7acaf4e commit ac8dba3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/node_crypto_common.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ using v8::NewStringType;
using v8::Null;
using v8::Object;
using v8::String;
using v8::Undefined;
using v8::Value;

namespace crypto {
Expand Down Expand Up @@ -330,11 +331,15 @@ const char* X509ErrorCode(long err) { // NOLINT(runtime/int)
}

MaybeLocal<Value> GetValidationErrorReason(Environment* env, int err) {
if (err == 0)
return Undefined(env->isolate());
const char* reason = X509_verify_cert_error_string(err);
return OneByteString(env->isolate(), reason);
}

MaybeLocal<Value> GetValidationErrorCode(Environment* env, int err) {
if (err == 0)
return Undefined(env->isolate());
return OneByteString(env->isolate(), X509ErrorCode(err));
}

Expand Down

0 comments on commit ac8dba3

Please sign in to comment.