libfilezilla
hash.hpp
Go to the documentation of this file.
1 #ifndef LIBFILEZILLA_HASH_HEADER
2 #define LIBFILEZILLA_HASH_HEADER
3 
8 #include "libfilezilla.hpp"
9 
10 #include <vector>
11 #include <string>
12 
13 namespace fz {
14 
16 enum class hash_algorithm
17 {
18  md5,
19  sha1,
20  sha256,
21  sha512
22 };
23 
25 class FZ_PUBLIC_SYMBOL hash_accumulator final
26 {
27 public:
31 
32  hash_accumulator(hash_accumulator const&) = delete;
33  hash_accumulator& operator=(hash_accumulator const&) = delete;
34 
35  void reinit();
36 
37  void update(std::string_view const& data);
38  void update(std::basic_string_view<uint8_t> const& data);
39  void update(std::vector<uint8_t> const& data);
40  void update(uint8_t const* data, size_t size);
41  void update(uint8_t in) {
42  update(&in, 1);
43  }
44 
46  std::vector<uint8_t> digest();
47 
48  operator std::vector<uint8_t>() {
49  return digest();
50  }
51 
52  template<typename T>
53  hash_accumulator& operator<<(T && in) {
54  update(std::forward<T>(in));
55  return *this;
56  }
57 
58  class impl;
59 private:
60  impl* impl_;
61 };
62 
67 std::vector<uint8_t> FZ_PUBLIC_SYMBOL md5(std::string_view const& data);
68 std::vector<uint8_t> FZ_PUBLIC_SYMBOL md5(std::vector<uint8_t> const& data);
69 
71 std::vector<uint8_t> FZ_PUBLIC_SYMBOL sha256(std::string_view const& data);
72 std::vector<uint8_t> FZ_PUBLIC_SYMBOL sha256(std::vector<uint8_t> const& data);
73 
75 std::vector<uint8_t> FZ_PUBLIC_SYMBOL hmac_sha256(std::string_view const& key, std::string_view const& data);
76 std::vector<uint8_t> FZ_PUBLIC_SYMBOL hmac_sha256(std::vector<uint8_t> const& key, std::vector<uint8_t> const& data);
77 std::vector<uint8_t> FZ_PUBLIC_SYMBOL hmac_sha256(std::vector<uint8_t> const& key, std::string_view const& data);
78 std::vector<uint8_t> FZ_PUBLIC_SYMBOL hmac_sha256(std::string_view const& key, std::vector<uint8_t> const& data);
79 
80 }
81 
82 #endif
fz::hmac_sha256
std::vector< uint8_t > hmac_sha256(std::string_view const &key, std::string_view const &data)
Standard HMAC using SHA256.
fz::hash_accumulator::digest
std::vector< uint8_t > digest()
Returns the raw digest and reinitializes the accumulator.
fz::sha256
std::vector< uint8_t > sha256(std::string_view const &data)
Standard SHA256.
fz::hash_accumulator::hash_accumulator
hash_accumulator(hash_algorithm algorithm)
Creates an initialized accumulator for the passed algorithm.
fz::md5
std::vector< uint8_t > md5(std::string_view const &data)
Standard MD5.
fz::hash_algorithm
hash_algorithm
List of supported hashing algorithms.
Definition: hash.hpp:17
libfilezilla.hpp
Sets some global macros and further includes string.hpp.
fz
The namespace used by libfilezilla.
Definition: apply.hpp:17
fz::hash_accumulator
Accumulator for hashing large amounts of data.
Definition: hash.hpp:26