/work/toxcore/crypto_core_test_util.cc
Line | Count | Source (jump to first uncovered line) |
1 | | #include "crypto_core_test_util.hh" |
2 | | |
3 | | #include <cstring> |
4 | | #include <iomanip> |
5 | | |
6 | | #include "crypto_core.h" |
7 | | #include "test_util.hh" |
8 | | #include "tox_random_impl.h" |
9 | | |
10 | | Tox_Random_Funcs const Random_Class::vtable = { |
11 | | Method<tox_random_bytes_cb, Random_Class>::invoke<&Random_Class::random_bytes>, |
12 | | Method<tox_random_uniform_cb, Random_Class>::invoke<&Random_Class::random_uniform>, |
13 | | }; |
14 | | |
15 | 25 | Random_Class::~Random_Class() = default; |
16 | | |
17 | | void Test_Random::random_bytes(void *obj, uint8_t *bytes, uint32_t length) |
18 | 2.16k | { |
19 | 2.16k | std::generate(bytes, &bytes[length], std::ref(lcg)); |
20 | 2.16k | } |
21 | | |
22 | | uint32_t Test_Random::random_uniform(void *obj, uint32_t upper_bound) |
23 | 0 | { |
24 | 0 | std::uniform_int_distribution<uint32_t> distrib(0, upper_bound); |
25 | 0 | return distrib(lcg); |
26 | 0 | } |
27 | | |
28 | | PublicKey random_pk(const Random *rng) |
29 | 77 | { |
30 | 77 | PublicKey pk; |
31 | 77 | random_bytes(rng, pk.data(), pk.size()); |
32 | 77 | return pk; |
33 | 77 | } |
34 | | |
35 | | std::ostream &operator<<(std::ostream &out, PublicKey const &pk) |
36 | 0 | { |
37 | 0 | out << '"'; |
38 | 0 | for (uint8_t byte : pk) { |
39 | 0 | out << std::setw(2) << std::setfill('0') << std::hex << uint32_t(byte); |
40 | 0 | } |
41 | 0 | out << '"'; |
42 | 0 | return out; |
43 | 0 | } |