mirror of
https://github.com/matrix-construct/construct
synced 2024-11-19 08:21:09 +01:00
ircd:Ⓜ️ Convenience to close over decoded ed25519::pk directly.
This commit is contained in:
parent
e74fb81860
commit
0b3ec2b476
3 changed files with 36 additions and 19 deletions
|
@ -65,12 +65,14 @@ struct ircd::m::keys
|
||||||
public:
|
public:
|
||||||
using closure = std::function<void (const keys &)>;
|
using closure = std::function<void (const keys &)>;
|
||||||
using key_closure = std::function<void (const string_view &)>; // remember to unquote()!!!
|
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 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 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 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 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::tuple;
|
||||||
using super_type::operator=;
|
using super_type::operator=;
|
||||||
|
|
20
ircd/m/m.cc
20
ircd/m/m.cc
|
@ -353,6 +353,26 @@ std::string
|
||||||
ircd::m::self::tls_cert_der_sha256_b64
|
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
|
void
|
||||||
ircd::m::keys::get(const string_view &server_name,
|
ircd::m::keys::get(const string_view &server_name,
|
||||||
const string_view &key_id,
|
const string_view &key_id,
|
||||||
|
|
|
@ -154,35 +154,30 @@ const
|
||||||
|
|
||||||
bool
|
bool
|
||||||
ircd::m::request::verify(const string_view &key,
|
ircd::m::request::verify(const string_view &key,
|
||||||
const string_view &sig)
|
const string_view &sig_)
|
||||||
const
|
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
|
|
||||||
{
|
|
||||||
[this, &key](auto &buf)
|
|
||||||
{
|
|
||||||
const auto &origin
|
const auto &origin
|
||||||
{
|
{
|
||||||
unquote(at<"origin"_>(*this))
|
unquote(at<"origin"_>(*this))
|
||||||
};
|
};
|
||||||
|
|
||||||
m::keys::get(origin, key, [&buf]
|
bool verified{false};
|
||||||
(const string_view &key)
|
m::keys::get(origin, key, [this, &verified, &sig]
|
||||||
|
(const ed25519::pk &pk)
|
||||||
{
|
{
|
||||||
b64decode(buf, unquote(key));
|
verified = verify(pk, sig);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return verify(pk, _sig);
|
return verified;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool
|
bool
|
||||||
|
|
Loading…
Reference in a new issue