0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-12 13:01:07 +01:00

ircd:Ⓜ️:event: Compare decoded hash to allow both rfc4648 and rfc1421 compat.

This commit is contained in:
Jason Volk 2020-09-28 05:49:18 -07:00
parent 4170235686
commit bd641e76ad
2 changed files with 9 additions and 16 deletions

View file

@ -45,7 +45,6 @@ namespace ircd::m
event signatures(const mutable_buffer &, const m::event &);
event essential(event, const mutable_buffer &content);
bool verify_sha256b64(const event &, const string_view &);
bool verify_hash(const event &, const sha256::buf &);
bool verify_hash(const event &);

View file

@ -237,20 +237,7 @@ ircd::m::verify_hash(const event &event)
bool
ircd::m::verify_hash(const event &event,
const sha256::buf &hash)
{
static constexpr size_t hashb64sz
{
size_t(sha256::digest_size * 1.34) + 1
};
thread_local char b64buf[hashb64sz];
return verify_sha256b64(event, b64::encode_unpadded(b64buf, hash));
}
bool
ircd::m::verify_sha256b64(const event &event,
const string_view &b64)
const sha256::buf &actual)
try
{
const json::object &object
@ -263,7 +250,14 @@ try
object.at("sha256")
};
return hash == b64;
thread_local char buf[32];
const auto claim
{
b64::decode(buf, hash)
};
static_assert(sizeof(buf) == sizeof(actual));
return memcmp(buf, ircd::data(actual), sizeof(buf)) == 0;
}
catch(const json::not_found &)
{