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_random.cc Lines: 24 26 92.3 %
Date: 2021-01-16 04:10:54 Branches: 8 16 50.0 %

Line Branch Exec Source
1
#include "crypto/crypto_random.h"
2
#include "crypto/crypto_util.h"
3
#include "allocated_buffer-inl.h"
4
#include "async_wrap-inl.h"
5
#include "env-inl.h"
6
#include "memory_tracker-inl.h"
7
#include "threadpoolwork-inl.h"
8
#include "v8.h"
9
10
namespace node {
11
12
using v8::FunctionCallbackInfo;
13
using v8::Just;
14
using v8::Local;
15
using v8::Maybe;
16
using v8::Nothing;
17
using v8::Object;
18
using v8::Uint32;
19
using v8::Value;
20
21
namespace crypto {
22
524
Maybe<bool> RandomBytesTraits::EncodeOutput(
23
    Environment* env,
24
    const RandomBytesConfig& params,
25
    ByteSource* unused,
26
    v8::Local<v8::Value>* result) {
27
1048
  *result = v8::Undefined(env->isolate());
28
524
  return Just(!result->IsEmpty());
29
}
30
31
524
Maybe<bool> RandomBytesTraits::AdditionalConfig(
32
    CryptoJobMode mode,
33
    const FunctionCallbackInfo<Value>& args,
34
    unsigned int offset,
35
    RandomBytesConfig* params) {
36
524
  Environment* env = Environment::GetCurrent(args);
37
1048
  CHECK(IsAnyByteSource(args[offset]));  // Buffer to fill
38
1572
  CHECK(args[offset + 1]->IsUint32());  // Offset
39
1572
  CHECK(args[offset + 2]->IsUint32());  // Size
40
41
1572
  ArrayBufferOrViewContents<unsigned char> in(args[offset]);
42
43
2096
  const uint32_t byte_offset = args[offset + 1].As<Uint32>()->Value();
44
2096
  const uint32_t size = args[offset + 2].As<Uint32>()->Value();
45
524
  CHECK_GE(byte_offset + size, byte_offset);  // Overflow check.
46
524
  CHECK_LE(byte_offset + size, in.size());  // Bounds check.
47
48
524
  if (UNLIKELY(size > INT_MAX)) {
49
    THROW_ERR_OUT_OF_RANGE(env, "buffer is too large");
50
    return Nothing<bool>();
51
  }
52
53
524
  params->buffer = in.data() + byte_offset;
54
524
  params->size = size;
55
56
524
  return Just(true);
57
}
58
59
524
bool RandomBytesTraits::DeriveBits(
60
    Environment* env,
61
    const RandomBytesConfig& params,
62
    ByteSource* unused) {
63
524
  CheckEntropy();  // Ensure that OpenSSL's PRNG is properly seeded.
64
524
  return RAND_bytes(params.buffer, params.size) != 0;
65
}
66
67
namespace Random {
68
663
void Initialize(Environment* env, Local<Object> target) {
69
663
  RandomBytesJob::Initialize(env, target);
70
663
}
71
}  // namespace Random
72
}  // namespace crypto
73

13995
}  // namespace node