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

randombit / botan / 5079590438

25 May 2023 12:28PM UTC coverage: 92.228% (+0.5%) from 91.723%
5079590438

Pull #3502

github

Pull Request #3502: Apply clang-format to the codebase

75589 of 81959 relevant lines covered (92.23%)

12139530.51 hits per line

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

84.29
/src/lib/utils/scan_name.cpp
1
/*
2
* SCAN Name Abstraction
3
* (C) 2008-2009,2015 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/internal/scan_name.h>
9

10
#include <botan/exceptn.h>
11
#include <botan/internal/parsing.h>
12

13
namespace Botan {
14

15
namespace {
16

17
std::string make_arg(const std::vector<std::pair<size_t, std::string>>& name, size_t start) {
218,070✔
18
   std::string output = name[start].second;
218,070✔
19
   size_t level = name[start].first;
218,070✔
20

21
   size_t paren_depth = 0;
218,070✔
22

23
   for(size_t i = start + 1; i != name.size(); ++i) {
221,190✔
24
      if(name[i].first <= name[start].first)
20,422✔
25
         break;
26

27
      if(name[i].first > level) {
3,120✔
28
         output += "(" + name[i].second;
6,104✔
29
         ++paren_depth;
3,052✔
30
      } else if(name[i].first < level) {
68✔
31
         for(size_t j = name[i].first; j < level; j++) {
×
32
            output += ")";
×
33
            --paren_depth;
×
34
         }
35
         output += "," + name[i].second;
×
36
      } else {
37
         if(output[output.size() - 1] != '(')
68✔
38
            output += ",";
68✔
39
         output += name[i].second;
68✔
40
      }
41

42
      level = name[i].first;
3,120✔
43
   }
44

45
   for(size_t i = 0; i != paren_depth; ++i)
221,122✔
46
      output += ")";
3,052✔
47

48
   return output;
218,070✔
49
}
×
50

51
}
52

53
SCAN_Name::SCAN_Name(const char* algo_spec) : SCAN_Name(std::string(algo_spec)) {}
×
54

55
SCAN_Name::SCAN_Name(std::string_view algo_spec) : m_orig_algo_spec(algo_spec), m_alg_name(), m_args(), m_mode_info() {
242,090✔
56
   if(algo_spec.empty())
242,090✔
57
      throw Invalid_Argument("Expected algorithm name, got empty string");
×
58

59
   std::vector<std::pair<size_t, std::string>> name;
242,090✔
60
   size_t level = 0;
242,090✔
61
   std::pair<size_t, std::string> accum = std::make_pair(level, "");
242,090✔
62

63
   const std::string decoding_error = "Bad SCAN name '" + m_orig_algo_spec + "': ";
242,090✔
64

65
   for(char c : algo_spec) {
3,182,555✔
66
      if(c == '/' || c == ',' || c == '(' || c == ')') {
2,940,465✔
67
         if(c == '(')
416,303✔
68
            ++level;
194,944✔
69
         else if(c == ')') {
221,359✔
70
            if(level == 0)
194,944✔
71
               throw Decoding_Error(decoding_error + "Mismatched parens");
×
72
            --level;
194,944✔
73
         }
74

75
         if(c == '/' && level > 0)
416,303✔
76
            accum.second.push_back(c);
169✔
77
         else {
78
            if(!accum.second.empty())
416,134✔
79
               name.push_back(accum);
413,470✔
80
            accum = std::make_pair(level, "");
3,356,599✔
81
         }
82
      } else
83
         accum.second.push_back(c);
2,524,162✔
84
   }
85

86
   if(!accum.second.empty())
242,090✔
87
      name.push_back(accum);
49,810✔
88

89
   if(level != 0)
242,090✔
90
      throw Decoding_Error(decoding_error + "Missing close paren");
×
91

92
   if(name.empty())
242,090✔
93
      throw Decoding_Error(decoding_error + "Empty name");
×
94

95
   m_alg_name = name[0].second;
242,090✔
96

97
   bool in_modes = false;
98

99
   for(size_t i = 1; i != name.size(); ++i) {
463,280✔
100
      if(name[i].first == 0) {
221,190✔
101
         m_mode_info.push_back(make_arg(name, i));
21,738✔
102
         in_modes = true;
10,869✔
103
      } else if(name[i].first == 1 && !in_modes)
210,321✔
104
         m_args.push_back(make_arg(name, i));
414,402✔
105
   }
106
}
246,002✔
107

108
std::string SCAN_Name::arg(size_t i) const {
173,604✔
109
   if(i >= arg_count())
173,604✔
110
      throw Invalid_Argument("SCAN_Name::arg " + std::to_string(i) + " out of range for '" + to_string() + "'");
×
111
   return m_args[i];
173,604✔
112
}
113

114
std::string SCAN_Name::arg(size_t i, std::string_view def_value) const {
7,547✔
115
   if(i >= arg_count())
7,547✔
116
      return std::string(def_value);
3,307✔
117
   return m_args[i];
4,240✔
118
}
119

120
size_t SCAN_Name::arg_as_integer(size_t i, size_t def_value) const {
134,251✔
121
   if(i >= arg_count())
134,251✔
122
      return def_value;
123
   return to_u32bit(m_args[i]);
22,005✔
124
}
125

126
size_t SCAN_Name::arg_as_integer(size_t i) const { return to_u32bit(arg(i)); }
2,992✔
127

128
}
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