Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
test_k1_recover.cpp
Go to the documentation of this file.
1#define BOOST_TEST_MODULE blake2
2#include <boost/test/included/unit_test.hpp>
3
5#include <fc/crypto/hex.hpp>
7#include <fc/utility.hpp>
8
9using namespace fc;
10
11#include "test_utils.hpp"
12
13namespace std {
14std::ostream& operator<<(std::ostream& st, const std::variant<fc::k1_recover_error, bytes>& err)
15{
16 if(std::holds_alternative<fc::k1_recover_error>(err))
17 st << static_cast<int32_t>(std::get<fc::k1_recover_error>(err));
18 else
19 st << fc::to_hex(std::get<bytes>(err));
20 return st;
21}
22}
23
24BOOST_AUTO_TEST_SUITE(k1_recover)
26
27 using test_k1_recover = std::tuple<std::string, std::string, std::variant<fc::k1_recover_error, bytes>>;
28 const std::vector<test_k1_recover> tests {
29 //test
30 {
31 "1b323dd47a1dd5592c296ee2ee12e0af38974087a475e99098a440284f19c1f7642fa0baa10a8a3ab800dfdbe987dee68a09b6fa3db45a5cc4f3a5835a1671d4dd",
32 "92390316873c5a9d520b28aba61e7a8f00025ac069acd9c4d2a71d775a55fa5f",
33 to_bytes("044424982f5c4044aaf27444965d15b53f219c8ad332bf98a98a902ebfb05d46cb86ea6fe663aa83fd4ce0a383855dfae9bf7a07b779d34c84c347fec79d04c51e")
34 },
35
36 //test (invalid signature v)
37 {
38 "01174de755b55bd29026d626f7313a5560353dc5175f29c78d79d961b81a0c04360d833ca789bc16d4ee714a6d1a19461d890966e0ec5c074f67be67e631d33aa7",
39 "45fd65f6dd062fe7020f11d19fe5c35dc4d425e1479c0968c8e932c208f25399",
41 },
42
43 //test (invalid signature len)
44 {
45 "174de755b55bd29026d626f7313a5560353dc5175f29c78d79d961b81a0c04360d833ca789bc16d4ee714a6d1a19461d890966e0ec5c074f67be67e631d33aa7",
46 "45fd65f6dd062fe7020f11d19fe5c35dc4d425e1479c0968c8e932c208f25399",
48 },
49
50 //test (invalid digest len)
51 {
52 "00174de755b55bd29026d626f7313a5560353dc5175f29c78d79d961b81a0c04360d833ca789bc16d4ee714a6d1a19461d890966e0ec5c074f67be67e631d33aa7",
53 "fd65f6dd062fe7020f11d19fe5c35dc4d425e1479c0968c8e932c208f25399",
55 },
56
57 };
58
59 for(const auto& test : tests) {
60
61 const auto& signature = to_bytes(std::get<0>(test));
62 const auto& digest = to_bytes(std::get<1>(test));
63 const auto& expected_result = std::get<2>(test);
64
65 auto res = fc::k1_recover(signature, digest);
66 BOOST_CHECK_EQUAL(res, expected_result);
67 }
68
70
71BOOST_AUTO_TEST_SUITE_END()
Defines exception's used by fc.
namespace sysio::chain
Definition authority.cpp:3
fc::sha256 digest(const T &value)
Definition digest.hpp:9
bytes signature
Definition pke.hpp:17
std::variant< k1_recover_error, bytes > k1_recover(const bytes &signature, const bytes &digest)
Definition name.hpp:106
std::ostream & operator<<(std::ostream &st, const std::variant< fc::alt_bn128_error, bytes > &err)
const unsigned char expected_result[]
Definition ssh.c:73
BOOST_AUTO_TEST_CASE(recover)
FC_LOG_AND_RETHROW()
bytes to_bytes(const std::string &source)
Definition test_utils.hpp:6