GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: crypto/crypto_hmac.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_HMAC_H_
2
#define SRC_CRYPTO_CRYPTO_HMAC_H_
3
4
#if defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
5
6
#include "crypto/crypto_keys.h"
7
#include "crypto/crypto_sig.h"
8
#include "crypto/crypto_util.h"
9
#include "allocated_buffer.h"
10
#include "base_object.h"
11
#include "env.h"
12
#include "memory_tracker.h"
13
#include "v8.h"
14
15
namespace node {
16
namespace crypto {
17
class Hmac : public BaseObject {
18
 public:
19
  static void Initialize(Environment* env, v8::Local<v8::Object> target);
20
  static void RegisterExternalReferences(ExternalReferenceRegistry* registry);
21
22
  void MemoryInfo(MemoryTracker* tracker) const override;
23
  SET_MEMORY_INFO_NAME(Hmac)
24
  SET_SELF_SIZE(Hmac)
25
26
 protected:
27
  void HmacInit(const char* hash_type, const char* key, int key_len);
28
  bool HmacUpdate(const char* data, size_t len);
29
30
  static void New(const v8::FunctionCallbackInfo<v8::Value>& args);
31
  static void HmacInit(const v8::FunctionCallbackInfo<v8::Value>& args);
32
  static void HmacUpdate(const v8::FunctionCallbackInfo<v8::Value>& args);
33
  static void HmacDigest(const v8::FunctionCallbackInfo<v8::Value>& args);
34
35
  Hmac(Environment* env, v8::Local<v8::Object> wrap);
36
37
  static void Sign(const v8::FunctionCallbackInfo<v8::Value>& args);
38
39
 private:
40
  HMACCtxPointer ctx_;
41
};
42
43
struct HmacConfig final : public MemoryRetainer {
44
  CryptoJobMode job_mode;
45
  SignConfiguration::Mode mode;
46
  std::shared_ptr<KeyObjectData> key;
47
  ByteSource data;
48
  ByteSource signature;
49
  const EVP_MD* digest;
50
51
102
  HmacConfig() = default;
52
53
  explicit HmacConfig(HmacConfig&& other) noexcept;
54
55
  HmacConfig& operator=(HmacConfig&& other) noexcept;
56
57
  void MemoryInfo(MemoryTracker* tracker) const override;
58
  SET_MEMORY_INFO_NAME(HmacConfig)
59
  SET_SELF_SIZE(HmacConfig)
60
};
61
62
struct HmacTraits final {
63
  using AdditionalParameters = HmacConfig;
64
  static constexpr const char* JobName = "HmacJob";
65
66
// TODO(@jasnell): Sign request vs. Verify request
67
68
  static constexpr AsyncWrap::ProviderType Provider =
69
      AsyncWrap::PROVIDER_SIGNREQUEST;
70
71
  static v8::Maybe<bool> AdditionalConfig(
72
      CryptoJobMode mode,
73
      const v8::FunctionCallbackInfo<v8::Value>& args,
74
      unsigned int offset,
75
      HmacConfig* params);
76
77
  static bool DeriveBits(
78
      Environment* env,
79
      const HmacConfig& params,
80
      ByteSource* out);
81
82
  static v8::Maybe<bool> EncodeOutput(
83
      Environment* env,
84
      const HmacConfig& params,
85
      ByteSource* out,
86
      v8::Local<v8::Value>* result);
87
};
88
89
using HmacJob = DeriveBitsJob<HmacTraits>;
90
91
}  // namespace crypto
92
}  // namespace node
93
94
#endif  // defined(NODE_WANT_INTERNALS) && NODE_WANT_INTERNALS
95
#endif  // SRC_CRYPTO_CRYPTO_HMAC_H_