0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-19 00:10:59 +01:00

ircd:Ⓜ️ Convenience to close over decoded ed25519::pk directly.

This commit is contained in:
Jason Volk 2018-03-20 18:46:20 -07:00
parent e74fb81860
commit 0b3ec2b476
3 changed files with 36 additions and 19 deletions

View file

@ -65,12 +65,14 @@ struct ircd::m::keys
public:
using closure = std::function<void (const keys &)>;
using key_closure = std::function<void (const string_view &)>; // remember to unquote()!!!
using ed25519_closure = std::function<void (const ed25519::pk &)>;
static void get(const string_view &server_name, const string_view &key_id, const string_view &query_server, const closure &);
static void get(const string_view &server_name, const closure &);
static void get(const string_view &server_name, const string_view &key_id, const closure &);
static void get(const string_view &server_name, const string_view &key_id, const key_closure &);
static void get(const string_view &server_name, const string_view &key_id, const ed25519_closure &);
using super_type::tuple;
using super_type::operator=;

View file

@ -353,6 +353,26 @@ std::string
ircd::m::self::tls_cert_der_sha256_b64
{};
void
ircd::m::keys::get(const string_view &server_name,
const string_view &key_id,
const ed25519_closure &closure)
{
get(server_name, key_id, key_closure{[&closure]
(const string_view &keyb64)
{
const ed25519::pk pk
{
[&keyb64](auto &buf)
{
b64decode(buf, unquote(keyb64));
}
};
closure(pk);
}});
}
void
ircd::m::keys::get(const string_view &server_name,
const string_view &key_id,

View file

@ -154,35 +154,30 @@ const
bool
ircd::m::request::verify(const string_view &key,
const string_view &sig)
const string_view &sig_)
const
{
const ed25519::sig _sig
const ed25519::sig sig
{
[&sig](auto &buf)
[&sig_](auto &buf)
{
b64decode(buf, sig);
b64decode(buf, sig_);
}
};
const ed25519::pk pk
const auto &origin
{
[this, &key](auto &buf)
{
const auto &origin
{
unquote(at<"origin"_>(*this))
};
m::keys::get(origin, key, [&buf]
(const string_view &key)
{
b64decode(buf, unquote(key));
});
}
unquote(at<"origin"_>(*this))
};
return verify(pk, _sig);
bool verified{false};
m::keys::get(origin, key, [this, &verified, &sig]
(const ed25519::pk &pk)
{
verified = verify(pk, sig);
});
return verified;
}
bool