mirror of
https://github.com/matrix-construct/construct
synced 2024-11-29 02:02:38 +01:00
modules/key/server: Move static ed25519 test to s_keys from here.
This commit is contained in:
parent
864a5b43dd
commit
d32fd05a83
2 changed files with 64 additions and 64 deletions
|
@ -53,67 +53,3 @@ method_get
|
|||
{
|
||||
server_resource, "GET", handle_get
|
||||
};
|
||||
|
||||
#ifdef RB_DEBUG
|
||||
__attribute__((constructor))
|
||||
#endif
|
||||
static void
|
||||
_test_ed25519_()
|
||||
noexcept
|
||||
{
|
||||
using namespace ircd;
|
||||
|
||||
char seed_buf[ed25519::SEED_SZ + 10];
|
||||
const auto seed
|
||||
{
|
||||
b64decode(seed_buf, "YJDBA9Xnr2sVqXD9Vj7XVUnmFZcZrlw8Md7kMW+3XA1")
|
||||
};
|
||||
|
||||
ed25519::pk pk;
|
||||
ed25519::sk sk{&pk, seed};
|
||||
|
||||
const auto SERVER_NAME {"domain"};
|
||||
const auto KEY_ID {"ed25519:1"};
|
||||
|
||||
const auto test{[&]
|
||||
(const std::string &object) -> bool
|
||||
{
|
||||
const auto sig
|
||||
{
|
||||
sk.sign(const_buffer{object})
|
||||
};
|
||||
|
||||
char sigb64_buf[128];
|
||||
const auto sigb64
|
||||
{
|
||||
b64encode_unpadded(sigb64_buf, sig)
|
||||
};
|
||||
|
||||
ed25519::sig unsig; const auto unsigb64
|
||||
{
|
||||
b64decode(unsig, sigb64)
|
||||
};
|
||||
|
||||
return pk.verify(const_buffer{object}, unsig);
|
||||
}};
|
||||
|
||||
const bool tests[]
|
||||
{
|
||||
test(std::string{json::object
|
||||
{
|
||||
"{}"
|
||||
}}),
|
||||
|
||||
test(json::strung(json::members
|
||||
{
|
||||
{ "one", 1L },
|
||||
{ "two", "Two" }
|
||||
})),
|
||||
};
|
||||
|
||||
if(!std::all_of(begin(tests), end(tests), [](const bool &b) { return b; }))
|
||||
throw ircd::panic
|
||||
{
|
||||
"Seeded ed25519 test failed"
|
||||
};
|
||||
}
|
||||
|
|
|
@ -672,3 +672,67 @@ cache_get(const string_view &server_name,
|
|||
node_room.get(std::nothrow, "ircd.key", reclosure):
|
||||
node_room.get(std::nothrow, "ircd.key", key_id, reclosure);
|
||||
}
|
||||
|
||||
#ifdef RB_DEBUG
|
||||
__attribute__((constructor))
|
||||
#endif
|
||||
static void
|
||||
_test_ed25519_()
|
||||
noexcept
|
||||
{
|
||||
using namespace ircd;
|
||||
|
||||
char seed_buf[ed25519::SEED_SZ + 10];
|
||||
const auto seed
|
||||
{
|
||||
b64decode(seed_buf, "YJDBA9Xnr2sVqXD9Vj7XVUnmFZcZrlw8Md7kMW+3XA1")
|
||||
};
|
||||
|
||||
ed25519::pk pk;
|
||||
ed25519::sk sk{&pk, seed};
|
||||
|
||||
const auto SERVER_NAME {"domain"};
|
||||
const auto KEY_ID {"ed25519:1"};
|
||||
|
||||
const auto test{[&]
|
||||
(const std::string &object) -> bool
|
||||
{
|
||||
const auto sig
|
||||
{
|
||||
sk.sign(const_buffer{object})
|
||||
};
|
||||
|
||||
char sigb64_buf[128];
|
||||
const auto sigb64
|
||||
{
|
||||
b64encode_unpadded(sigb64_buf, sig)
|
||||
};
|
||||
|
||||
ed25519::sig unsig; const auto unsigb64
|
||||
{
|
||||
b64decode(unsig, sigb64)
|
||||
};
|
||||
|
||||
return pk.verify(const_buffer{object}, unsig);
|
||||
}};
|
||||
|
||||
const bool tests[]
|
||||
{
|
||||
test(std::string{json::object
|
||||
{
|
||||
"{}"
|
||||
}}),
|
||||
|
||||
test(json::strung(json::members
|
||||
{
|
||||
{ "one", 1L },
|
||||
{ "two", "Two" }
|
||||
})),
|
||||
};
|
||||
|
||||
if(!std::all_of(begin(tests), end(tests), [](const bool &b) { return b; }))
|
||||
throw ircd::panic
|
||||
{
|
||||
"Seeded ed25519 test failed"
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue