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

randombit / botan / 5356685938

23 Jun 2023 01:39PM UTC coverage: 91.746% (+0.02%) from 91.728%
5356685938

push

github

randombit
Merge GH #3595 Apply clang-tidy more universally

Previously clang-tidy ruleset disabled certain rules for the cli and
tests. Remove these exceptions, and fix the relevant warnings.

Also fix compile_commands.json which had previously not provided information for
the examples, BoGo shim, or fuzzers. As a result, clang-tidy was effectively
blind to them. Fix various clang-tidy findings in these files.

Additionally fix clang-tidy warnings that were in Boost or Sqlite3 specific
code, which had been accidentally omitted in past checks.

Modify the nightly clang-tidy run to additionally check the examples, fuzzers,
shim, and Sqlite3/Boost specific code.

78183 of 85217 relevant lines covered (91.75%)

12364366.11 hits per line

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

75.0
/src/tests/test_pk_pad.cpp
1
/*
2
* (C) 2016 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_PK_PADDING)
10
   #include <botan/internal/emsa.h>
11
#endif
12

13
#if defined(BOTAN_HAS_EME_PKCS1)
14
   #include <botan/internal/eme_pkcs.h>
15
#endif
16

17
#include <botan/internal/fmt.h>
18

19
namespace Botan_Tests {
20

21
#if defined(BOTAN_HAS_EME_PKCS1)
22

23
class EME_PKCS1v15_Decoding_Tests final : public Text_Based_Test {
×
24
   public:
25
      EME_PKCS1v15_Decoding_Tests() : Text_Based_Test("pk_pad_eme/pkcs1.vec", "RawCiphertext", "Plaintext") {}
2✔
26

27
      Test::Result run_one_test(const std::string& hdr, const VarMap& vars) override {
18✔
28
         const bool is_valid = (hdr == "valid");
18✔
29

30
         Test::Result result("PKCSv15 Decoding");
18✔
31

32
         Botan::EME_PKCS1v15 pkcs;
18✔
33

34
         const std::vector<uint8_t> ciphertext = vars.get_req_bin("RawCiphertext");
18✔
35
         const std::vector<uint8_t> plaintext = vars.get_opt_bin("Plaintext");
18✔
36

37
         if(is_valid == false) {
18✔
38
            result.test_eq("Plaintext value should be empty for invalid EME inputs", plaintext.size(), 0);
22✔
39
         }
40

41
         uint8_t valid_mask = 0;
18✔
42
         Botan::secure_vector<uint8_t> decoded = pkcs.unpad(valid_mask, ciphertext.data(), ciphertext.size());
18✔
43

44
         result.confirm("EME valid_mask has expected value", valid_mask == 0x00 || valid_mask == 0xFF);
36✔
45
         result.test_eq("EME decoding valid/invalid matches", valid_mask == 0xFF, is_valid);
18✔
46

47
         if(valid_mask == 0xFF) {
18✔
48
            result.test_eq("EME decoded plaintext correct", decoded, plaintext);
14✔
49
         } else {
50
            bool all_zeros = true;
51
            for(size_t i = 0; i != decoded.size(); ++i) {
11✔
52
               if(decoded[i] != 0) {
×
53
                  all_zeros = false;
×
54
               }
55
            }
56

57
            result.confirm("On invalid padding output is all zero", all_zeros);
33✔
58
         }
59

60
         // TODO: also test that encoding is accepted
61

62
         return result;
36✔
63
      }
43✔
64
};
65

66
BOTAN_REGISTER_TEST("pubkey", "eme_pkcs1v15", EME_PKCS1v15_Decoding_Tests);
67

68
class EMSA_unit_tests final : public Test {
×
69
   public:
70
      std::vector<Test::Result> run() override {
1✔
71
         Test::Result name_tests("EMSA_name_tests");
1✔
72

73
         std::vector<std::string> pads_need_hash = {
1✔
74
   #if BOTAN_HAS_EMSA_X931
75
            "EMSA2",
76
   #endif
77
   #if BOTAN_HAS_EMSA_PKCS1
78
            "EMSA3",
79
   #endif
80
   #if BOTAN_HAS_EMSA_PSSR
81
            "EMSA4",
82
            "PSSR_Raw",
83
   #endif
84
   #if BOTAN_HAS_ISO_9796
85
            "ISO_9796_DS2",
86
            "ISO_9796_DS3",
87
   #endif
88
         };
7✔
89

90
         std::vector<std::string> pads_no_hash = {
1✔
91
   #if BOTAN_HAS_EMSA_RAW
92
            "Raw",
93
   #endif
94
   #if BOTAN_HAS_EMSA_PKCS1
95
            "EMSA3(Raw)",
96
            "EMSA3(Raw,SHA-512)",
97
   #endif
98
         };
4✔
99

100
         for(const auto& pad : pads_need_hash) {
7✔
101
            try {
6✔
102
               const std::string hash_to_use = "SHA-256";
6✔
103
               auto emsa_1 = Botan::EMSA::create(Botan::fmt("{}({})", pad, hash_to_use));
6✔
104
               auto emsa_2 = Botan::EMSA::create(emsa_1->name());
6✔
105
               name_tests.test_eq("EMSA_name_test for " + pad, emsa_1->name(), emsa_2->name());
20✔
106
            } catch(Botan::Lookup_Error&) {
12✔
107
               name_tests.test_note("Skipping test due to missing hash");
×
108
            } catch(const std::exception& e) {
×
109
               name_tests.test_failure("EMSA_name_test for " + pad + ": " + e.what());
×
110
            }
×
111
         }
112

113
         for(const auto& pad : pads_need_hash) {
7✔
114
            std::string algo_name = pad + "(YYZ)";
6✔
115
            try {
6✔
116
               auto emsa = Botan::EMSA::create_or_throw(algo_name);
6✔
117
               name_tests.test_failure("EMSA_name_test for " + pad + ": " + "Could create EMSA with fantasy hash YYZ");
×
118
            } catch(Botan::Lookup_Error&) {
6✔
119
               name_tests.test_note("Skipping test due to missing hash");
6✔
120
            } catch(const std::exception& e) {
6✔
121
               name_tests.test_eq(
×
122
                  "EMSA_name_test for " + pad, e.what(), "Could not find any algorithm named \"" + algo_name + "\"");
×
123
            }
×
124
         }
6✔
125

126
         for(const auto& pad : pads_no_hash) {
4✔
127
            try {
3✔
128
               auto emsa_1 = Botan::EMSA::create(pad);
3✔
129
               auto emsa_2 = Botan::EMSA::create(emsa_1->name());
3✔
130
               name_tests.test_eq("EMSA_name_test for " + pad, emsa_1->name(), emsa_2->name());
8✔
131
            } catch(Botan::Lookup_Error&) {
6✔
132
               name_tests.test_note("Skipping test due to missing hash");
×
133
            } catch(const std::exception& e) {
×
134
               name_tests.test_failure("EMSA_name_test for " + pad + ": " + e.what());
×
135
            }
×
136
         }
137

138
         return {name_tests};
3✔
139
      }
1✔
140
};
141

142
BOTAN_REGISTER_TEST("pubkey", "pk_pad_emsa_unit", EMSA_unit_tests);
143

144
#endif
145

146
}  // 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

© 2025 Coveralls, Inc