GCC Code Coverage Report
Directory: ../ Exec Total Coverage
File: /home/iojs/build/workspace/node-test-commit-linux-coverage-daily/nodes/benchmark/out/../src/crypto/crypto_timing.cc Lines: 19 19 100.0 %
Date: 2021-04-29 04:13:25 Branches: 8 10 80.0 %

Line Branch Exec Source
1
#include "crypto/crypto_timing.h"
2
#include "crypto/crypto_util.h"
3
#include "env-inl.h"
4
#include "node_errors.h"
5
#include "v8.h"
6
#include "node.h"
7
8
#include <openssl/crypto.h>
9
10
namespace node {
11
12
using v8::FunctionCallbackInfo;
13
using v8::Local;
14
using v8::Object;
15
using v8::Value;
16
17
namespace crypto {
18
namespace Timing {
19
27
void TimingSafeEqual(const FunctionCallbackInfo<Value>& args) {
20
  // Moving the type checking into JS leads to test failures, most likely due
21
  // to V8 inlining certain parts of the wrapper. Therefore, keep them in C++.
22
  // Refs: https://github.com/nodejs/node/issues/34073.
23
27
  Environment* env = Environment::GetCurrent(args);
24
27
  if (!IsAnyByteSource(args[0])) {
25
    THROW_ERR_INVALID_ARG_TYPE(
26
      env, "The \"buf1\" argument must be an instance of "
27
1
      "ArrayBuffer, Buffer, TypedArray, or DataView.");
28
1
    return;
29
  }
30
26
  if (!IsAnyByteSource(args[1])) {
31
    THROW_ERR_INVALID_ARG_TYPE(
32
      env, "The \"buf2\" argument must be an instance of "
33
1
      "ArrayBuffer, Buffer, TypedArray, or DataView.");
34
1
    return;
35
  }
36
37
50
  ArrayBufferOrViewContents<char> buf1(args[0]);
38
50
  ArrayBufferOrViewContents<char> buf2(args[1]);
39
40
25
  if (buf1.size() != buf2.size()) {
41
1
    THROW_ERR_CRYPTO_TIMING_SAFE_EQUAL_LENGTH(env);
42
1
    return;
43
  }
44
45
72
  return args.GetReturnValue().Set(
46
48
      CRYPTO_memcmp(buf1.data(), buf2.data(), buf1.size()) == 0);
47
}
48
49
4153
void Initialize(Environment* env, Local<Object> target) {
50
4153
  env->SetMethodNoSideEffect(target, "timingSafeEqual", TimingSafeEqual);
51
4153
}
52
}  // namespace Timing
53
54
}  // namespace crypto
55

14484
}  // namespace node