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

randombit / botan / 21786344715

07 Feb 2026 08:25PM UTC coverage: 90.068% (-0.005%) from 90.073%
21786344715

Pull #5295

github

web-flow
Merge 8d5fc3b23 into ebf8f0044
Pull Request #5295: Reduce header dependencies in tests and cli

102234 of 113507 relevant lines covered (90.07%)

11372278.81 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
#if defined(BOTAN_HAS_EME_PKCS1)
22
class EME_PKCS1v15_Decoding_Tests final : public Text_Based_Test {
×
23
   public:
24
      EME_PKCS1v15_Decoding_Tests() : Text_Based_Test("pk_pad_eme/pkcs1.vec", "RawCiphertext", "Plaintext") {}
2✔
25

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

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

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

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

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

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

46
         result.test_eq("EME decoding valid/invalid matches", len.has_value().as_bool(), is_valid);
18✔
47

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

59
            result.confirm("On invalid padding output is all zero", all_zeros);
22✔
60
         }
61

62
         // TODO: also test that encoding is accepted
63

64
         return result;
18✔
65
      }
61✔
66
};
67

68
BOTAN_REGISTER_TEST("pubkey", "eme_pkcs1v15", EME_PKCS1v15_Decoding_Tests);
69
#endif
70

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

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

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

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

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

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

144
         return {result};
3✔
145
      }
2✔
146
};
147

148
BOTAN_REGISTER_TEST("pubkey", "sig_padding_name", SignaturePaddingSchemeNameTests);
149

150
#endif
151

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