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

randombit / botan / 23225340130

18 Mar 2026 01:53AM UTC coverage: 89.677% (-0.001%) from 89.678%
23225340130

push

github

web-flow
Merge pull request #5456 from randombit/jack/clang-tidy-22

Fix various warnings from clang-tidy 22

104438 of 116460 relevant lines covered (89.68%)

11819947.55 hits per line

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

85.37
/src/tests/test_pad.cpp
1
/*
2
* (C) 2016 René Korthaus, Rohde & Schwarz Cybersecurity
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_CIPHER_MODE_PADDING)
10
   #include <botan/internal/mode_pad.h>
11
#endif
12

13
namespace Botan_Tests {
14

15
namespace {
16

17
#if defined(BOTAN_HAS_CIPHER_MODE_PADDING)
18

19
class Cipher_Mode_Padding_Tests final : public Text_Based_Test {
×
20
   public:
21
      Cipher_Mode_Padding_Tests() : Text_Based_Test("pad.vec", "In,Blocksize", "Out") {}
2✔
22

23
      Test::Result run_one_test(const std::string& header, const VarMap& vars) override {
66✔
24
         const std::vector<uint8_t> input = vars.get_req_bin("In");
66✔
25
         const std::vector<uint8_t> expected = vars.get_opt_bin("Out");
66✔
26
         const size_t block_size = vars.get_req_sz("Blocksize");
66✔
27

28
         std::string algo = header;
66✔
29

30
         auto underscore = algo.find('_');
66✔
31
         if(underscore != std::string::npos) {
66✔
32
            if(algo.substr(underscore + 1, std::string::npos) != "Invalid") {
28✔
33
               throw Test_Error("Unexpected padding header " + header);
×
34
            }
35
            algo.resize(underscore);  // Use just the part before the underscore
28✔
36
         }
37

38
         Test::Result result(algo);
66✔
39

40
         auto pad = Botan::BlockCipherModePaddingMethod::create(algo);
66✔
41

42
         if(!pad) {
66✔
43
            result.test_failure("Invalid padding method: " + algo);
×
44
            return result;
×
45
         }
46

47
         if(expected.empty()) {
66✔
48
            // This is an unpad an invalid input and ensure we reject
49
            if(pad->unpad(std::span{input}.last(block_size)) != block_size) {
28✔
50
               result.test_failure("Did not reject invalid padding", input);
×
51
            } else {
52
               result.test_success("Rejected invalid padding");
28✔
53
            }
54
         } else {
55
            // This is a pad plaintext and unpad valid padding round trip test
56
            Botan::secure_vector<uint8_t> buf(input.begin(), input.end());
38✔
57
            const size_t outlen = pad->output_length(buf.size(), block_size);
38✔
58
            if(!result.test_sz_eq("output length", outlen, expected.size())) {
38✔
59
               return result;
×
60
            }
61
            buf.resize(outlen);
38✔
62
            pad->add_padding(buf, input.size() % block_size, block_size);
38✔
63
            result.test_bin_eq("pad", buf, expected);
38✔
64

65
            buf.assign(expected.begin(), expected.end());
38✔
66

67
            const auto pad_bytes = [&] {
114✔
68
               if(algo == "NoPadding") {
38✔
69
                  const size_t maybe_partial = (buf.size() < block_size) ? buf.size() : block_size;
5✔
70
                  const auto no_padding = maybe_partial - pad->unpad(std::span{buf}.last(maybe_partial));
5✔
71
                  result.test_sz_eq("no padding", no_padding, 0);
5✔
72
                  return no_padding;
5✔
73
               } else {
74
                  return block_size - pad->unpad(std::span{buf}.last(block_size));
33✔
75
               }
76
            }();
38✔
77

78
            buf.resize(buf.size() - pad_bytes);  // remove padding
38✔
79
            result.test_bin_eq("unpad", buf, input);
38✔
80
         }
38✔
81

82
         return result;
83
      }
198✔
84
};
85

86
BOTAN_REGISTER_TEST("modes", "bc_pad", Cipher_Mode_Padding_Tests);
87

88
#endif
89

90
}  // namespace
91

92
}  // namespace Botan_Tests
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