libfilezilla
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 const& data);
38  void update(std::vector<uint8_t> const& data);
39  void update(uint8_t const* data, size_t size);
40  void update(uint8_t in) {
41  update(&in, 1);
42  }
43 
45  std::vector<uint8_t> digest();
46 
47  operator std::vector<uint8_t>() {
48  return digest();
49  }
50 
51  template<typename T>
52  hash_accumulator& operator<<(T && in) {
53  update(std::forward<T>(in));
54  return *this;
55  }
56 
57  class impl;
58 private:
59  impl* impl_;
60 };
61 
66 std::vector<uint8_t> FZ_PUBLIC_SYMBOL md5(std::string const& data);
67 std::vector<uint8_t> FZ_PUBLIC_SYMBOL md5(std::vector<uint8_t> const& data);
68 
70 std::vector<uint8_t> FZ_PUBLIC_SYMBOL sha256(std::string const& data);
71 std::vector<uint8_t> FZ_PUBLIC_SYMBOL sha256(std::vector<uint8_t> const& data);
72 
74 std::vector<uint8_t> FZ_PUBLIC_SYMBOL hmac_sha256(std::string const& key, std::string const& data);
75 std::vector<uint8_t> FZ_PUBLIC_SYMBOL hmac_sha256(std::vector<uint8_t> const& key, std::vector<uint8_t> const& data);
76 std::vector<uint8_t> FZ_PUBLIC_SYMBOL hmac_sha256(std::vector<uint8_t> const& key, std::string const& data);
77 std::vector<uint8_t> FZ_PUBLIC_SYMBOL hmac_sha256(std::string const& key, std::vector<uint8_t> const& data);
78 
79 }
80 
81 #endif
std::vector< uint8_t > sha256(std::string const &data)
Standard SHA256.
std::vector< uint8_t > hmac_sha256(std::string const &key, std::string const &data)
Standard HMAC using SHA256.
hash_algorithm
List of supported hashing algorithms.
Definition: hash.hpp:16
Accumulator for hashing large amounts of data.
Definition: hash.hpp:25
The namespace used by libfilezilla.
Definition: apply.hpp:16
Sets some global macros and further includes string.hpp.
std::vector< uint8_t > md5(std::string const &data)
Standard MD5.