• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

randombit / botan / 23114513202

15 Mar 2026 04:32PM UTC coverage: 91.99% (+2.3%) from 89.738%
23114513202

push

github

web-flow
Merge pull request #5446 from randombit/jack/fix-clang-tidy-22-warnings

Address (or silence) various new warnings from clang-tidy 22

106961 of 116275 relevant lines covered (91.99%)

11215912.22 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

90.0
/src/tests/test_zfec.cpp
1
/*
2
* (C) 2021 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "tests.h"
8

9
#if defined(BOTAN_HAS_ZFEC)
10

11
   #include <botan/rng.h>
12
   #include <botan/zfec.h>
13
   #include <set>
14

15
namespace Botan_Tests {
16

17
namespace {
18

19
class ZFEC_KAT final : public Text_Based_Test {
×
20
   public:
21
      ZFEC_KAT() : Text_Based_Test("zfec.vec", "K,N,Data,Code") {}
2✔
22

23
      Test::Result run_one_test(const std::string& /*header*/, const VarMap& vars) override {
243✔
24
         const size_t K = vars.get_req_sz("K");
243✔
25
         const size_t N = vars.get_req_sz("N");
243✔
26

27
         const std::vector<uint8_t> input = vars.get_req_bin("Data");
243✔
28
         const std::vector<uint8_t> expected = vars.get_req_bin("Code");
243✔
29

30
         if(input.size() % K != 0) {
243✔
31
            throw Test_Error("ZFEC input is not a multiple of K bytes");
×
32
         }
33

34
         Test::Result result("ZFEC encoding/decoding");
243✔
35

36
         const size_t share_size = input.size() / K;
243✔
37

38
         if(expected.size() != share_size * (N - K)) {
243✔
39
            throw Test_Error("ZFEC output does not correspond with K/N");
×
40
         }
41

42
         std::map<size_t, const uint8_t*> shares;
243✔
43

44
         for(size_t i = 0; i != N; ++i) {
2,673✔
45
            const uint8_t* expected_share = nullptr;
2,430✔
46
            if(i < K) {
2,430✔
47
               expected_share = &input[share_size * i];
1,215✔
48
            } else {
49
               expected_share = &expected[share_size * (i - K)];
1,215✔
50
            }
51

52
            shares.insert(std::make_pair(i, expected_share));
2,430✔
53
         }
54

55
         const Botan::ZFEC zfec(K, N);
243✔
56

57
         const std::string zfec_impl = zfec.provider();
243✔
58

59
         std::set<size_t> shares_encoded;
243✔
60

61
         auto zfec_enc_fn = [&](size_t share, const uint8_t block[], size_t len) {
2,673✔
62
            if(shares_encoded.insert(share).second == false) {
2,430✔
63
               result.test_failure("Encoding returned the same share twice");
×
64
            }
65

66
            result.test_sz_lt("ZFEC enc share in range", share, N);
2,430✔
67

68
            result.test_bin_eq(
4,860✔
69
               zfec_impl + " share " + std::to_string(share), {block, len}, {shares[share], share_size});
4,860✔
70
         };
2,430✔
71

72
         zfec.encode(input.data(), input.size(), zfec_enc_fn);
243✔
73

74
         result.test_sz_eq("Correct number of shares encoded", shares_encoded.size(), N);
243✔
75

76
         // First test full decoding:
77
         std::set<size_t> shares_decoded;
243✔
78

79
         auto zfec_dec_fn = [&](size_t share, const uint8_t block[], size_t len) {
2,673✔
80
            if(shares_decoded.insert(share).second == false) {
2,430✔
81
               result.test_failure("Decoding returned the same share twice");
×
82
            }
83

84
            result.test_sz_lt("ZFEC dec share in range", share, K);
2,430✔
85

86
            result.test_bin_eq(
2,430✔
87
               zfec_impl + " share " + std::to_string(share), {block, len}, {&input[share * share_size], share_size});
4,860✔
88
         };
2,430✔
89

90
         zfec.decode_shares(shares, share_size, zfec_dec_fn);
243✔
91

92
         result.test_sz_eq("Correct number of shares decoded", shares_decoded.size(), K);
243✔
93

94
         // Now remove N-K shares:
95
         shares_decoded.clear();
243✔
96

97
         while(shares.size() != K) {
45,467✔
98
            const size_t idx = this->rng().next_byte();
45,224✔
99
            shares.erase(idx);
45,224✔
100
         }
101

102
         zfec.decode_shares(shares, share_size, zfec_dec_fn);
243✔
103

104
         result.test_sz_eq("Correct number of shares decoded", shares_decoded.size(), K);
243✔
105

106
         return result;
243✔
107
      }
972✔
108
};
109

110
BOTAN_REGISTER_SERIALIZED_TEST("zfec", "zfec", ZFEC_KAT);
111

112
}  // namespace
113

114
}  // namespace Botan_Tests
115

116
#endif
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc