• 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

77.27
/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
#include <botan/exceptn.h>
9

10
#if defined(BOTAN_HAS_RSA_ENCRYPTION_PADDING)
11
   #include <botan/internal/enc_padding.h>
12
#endif
13

14
#if defined(BOTAN_HAS_RSA_SIGNATURE_PADDING)
15
   #include <botan/internal/fmt.h>
16
   #include <botan/internal/sig_padding.h>
17
#endif
18

19
namespace Botan_Tests {
20

21
namespace {
22

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

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

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

33
         auto pkcs = Botan::EncryptionPaddingScheme::create("PKCS1v15");
18✔
34
         if(!pkcs) {
18✔
35
            return result;
36
         }
37

38
         const std::vector<uint8_t> ciphertext = vars.get_req_bin("RawCiphertext");
18✔
39
         const std::vector<uint8_t> plaintext = vars.get_opt_bin("Plaintext");
18✔
40

41
         if(!is_valid) {
18✔
42
            result.test_sz_eq("Plaintext value should be empty for invalid EME inputs", plaintext.size(), 0);
11✔
43
         }
44

45
         std::vector<uint8_t> decoded(ciphertext.size());
18✔
46
         auto len = pkcs->unpad(decoded, ciphertext);
18✔
47

48
         result.test_bool_eq("EME decoding valid/invalid matches", len.has_value().as_bool(), is_valid);
18✔
49

50
         if(len.has_value().as_bool()) {
18✔
51
            decoded.resize(len.value_or(0));
7✔
52
            result.test_bin_eq("EME decoded plaintext correct", decoded, plaintext);
7✔
53
         } else {
54
            bool all_zeros = true;
55
            for(const uint8_t b : decoded) {
137✔
56
               if(b != 0) {
126✔
57
                  all_zeros = false;
×
58
               }
59
            }
60

61
            result.test_is_true("On invalid padding output is all zero", all_zeros);
11✔
62
         }
63

64
         // TODO: also test that encoding is accepted
65

66
         return result;
18✔
67
      }
61✔
68
};
69

70
BOTAN_REGISTER_TEST("pubkey", "eme_pkcs1v15", EME_PKCS1v15_Decoding_Tests);
71
#endif
72

73
#if defined(BOTAN_HAS_RSA_SIGNATURE_PADDING)
74
class SignaturePaddingSchemeNameTests final : public Test {
1✔
75
   public:
76
      std::vector<Test::Result> run() override {
1✔
77
         Test::Result result("SignaturePaddingScheme::name");
1✔
78

79
         const std::vector<std::string> pads_need_hash = {
1✔
80
   #if BOTAN_HAS_EMSA_X931
81
            "X9.31",
82
   #endif
83
   #if BOTAN_HAS_EMSA_PKCS1
84
            "PKCS1v15",
85
   #endif
86
   #if BOTAN_HAS_EMSA_PSSR
87
            "PSS",
88
            "PSS_Raw",
89
   #endif
90
   #if BOTAN_HAS_ISO_9796
91
            "ISO_9796_DS2",
92
            "ISO_9796_DS3",
93
   #endif
94
         };
1✔
95

96
         const std::vector<std::string> pads_no_hash = {
1✔
97
   #if BOTAN_HAS_EMSA_RAW
98
            "Raw",
99
   #endif
100
   #if BOTAN_HAS_EMSA_PKCS1
101
            "PKCS1v15(Raw)",
102
            "PKCS1v15(Raw,SHA-512)",
103
   #endif
104
         };
1✔
105

106
         for(const auto& pad : pads_need_hash) {
7✔
107
            try {
6✔
108
               const std::string hash_to_use = "SHA-256";
6✔
109
               auto padding = Botan::SignaturePaddingScheme::create_or_throw(Botan::fmt("{}({})", pad, hash_to_use));
6✔
110
               auto padding_copy = Botan::SignaturePaddingScheme::create(padding->name());
6✔
111
               result.test_str_eq("SignaturePaddingScheme::name for " + pad, padding->name(), padding_copy->name());
12✔
112
            } catch(Botan::Lookup_Error&) {
12✔
113
               result.test_note("Skipping test due to missing hash");
×
114
            } catch(const std::exception& e) {
×
115
               result.test_failure("SignaturePaddingScheme::name for " + pad + ": " + e.what());
×
116
            }
×
117
         }
118

119
         for(const auto& pad : pads_need_hash) {
7✔
120
            const std::string algo_name = pad + "(YYZ)";
6✔
121
            try {
6✔
122
               auto padding = Botan::SignaturePaddingScheme::create_or_throw(algo_name);
6✔
123
               result.test_failure("SignaturePaddingScheme::name for " + pad + ": " +
×
124
                                   "Could create SignaturePaddingScheme with fantasy hash YYZ");
125
            } catch(Botan::Lookup_Error&) {
6✔
126
               result.test_note("Skipping test due to missing hash");
6✔
127
            } catch(const std::exception& e) {
6✔
128
               result.test_str_eq("SignaturePaddingScheme::name for " + pad,
×
129
                                  e.what(),
×
130
                                  "Could not find any algorithm named \"" + algo_name + "\"");
×
131
            }
×
132
         }
6✔
133

134
         for(const auto& pad : pads_no_hash) {
4✔
135
            try {
3✔
136
               auto padding = Botan::SignaturePaddingScheme::create(pad);
3✔
137
               auto padding_copy = Botan::SignaturePaddingScheme::create(padding->name());
3✔
138
               result.test_str_eq("SignaturePaddingScheme::name for " + pad, padding->name(), padding_copy->name());
6✔
139
            } catch(Botan::Lookup_Error&) {
6✔
140
               result.test_note("Skipping test due to missing hash");
×
141
            } catch(const std::exception& e) {
×
142
               result.test_failure("SignaturePaddingScheme::name for " + pad + ": " + e.what());
×
143
            }
×
144
         }
145

146
         return {result};
3✔
147
      }
2✔
148
};
149

150
BOTAN_REGISTER_TEST("pubkey", "sig_padding_name", SignaturePaddingSchemeNameTests);
151

152
#endif
153

154
}  // namespace
155

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