bsnes/nall/hash/hash.hpp
Tim Allen f3e67da937 Update to v101r19 release.
byuu says:

Changelog:

-   added \~130 new PAL games to icarus (courtesy of Smarthuman
    and aquaman)
-   added all three Korean-localized games to icarus
-   sfc: removed SuperDisc emulation (it was going nowhere)
-   sfc: fixed MSU1 regression where the play/repeat flags were not
    being cleared on track select
-   nall: cryptography support added; will be used to sign future
    databases (validation will always be optional)
-   minor shims to fix compilation issues due to nall changes

The real magic is that we now have 25-30% of the PAL SNES library in
icarus!

Signing will be tricky. Obviously if I put the public key inside the
higan archive, then all anyone has to do is change that public key for
their own releases. And if you download from my site (which is now over
HTTPS), then you don't need the signing to verify integrity. I may just
put the public key on my site on my site and leave it at that, we'll
see.
2016-10-28 08:16:58 +11:00

44 lines
1.1 KiB
C++

#pragma once
#include <nall/arithmetic.hpp>
#include <nall/range.hpp>
#include <nall/string.hpp>
//cannot use constructor inheritance due to needing to call virtual reset();
//instead, define a macro to reduce boilerplate code in every Hash subclass
#define nallHash(Name) \
Name() { reset(); } \
Name(const void* data, uint64_t size) : Name() { input(data, size); } \
Name(const vector<uint8_t>& data) : Name() { input(data); } \
Name(const string& data) : Name() { input(data); } \
using Hash::input; \
namespace nall { namespace Hash {
struct Hash {
virtual auto reset() -> void = 0;
virtual auto input(uint8_t data) -> void = 0;
virtual auto output() const -> vector<uint8_t> = 0;
auto input(const void* data, uint64_t size) -> void {
auto p = (const uint8_t*)data;
while(size--) input(*p++);
}
auto input(const vector<uint8_t>& data) -> void {
for(auto byte : data) input(byte);
}
auto input(const string& data) -> void {
for(auto byte : data) input(byte);
}
auto digest() const -> string {
string result;
for(auto n : output()) result.append(hex(n, 2L));
return result;
}
};
}}