/src/node/src/crypto/crypto_hash.h
Line  | Count  | Source  | 
1  |  | #ifndef SRC_CRYPTO_CRYPTO_HASH_H_  | 
2  |  | #define SRC_CRYPTO_CRYPTO_HASH_H_  | 
3  |  |  | 
4  |  | #if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS  | 
5  |  |  | 
6  |  | #include "base_object.h"  | 
7  |  | #include "crypto/crypto_keys.h"  | 
8  |  | #include "crypto/crypto_util.h"  | 
9  |  | #include "env.h"  | 
10  |  | #include "memory_tracker.h"  | 
11  |  | #include "v8.h"  | 
12  |  |  | 
13  |  | namespace node { | 
14  |  | namespace crypto { | 
15  |  | class Hash final : public BaseObject { | 
16  |  |  public:  | 
17  |  |   static void Initialize(Environment* env, v8::Local<v8::Object> target);  | 
18  |  |   static void RegisterExternalReferences(ExternalReferenceRegistry* registry);  | 
19  |  |  | 
20  |  |   void MemoryInfo(MemoryTracker* tracker) const override;  | 
21  |  |   SET_MEMORY_INFO_NAME(Hash)  | 
22  |  |   SET_SELF_SIZE(Hash)  | 
23  |  |  | 
24  |  |   bool HashInit(const EVP_MD* md, v8::Maybe<unsigned int> xof_md_len);  | 
25  |  |   bool HashUpdate(const char* data, size_t len);  | 
26  |  |  | 
27  |  |   static void GetHashes(const v8::FunctionCallbackInfo<v8::Value>& args);  | 
28  |  |   static void GetCachedAliases(const v8::FunctionCallbackInfo<v8::Value>& args);  | 
29  |  |   static void OneShotDigest(const v8::FunctionCallbackInfo<v8::Value>& args);  | 
30  |  |  | 
31  |  |  protected:  | 
32  |  |   static void New(const v8::FunctionCallbackInfo<v8::Value>& args);  | 
33  |  |   static void HashUpdate(const v8::FunctionCallbackInfo<v8::Value>& args);  | 
34  |  |   static void HashDigest(const v8::FunctionCallbackInfo<v8::Value>& args);  | 
35  |  |  | 
36  |  |   Hash(Environment* env, v8::Local<v8::Object> wrap);  | 
37  |  |  | 
38  |  |  private:  | 
39  |  |   ncrypto::EVPMDCtxPointer mdctx_{}; | 
40  |  |   unsigned int md_len_ = 0;  | 
41  |  |   ByteSource digest_;  | 
42  |  | };  | 
43  |  |  | 
44  |  | struct HashConfig final : public MemoryRetainer { | 
45  |  |   CryptoJobMode mode;  | 
46  |  |   ByteSource in;  | 
47  |  |   const EVP_MD* digest;  | 
48  |  |   unsigned int length;  | 
49  |  |  | 
50  | 0  |   HashConfig() = default;  | 
51  |  |  | 
52  |  |   explicit HashConfig(HashConfig&& other) noexcept;  | 
53  |  |  | 
54  |  |   HashConfig& operator=(HashConfig&& other) noexcept;  | 
55  |  |  | 
56  |  |   void MemoryInfo(MemoryTracker* tracker) const override;  | 
57  |  |   SET_MEMORY_INFO_NAME(HashConfig)  | 
58  |  |   SET_SELF_SIZE(HashConfig)  | 
59  |  | };  | 
60  |  |  | 
61  |  | struct HashTraits final { | 
62  |  |   using AdditionalParameters = HashConfig;  | 
63  |  |   static constexpr const char* JobName = "HashJob";  | 
64  |  |   static constexpr AsyncWrap::ProviderType Provider =  | 
65  |  |       AsyncWrap::PROVIDER_HASHREQUEST;  | 
66  |  |  | 
67  |  |   static v8::Maybe<void> AdditionalConfig(  | 
68  |  |       CryptoJobMode mode,  | 
69  |  |       const v8::FunctionCallbackInfo<v8::Value>& args,  | 
70  |  |       unsigned int offset,  | 
71  |  |       HashConfig* params);  | 
72  |  |  | 
73  |  |   static bool DeriveBits(Environment* env,  | 
74  |  |                          const HashConfig& params,  | 
75  |  |                          ByteSource* out,  | 
76  |  |                          CryptoJobMode mode);  | 
77  |  |  | 
78  |  |   static v8::MaybeLocal<v8::Value> EncodeOutput(Environment* env,  | 
79  |  |                                                 const HashConfig& params,  | 
80  |  |                                                 ByteSource* out);  | 
81  |  | };  | 
82  |  |  | 
83  |  | using HashJob = DeriveBitsJob<HashTraits>;  | 
84  |  |  | 
85  |  | }  // namespace crypto  | 
86  |  | }  // namespace node  | 
87  |  |  | 
88  |  | #endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS  | 
89  |  | #endif  // SRC_CRYPTO_CRYPTO_HASH_H_  |