1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-13 07:54:32 +01:00
dxvk/src/util/sha1/sha1_util.h
Joshua Ashton e8ee7a0790 [util] Fix Sha1 dword extraction
Previously we were getting incorrect values here.

The u suffix is no longer necessary, which was originally there to work around a MSVC compiler warning which now doesn't happen under the new code 🤷‍♀
2019-10-06 00:28:19 +02:00

59 lines
1.1 KiB
C++

#pragma once
#include <array>
#include <cstring>
#include <string>
namespace dxvk {
using Sha1Digest = std::array<uint8_t, 20>;
struct Sha1Data {
const void* data;
size_t size;
};
class Sha1Hash {
public:
Sha1Hash() { }
Sha1Hash(const Sha1Digest& digest)
: m_digest(digest) { }
std::string toString() const;
uint32_t dword(uint32_t id) const {
return uint32_t(m_digest[4 * id + 0]) << 0
| uint32_t(m_digest[4 * id + 1]) << 8
| uint32_t(m_digest[4 * id + 2]) << 16
| uint32_t(m_digest[4 * id + 3]) << 24;
}
bool operator == (const Sha1Hash& other) const {
return !std::memcmp(
this->m_digest.data(),
other.m_digest.data(),
other.m_digest.size());
}
static Sha1Hash compute(
const void* data,
size_t size);
static Sha1Hash compute(
size_t numChunks,
const Sha1Data* chunks);
template<typename T>
static Sha1Hash compute(const T& data) {
return compute(&data, sizeof(T));
}
private:
Sha1Digest m_digest;
};
}