hash.h 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. * Based on
  3. * 1. OpenSSL lib
  4. * 2. PurpleI2P source code
  5. * 3. cppcodec lib
  6. *
  7. * PUBLIC DOMAIN C++ WRAPPER
  8. * acetone, 2022
  9. */
  10. #ifndef HASH_H
  11. #define HASH_H
  12. #include <vector>
  13. #include <string>
  14. using uint8_t = unsigned char;
  15. namespace FriendlyCrypto {
  16. namespace Hash {
  17. class Sum {
  18. public:
  19. Sum (const std::vector<uint8_t>& raw)
  20. : m_data(raw) {};
  21. const std::vector<uint8_t> data() const noexcept;
  22. const std::string base64String() const noexcept;
  23. bool operator==(const Hash::Sum& another) const noexcept;
  24. bool operator==(const std::vector<uint8_t>& rawAnother) const noexcept;
  25. bool operator==(const std::string& base64String) const noexcept;
  26. private:
  27. std::vector<uint8_t> m_data;
  28. };
  29. //// FUNCTIONS
  30. Hash::Sum sha256 (const std::vector<uint8_t>& data) noexcept;
  31. Hash::Sum sha512 (const std::vector<uint8_t>& data) noexcept;
  32. Hash::Sum md5 (const std::vector<uint8_t>& data) noexcept;
  33. } // namespace Hash
  34. } // namespace FriendlyCrypto
  35. #endif // HASH_H