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

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 hits per line

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

83.87
/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
#if defined(BOTAN_HAS_CIPHER_MODE_PADDING)
16

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

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

26
         std::string algo = header;
66✔
27

28
         auto underscore = algo.find('_');
66✔
29
         if(underscore != std::string::npos) {
66✔
30
            if(algo.substr(underscore + 1, std::string::npos) != "Invalid") {
28✔
31
               throw Test_Error("Unexpected padding header " + header);
×
32
            }
33
            algo = algo.substr(0, underscore);
28✔
34
         }
35

36
         Test::Result result(algo);
132✔
37

38
         auto pad = Botan::BlockCipherModePaddingMethod::create(algo);
66✔
39

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

45
         if(expected.empty()) {
66✔
46
            // This is an unpad an invalid input and ensure we reject
47
            if(pad->unpad(input.data(), block_size) != block_size) {
28✔
48
               result.test_failure("Did not reject invalid padding", Botan::hex_encode(input));
×
49
            } else {
50
               result.test_success("Rejected invalid padding");
56✔
51
            }
52
         } else {
53
            // This is a pad plaintext and unpad valid padding round trip test
54
            Botan::secure_vector<uint8_t> buf(input.begin(), input.end());
38✔
55
            pad->add_padding(buf, input.size() % block_size, block_size);
38✔
56
            result.test_eq("pad", buf, expected);
38✔
57

58
            buf.assign(expected.begin(), expected.end());
38✔
59

60
            const size_t last_block = (buf.size() < block_size) ? 0 : buf.size() - block_size;
38✔
61
            const size_t pad_bytes = block_size - pad->unpad(&buf[last_block], block_size);
38✔
62
            buf.resize(buf.size() - pad_bytes);  // remove padding
38✔
63
            result.test_eq("unpad", buf, input);
76✔
64
         }
38✔
65

66
         return result;
67
      }
176✔
68
};
69

70
BOTAN_REGISTER_TEST("modes", "bc_pad", Cipher_Mode_Padding_Tests);
71

72
#endif
73

74
}
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

© 2025 Coveralls, Inc