lhashes  1.0.0
C++ hashes library
lhashes_sha1.h
Go to the documentation of this file.
1 /*
2  * ======================================================================================
3  * __ ____ __ __ ____ ___
4  * ( ) (_ _)( \/ )( ___)/ __)
5  * )(__ _)(_ ) ( )__) \__ \
6  * (____)(____)(_/\/\_)(____)(___/
7  *
8  * This file is part of the Limes open source library and is licensed under the terms of the GNU Public License.
9  *
10  * Commercial licenses are available; contact the maintainers at ben.the.vining@gmail.com to inquire for details.
11  *
12  * ======================================================================================
13  */
14 
15 #pragma once
16 
17 #include <cstdint>
18 #include <string>
19 #include <string_view>
20 #include "lhashes/lhashes_Export.h"
21 #include "lhashes/lhashes_hash.h"
22 
29 namespace limes::hash
30 {
31 
39 class LHASH_EXPORT SHA1 final : public Hasher // cppcheck-suppress noConstructor
40 {
41 public:
43  void update (const unsigned char* data, std::size_t length) final;
44 
46  [[nodiscard]] std::string getHash() final;
47 
49  [[nodiscard]] std::size_t getLengthOfHash() const final;
50 
51 private:
52  std::uint32_t digest[5] { 0x67452301, 0xefcdab89, 0x98badcfe, 0x10325476, 0xc3d2e1f0 };
53 
54  std::string buffer;
55 
56  std::uint64_t transforms { 0 };
57 };
58 
64 [[nodiscard]] LHASH_EXPORT std::string sha1 (const char* input, std::size_t length);
65 
71 [[nodiscard]] LHASH_EXPORT std::string sha1 (std::string_view input);
72 
73 } // namespace limes::hash
A base class representing an object that calculates a hash function.
Definition: lhashes_hash.h:69
A Hasher object that calculates a SHA1 hash.
Definition: lhashes_sha1.h:40
std::string getHash() final
Retrieves the calculated SHA1 hash value as a string.
void update(const unsigned char *data, std::size_t length) final
Updates the internal state of the hasher with new data.
LHASH_EXPORT std::string sha1(const char *input, std::size_t length)
Calculates a SHA1 hash for the given data.
LHASH_EXPORT std::string sha1(std::string_view input)
Calculates a SHA1 hash for the given string.
This file defines the hash::Hasher class and the hash::hash() free functions.
Cryptographic hash functions.