/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 | | Random_Funcs const Random_Class::vtable = { |
7 | | Method<crypto_random_bytes_cb, Random_Class>::invoke<&Random_Class::random_bytes>, |
8 | | Method<crypto_random_uniform_cb, Random_Class>::invoke<&Random_Class::random_uniform>, |
9 | | }; |
10 | | |
11 | 20 | Random_Class::~Random_Class() = default; |
12 | | |
13 | | void Test_Random::random_bytes(void *obj, uint8_t *bytes, size_t length) |
14 | 2.16k | { |
15 | 2.16k | std::generate(bytes, &bytes[length], std::ref(lcg)); |
16 | 2.16k | } |
17 | | |
18 | | uint32_t Test_Random::random_uniform(void *obj, uint32_t upper_bound) |
19 | 0 | { |
20 | 0 | std::uniform_int_distribution<uint32_t> distrib(0, upper_bound); |
21 | 0 | return distrib(lcg); |
22 | 0 | } |
23 | | |
24 | | PublicKey random_pk(const Random *rng) |
25 | 77 | { |
26 | 77 | PublicKey pk; |
27 | 77 | random_bytes(rng, pk.data(), pk.size()); |
28 | 77 | return pk; |
29 | 77 | } |
30 | | |
31 | | std::ostream &operator<<(std::ostream &out, PublicKey const &pk) |
32 | 0 | { |
33 | 0 | out << '"'; |
34 | 0 | for (uint8_t byte : pk) { |
35 | 0 | out << std::setw(2) << std::setfill('0') << std::hex << uint32_t(byte); |
36 | 0 | } |
37 | 0 | out << '"'; |
38 | 0 | return out; |
39 | 0 | } |