| 1 | // LAF Base Library |
| 2 | // Copyright (c) 2001-2016 David Capello |
| 3 | // |
| 4 | // This file is released under the terms of the MIT license. |
| 5 | // Read LICENSE.txt for more information. |
| 6 | |
| 7 | #ifndef BASE_SHA1_H_INCLUDED |
| 8 | #define BASE_SHA1_H_INCLUDED |
| 9 | #pragma once |
| 10 | |
| 11 | #include <vector> |
| 12 | #include <string> |
| 13 | |
| 14 | extern "C" struct SHA1Context; |
| 15 | |
| 16 | namespace base { |
| 17 | |
| 18 | class Sha1 { |
| 19 | public: |
| 20 | enum { HashSize = 20 }; |
| 21 | |
| 22 | Sha1(); |
| 23 | explicit Sha1(const std::vector<uint8_t>& digest); |
| 24 | |
| 25 | // Calculates the SHA1 of the given file or string. |
| 26 | static Sha1 calculateFromFile(const std::string& fileName); |
| 27 | static Sha1 calculateFromString(const std::string& text); |
| 28 | |
| 29 | bool operator==(const Sha1& other) const; |
| 30 | bool operator!=(const Sha1& other) const; |
| 31 | |
| 32 | uint8_t operator[](int index) const { |
| 33 | return m_digest[index]; |
| 34 | } |
| 35 | |
| 36 | const uint8_t *digest() const { |
| 37 | return m_digest.data(); |
| 38 | } |
| 39 | |
| 40 | size_t size() const { |
| 41 | return m_digest.size(); |
| 42 | } |
| 43 | |
| 44 | private: |
| 45 | std::vector<uint8_t> m_digest; |
| 46 | }; |
| 47 | |
| 48 | } // namespace base |
| 49 | |
| 50 | #endif // BASE_SHA1_H_INCLUDED |
| 51 | |