mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-21 05:09:34 -06:00
Common/Crypto/SHA1: Add DigestToString() utility function
This commit is contained in:

committed by
Admiral H. Curtiss

parent
bb4e8d0d01
commit
360f899f68
@ -385,4 +385,20 @@ Digest CalculateDigest(const u8* msg, size_t len)
|
||||
ctx->Update(msg, len);
|
||||
return ctx->Finish();
|
||||
}
|
||||
|
||||
std::string DigestToString(const Digest& digest)
|
||||
{
|
||||
static constexpr std::array<char, 16> lookup = {'0', '1', '2', '3', '4', '5', '6', '7',
|
||||
'8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
|
||||
std::string hash;
|
||||
hash.reserve(digest.size() * 2);
|
||||
for (size_t i = 0; i < digest.size(); ++i)
|
||||
{
|
||||
const u8 upper = static_cast<u8>((digest[i] >> 4) & 0xf);
|
||||
const u8 lower = static_cast<u8>(digest[i] & 0xf);
|
||||
hash.push_back(lookup[upper]);
|
||||
hash.push_back(lookup[lower]);
|
||||
}
|
||||
return hash;
|
||||
}
|
||||
} // namespace Common::SHA1
|
||||
|
Reference in New Issue
Block a user