GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: crypto/crypto_hash.h Lines: 1 5 20.0 %
Date: 2021-12-25 04:14:02 Branches: 0 0 - %

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