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

randombit / botan / 20579846577

29 Dec 2025 06:24PM UTC coverage: 90.415% (+0.2%) from 90.243%
20579846577

push

github

web-flow
Merge pull request #5167 from randombit/jack/src-size-reductions

Changes to reduce unnecessary inclusions

101523 of 112285 relevant lines covered (90.42%)

12817276.56 hits per line

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

89.8
/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
class ZFEC_KAT final : public Text_Based_Test {
×
18
   public:
19
      ZFEC_KAT() : Text_Based_Test("zfec.vec", "K,N,Data,Code") {}
2✔
20

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

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

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

32
         Test::Result result("ZFEC encoding/decoding");
243✔
33

34
         const size_t share_size = input.size() / K;
243✔
35

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

40
         std::map<size_t, const uint8_t*> shares;
243✔
41

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

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

53
         const Botan::ZFEC zfec(K, N);
243✔
54

55
         const std::string zfec_impl = zfec.provider();
243✔
56

57
         std::set<size_t> shares_encoded;
243✔
58

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

64
            result.test_lt("ZFEC enc share in range", share, N);
2,430✔
65

66
            result.test_eq(zfec_impl.c_str(), "share " + std::to_string(share), block, len, shares[share], share_size);
7,290✔
67
         };
2,430✔
68

69
         zfec.encode(input.data(), input.size(), zfec_enc_fn);
243✔
70

71
         result.test_eq("Correct number of shares encoded", shares_encoded.size(), N);
243✔
72

73
         // First test full decoding:
74
         std::set<size_t> shares_decoded;
243✔
75

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

81
            result.test_lt("ZFEC dec share in range", share, K);
2,430✔
82

83
            result.test_eq(
4,860✔
84
               zfec_impl.c_str(), "share " + std::to_string(share), block, len, &input[share * share_size], share_size);
7,290✔
85
         };
2,430✔
86

87
         zfec.decode_shares(shares, share_size, zfec_dec_fn);
243✔
88

89
         result.test_eq("Correct number of shares decoded", shares_decoded.size(), K);
243✔
90

91
         // Now remove N-K shares:
92
         shares_decoded.clear();
243✔
93

94
         while(shares.size() != K) {
41,541✔
95
            const size_t idx = this->rng().next_byte();
41,298✔
96
            shares.erase(idx);
41,298✔
97
         }
98

99
         zfec.decode_shares(shares, share_size, zfec_dec_fn);
243✔
100

101
         result.test_eq("Correct number of shares decoded", shares_decoded.size(), K);
243✔
102

103
         return result;
243✔
104
      }
972✔
105
};
106

107
BOTAN_REGISTER_SERIALIZED_TEST("zfec", "zfec", ZFEC_KAT);
108

109
}  // namespace Botan_Tests
110

111
#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