summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/util/hash.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/util/hash.h')
-rw-r--r--src/lib/util/hash.h52
1 files changed, 24 insertions, 28 deletions
diff --git a/src/lib/util/hash.h b/src/lib/util/hash.h
index 98a851bfd60..bd111224e6f 100644
--- a/src/lib/util/hash.h
+++ b/src/lib/util/hash.h
@@ -16,6 +16,10 @@
#pragma once
#include "hashing.h"
+#include "utilfwd.h"
+
+#include <memory>
+#include <system_error>
//**************************************************************************
@@ -30,6 +34,7 @@
namespace util {
+
//**************************************************************************
// TYPE DEFINITIONS
//**************************************************************************
@@ -40,6 +45,9 @@ namespace util {
// a collection of the various supported hashes and flags
class hash_collection
{
+ // forward declaration
+ class hash_creator;
+
public:
// hash types are identified by non-hex alpha values (G-Z)
static constexpr char HASH_CRC = 'R';
@@ -56,46 +64,44 @@ public:
// construction/destruction
hash_collection();
- hash_collection(const char *string);
- hash_collection(const hash_collection &src);
- ~hash_collection();
+ hash_collection(std::string_view string) : hash_collection() { from_internal_string(string); }
+ hash_collection(const hash_collection &src) : hash_collection() { copyfrom(src); }
// operators
hash_collection &operator=(const hash_collection &src);
- bool operator==(const hash_collection &rhs) const;
- bool operator!=(const hash_collection &rhs) const { return !(*this == rhs); }
+ bool operator==(const hash_collection &rhs) const noexcept;
+ bool operator!=(const hash_collection &rhs) const noexcept { return !(*this == rhs); }
// getters
- bool flag(char flag) const { return (m_flags.find_first_of(flag) != std::string::npos); }
+ bool flag(char flag) const noexcept { return (m_flags.find_first_of(flag) != std::string::npos); }
std::string hash_types() const;
// hash manipulators
- void reset();
- bool add_from_string(char type, const char *buffer, int length = -1);
- bool remove(char type);
+ void reset() noexcept;
+ bool add_from_string(char type, std::string_view string) noexcept;
+ bool remove(char type) noexcept;
// CRC-specific helpers
- bool crc(uint32_t &result) const { result = m_crc32; return m_has_crc32; }
- void add_crc(uint32_t crc) { m_crc32 = crc; m_has_crc32 = true; }
+ bool crc(uint32_t &result) const noexcept { result = m_crc32; return m_has_crc32; }
+ void add_crc(uint32_t crc) noexcept { m_crc32 = crc; m_has_crc32 = true; }
// SHA1-specific helpers
- bool sha1(sha1_t &result) const { result = m_sha1; return m_has_sha1; }
- void add_sha1(sha1_t sha1) { m_has_sha1 = true; m_sha1 = sha1; }
+ bool sha1(sha1_t &result) const noexcept { result = m_sha1; return m_has_sha1; }
+ void add_sha1(sha1_t sha1) noexcept { m_has_sha1 = true; m_sha1 = sha1; }
// string conversion
std::string internal_string() const;
std::string macro_string() const;
std::string attribute_string() const;
- bool from_internal_string(const char *string);
+ bool from_internal_string(std::string_view string);
// creation
- void begin(const char *types = nullptr);
- void buffer(const uint8_t *data, uint32_t length);
- void end();
- void compute(const uint8_t *data, uint32_t length, const char *types = nullptr) { begin(types); buffer(data, length); end(); }
+ void compute(const uint8_t *data, uint32_t length, const char *types = nullptr);
+ std::error_condition compute(random_read &stream, uint64_t offset, size_t length, size_t &actual, const char *types = nullptr);
private:
// internal helpers
+ std::unique_ptr<hash_creator> create(const char *types = nullptr);
void copyfrom(const hash_collection &src);
// internal state
@@ -104,16 +110,6 @@ private:
crc32_t m_crc32;
bool m_has_sha1;
sha1_t m_sha1;
-
- // creators
- struct hash_creator
- {
- bool m_doing_crc32;
- crc32_creator m_crc32_creator;
- bool m_doing_sha1;
- sha1_creator m_sha1_creator;
- };
- hash_creator * m_creator;
};