1 |
|
|
#ifndef SRC_CRYPTO_CRYPTO_RANDOM_H_ |
2 |
|
|
#define SRC_CRYPTO_CRYPTO_RANDOM_H_ |
3 |
|
|
|
4 |
|
|
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
5 |
|
|
|
6 |
|
|
#include "crypto/crypto_util.h" |
7 |
|
|
#include "base_object.h" |
8 |
|
|
#include "allocated_buffer.h" |
9 |
|
|
#include "env.h" |
10 |
|
|
#include "memory_tracker.h" |
11 |
|
|
#include "node_internals.h" |
12 |
|
|
#include "v8.h" |
13 |
|
|
|
14 |
|
|
namespace node { |
15 |
|
|
namespace crypto { |
16 |
|
2072 |
struct RandomBytesConfig final : public MemoryRetainer { |
17 |
|
|
unsigned char* buffer; |
18 |
|
|
size_t size; |
19 |
|
1 |
SET_NO_MEMORY_INFO(); |
20 |
|
1 |
SET_MEMORY_INFO_NAME(RandomBytesConfig); |
21 |
|
1 |
SET_SELF_SIZE(RandomBytesConfig); |
22 |
|
|
}; |
23 |
|
|
|
24 |
|
|
struct RandomBytesTraits final { |
25 |
|
|
using AdditionalParameters = RandomBytesConfig; |
26 |
|
|
static constexpr const char* JobName = "RandomBytesJob"; |
27 |
|
|
static constexpr AsyncWrap::ProviderType Provider = |
28 |
|
|
AsyncWrap::PROVIDER_RANDOMBYTESREQUEST; |
29 |
|
|
|
30 |
|
|
static v8::Maybe<bool> AdditionalConfig( |
31 |
|
|
CryptoJobMode mode, |
32 |
|
|
const v8::FunctionCallbackInfo<v8::Value>& args, |
33 |
|
|
unsigned int offset, |
34 |
|
|
RandomBytesConfig* params); |
35 |
|
|
|
36 |
|
|
static bool DeriveBits( |
37 |
|
|
Environment* env, |
38 |
|
|
const RandomBytesConfig& params, |
39 |
|
|
ByteSource* out_); |
40 |
|
|
|
41 |
|
|
static v8::Maybe<bool> EncodeOutput( |
42 |
|
|
Environment* env, |
43 |
|
|
const RandomBytesConfig& params, |
44 |
|
|
ByteSource* unused, |
45 |
|
|
v8::Local<v8::Value>* result); |
46 |
|
|
}; |
47 |
|
|
|
48 |
|
|
using RandomBytesJob = DeriveBitsJob<RandomBytesTraits>; |
49 |
|
|
|
50 |
|
|
namespace Random { |
51 |
|
|
void Initialize(Environment* env, v8::Local<v8::Object> target); |
52 |
|
|
} // namespace Random |
53 |
|
|
} // namespace crypto |
54 |
|
|
} // namespace node |
55 |
|
|
|
56 |
|
|
#endif // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS |
57 |
|
|
#endif // SRC_CRYPTO_CRYPTO_RANDOM_H_ |