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

randombit / botan / 16581714815

28 Jul 2025 10:25PM UTC coverage: 90.475% (-0.2%) from 90.685%
16581714815

Pull #5021

github

web-flow
Merge 072983077 into 1eacc5b05
Pull Request #5021: Add PK_Signature_Options

99366 of 109827 relevant lines covered (90.48%)

12349417.34 hits per line

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

87.88
/src/lib/pk_pad/sig_padding/sig_padding.cpp
1
/*
2
* (C) 2015 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include <botan/internal/sig_padding.h>
8

9
#include <botan/exceptn.h>
10
#include <botan/hash.h>
11
#include <botan/internal/pk_options.h>
12
#include <botan/internal/scan_name.h>
13

14
#if defined(BOTAN_HAS_X931_SIGNATURE_PADDING)
15
   #include <botan/internal/x931_sig_padding.h>
16
#endif
17

18
#if defined(BOTAN_HAS_PKCSV15_SIGNATURE_PADDING)
19
   #include <botan/internal/pkcs1_sig_padding.h>
20
#endif
21

22
#if defined(BOTAN_HAS_PSS)
23
   #include <botan/internal/pssr.h>
24
#endif
25

26
#if defined(BOTAN_HAS_RAW_SIGNATURE_PADDING)
27
   #include <botan/internal/raw_sig_padding.h>
28
#endif
29

30
#if defined(BOTAN_HAS_ISO_9796)
31
   #include <botan/internal/iso9796.h>
32
#endif
33

34
namespace Botan {
35

36
std::unique_ptr<SignaturePaddingScheme> SignaturePaddingScheme::create_or_throw(const PK_Signature_Options& options) {
16,123✔
37
   const bool is_raw_hash = !options.using_hash() || options.hash_function_name() == "Raw";
32,048✔
38

39
   if(!options.using_padding() || options.padding() == "Raw") {
16,123✔
40
      // Only valid possibility for empty padding is no hash / "Raw" hash
41

42
#if defined(BOTAN_HAS_EMSA_RAW)
43
      if(is_raw_hash) {
203✔
44
         if(options.using_prehash()) {
200✔
45
            if(auto hash = HashFunction::create(options.prehash_fn().value())) {
×
46
               return std::make_unique<SignRawBytes>(hash->output_length());
×
47
            }
×
48
         } else {
49
            return std::make_unique<SignRawBytes>();
200✔
50
         }
51
      }
52
#endif
53
   } else {
54
      const std::string padding = options.padding().value();
15,920✔
55

56
      // null if raw_hash
57
      auto hash = [&]() -> std::unique_ptr<HashFunction> {
×
58
         if(is_raw_hash) {
15,920✔
59
            return nullptr;
12✔
60
         } else {
61
            return HashFunction::create(options.hash_function_name());
31,816✔
62
         }
63
      }();
15,920✔
64

65
#if defined(BOTAN_HAS_EMSA_PKCS1)
66
      if(padding == "PKCS1v15") {
15,920✔
67
         if(is_raw_hash) {
12,716✔
68
            return std::make_unique<PKCS1v15_Raw_SignaturePaddingScheme>(options.prehash_fn());
12✔
69
         } else if(hash) {
12,704✔
70
            return std::make_unique<PKCS1v15_SignaturePaddingScheme>(std::move(hash));
12,704✔
71
         }
72
      }
73
#endif
74

75
#if defined(BOTAN_HAS_PSS)
76
      if(padding == "PSS_Raw" && hash) {
3,204✔
77
         return std::make_unique<PSS_Raw>(std::move(hash), options.salt_size());
160✔
78
      }
79

80
      if(padding == "PSS" && hash) {
3,044✔
81
         return std::make_unique<PSSR>(std::move(hash), options.salt_size());
2,977✔
82
      }
83
#endif
84

85
#if defined(BOTAN_HAS_ISO_9796)
86
      if(padding == "ISO_9796_DS2" && hash) {
67✔
87
         return std::make_unique<ISO_9796_DS2>(
7✔
88
            std::move(hash), !options.using_explicit_trailer_field(), options.salt_size());
7✔
89
      }
90

91
      //ISO-9796-2 DS 3 is deterministic and DS2 without a salt
92
      if(padding == "ISO_9796_DS3" && hash) {
60✔
93
         return std::make_unique<ISO_9796_DS3>(std::move(hash), !options.using_explicit_trailer_field());
7✔
94
      }
95
#endif
96

97
#if defined(BOTAN_HAS_EMSA_X931)
98
      if(padding == "X9.31" && hash) {
53✔
99
         return std::make_unique<X931_SignaturePadding>(std::move(hash));
53✔
100
      }
101
#endif
102
   }
15,920✔
103

104
   throw Lookup_Error("Invalid or unavailable signature padding scheme " + options.to_string());
6✔
105
}
106

107
}  // namespace Botan
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