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

randombit / botan / 5123321399

30 May 2023 04:06PM UTC coverage: 92.213% (+0.004%) from 92.209%
5123321399

Pull #3558

github

web-flow
Merge dd72f7389 into 057bcbc35
Pull Request #3558: Add braces around all if/else statements

75602 of 81986 relevant lines covered (92.21%)

11859779.3 hits per line

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

93.55
/src/lib/pk_pad/emsa.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/emsa.h>
8

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

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

17
#if defined(BOTAN_HAS_EMSA_PKCS1)
18
   #include <botan/internal/emsa_pkcs1.h>
19
#endif
20

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

25
#if defined(BOTAN_HAS_EMSA_RAW)
26
   #include <botan/internal/emsa_raw.h>
27
#endif
28

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

33
namespace Botan {
34

35
std::unique_ptr<EMSA> EMSA::create(std::string_view algo_spec) {
11,798✔
36
   SCAN_Name req(algo_spec);
11,798✔
37

38
#if defined(BOTAN_HAS_EMSA_PKCS1)
39
   if(req.algo_name() == "EMSA_PKCS1" || req.algo_name() == "PKCS1v15" || req.algo_name() == "EMSA-PKCS1-v1_5" ||
70,237✔
40
      req.algo_name() == "EMSA3") {
31,941✔
41
      if(req.arg_count() == 2 && req.arg(0) == "Raw") {
8,759✔
42
         return std::make_unique<EMSA_PKCS1v15_Raw>(req.arg(1));
4✔
43
      } else if(req.arg_count() == 1) {
8,751✔
44
         if(req.arg(0) == "Raw") {
8,751✔
45
            return std::make_unique<EMSA_PKCS1v15_Raw>();
12✔
46
         } else {
47
            if(auto hash = HashFunction::create(req.arg(0))) {
17,478✔
48
               return std::make_unique<EMSA_PKCS1v15>(std::move(hash));
8,738✔
49
            }
8,739✔
50
         }
51
      }
52
   }
53
#endif
54

55
#if defined(BOTAN_HAS_EMSA_PSSR)
56
   if(req.algo_name() == "PSS_Raw" || req.algo_name() == "PSSR_Raw") {
12,176✔
57
      if(req.arg_count_between(1, 3) && req.arg(1, "MGF1") == "MGF1") {
489✔
58
         if(auto hash = HashFunction::create(req.arg(0))) {
326✔
59
            if(req.arg_count() == 3) {
162✔
60
               const size_t salt_size = req.arg_as_integer(2, 0);
161✔
61
               return std::make_unique<PSSR_Raw>(std::move(hash), salt_size);
161✔
62
            } else {
63
               return std::make_unique<PSSR_Raw>(std::move(hash));
1✔
64
            }
65
         }
163✔
66
      }
67
   }
68

69
   if(req.algo_name() == "PSS" || req.algo_name() == "PSSR" || req.algo_name() == "EMSA-PSS" ||
9,602✔
70
      req.algo_name() == "PSS-MGF1" || req.algo_name() == "EMSA4") {
12,380✔
71
      if(req.arg_count_between(1, 3) && req.arg(1, "MGF1") == "MGF1") {
8,396✔
72
         if(auto hash = HashFunction::create(req.arg(0))) {
5,596✔
73
            if(req.arg_count() == 3) {
2,797✔
74
               const size_t salt_size = req.arg_as_integer(2, 0);
2,342✔
75
               return std::make_unique<PSSR>(std::move(hash), salt_size);
2,342✔
76
            } else {
77
               return std::make_unique<PSSR>(std::move(hash));
455✔
78
            }
79
         }
2,798✔
80
      }
81
   }
82
#endif
83

84
#if defined(BOTAN_HAS_ISO_9796)
85
   if(req.algo_name() == "ISO_9796_DS2") {
170✔
86
      if(req.arg_count_between(1, 3)) {
9✔
87
         if(auto hash = HashFunction::create(req.arg(0))) {
18✔
88
            const size_t salt_size = req.arg_as_integer(2, hash->output_length());
8✔
89
            const bool implicit = req.arg(1, "exp") == "imp";
8✔
90
            return std::make_unique<ISO_9796_DS2>(std::move(hash), implicit, salt_size);
8✔
91
         }
9✔
92
      }
93
   }
94
   //ISO-9796-2 DS 3 is deterministic and DS2 without a salt
95
   if(req.algo_name() == "ISO_9796_DS3") {
154✔
96
      if(req.arg_count_between(1, 2)) {
9✔
97
         if(auto hash = HashFunction::create(req.arg(0))) {
18✔
98
            const bool implicit = req.arg(1, "exp") == "imp";
8✔
99
            return std::make_unique<ISO_9796_DS3>(std::move(hash), implicit);
8✔
100
         }
9✔
101
      }
102
   }
103
#endif
104

105
#if defined(BOTAN_HAS_EMSA_X931)
106
   if(req.algo_name() == "EMSA_X931" || req.algo_name() == "EMSA2" || req.algo_name() == "X9.31") {
304✔
107
      if(req.arg_count() == 1) {
55✔
108
         if(auto hash = HashFunction::create(req.arg(0))) {
110✔
109
            return std::make_unique<EMSA_X931>(std::move(hash));
54✔
110
         }
55✔
111
      }
112
   }
113
#endif
114

115
#if defined(BOTAN_HAS_EMSA_RAW)
116
   if(req.algo_name() == "Raw") {
30✔
117
      if(req.arg_count() == 0) {
7✔
118
         return std::make_unique<EMSA_Raw>();
7✔
119
      } else {
120
         auto hash = HashFunction::create(req.arg(0));
×
121
         if(hash) {
×
122
            return std::make_unique<EMSA_Raw>(hash->output_length());
×
123
         }
124
      }
×
125
   }
126
#endif
127

128
   return nullptr;
8✔
129
}
11,798✔
130

131
std::unique_ptr<EMSA> EMSA::create_or_throw(std::string_view algo_spec) {
11,780✔
132
   auto emsa = EMSA::create(algo_spec);
11,780✔
133
   if(emsa) {
11,780✔
134
      return emsa;
11,772✔
135
   }
136
   throw Algorithm_Not_Found(algo_spec);
8✔
137
}
8✔
138

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