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

randombit / botan / 13230468750

09 Feb 2025 11:07PM UTC coverage: 91.651% (-0.008%) from 91.659%
13230468750

Pull #4647

github

web-flow
Merge 8b67be1f1 into 7deaa69bb
Pull Request #4647: Avoid using mem_ops.h or assert.h in public headers

94826 of 103464 relevant lines covered (91.65%)

11402585.19 hits per line

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

87.93
/src/lib/filters/filter.cpp
1
/*
2
* Filter
3
* (C) 1999-2007 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/filter.h>
9

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

13
namespace Botan {
14

15
/*
16
* Filter Constructor
17
*/
18
Filter::Filter() {
136✔
19
   m_next.resize(1);
136✔
20
   m_port_num = 0;
136✔
21
   m_filter_owns = 0;
136✔
22
   m_owned = false;
136✔
23
}
136✔
24

25
void Filter::send(std::span<uint8_t> in, size_t length) {
89✔
26
   BOTAN_ASSERT_NOMSG(length <= in.size());
89✔
27
   send(in.data(), length);
89✔
28
}
89✔
29

30
/*
31
* Send data to all ports
32
*/
33
void Filter::send(const uint8_t input[], size_t length) {
183✔
34
   if(!length) {
183✔
35
      return;
36
   }
37

38
   bool nothing_attached = true;
39
   for(size_t j = 0; j != total_ports(); ++j) {
312✔
40
      if(m_next[j]) {
157✔
41
         if(!m_write_queue.empty()) {
157✔
42
            m_next[j]->write(m_write_queue.data(), m_write_queue.size());
×
43
         }
44
         m_next[j]->write(input, length);
157✔
45
         nothing_attached = false;
157✔
46
      }
47
   }
48

49
   if(nothing_attached) {
155✔
50
      m_write_queue += std::make_pair(input, length);
×
51
   } else {
52
      m_write_queue.clear();
155✔
53
   }
54
}
55

56
/*
57
* Start a new message
58
*/
59
void Filter::new_msg() {
207✔
60
   start_msg();
207✔
61
   for(size_t j = 0; j != total_ports(); ++j) {
349✔
62
      if(m_next[j]) {
142✔
63
         m_next[j]->new_msg();
142✔
64
      }
65
   }
66
}
207✔
67

68
/*
69
* End the current message
70
*/
71
void Filter::finish_msg() {
207✔
72
   end_msg();
207✔
73
   for(size_t j = 0; j != total_ports(); ++j) {
349✔
74
      if(m_next[j]) {
142✔
75
         m_next[j]->finish_msg();
142✔
76
      }
77
   }
78
}
207✔
79

80
/*
81
* Attach a filter to the current port
82
*/
83
void Filter::attach(Filter* new_filter) {
20✔
84
   if(new_filter) {
20✔
85
      Filter* last = this;
86
      while(last->get_next()) {
24✔
87
         last = last->get_next();
4✔
88
      }
89
      last->m_next[last->current_port()] = new_filter;
20✔
90
   }
91
}
20✔
92

93
/*
94
* Set the active port on a filter
95
*/
96
void Filter::set_port(size_t new_port) {
×
97
   if(new_port >= total_ports()) {
×
98
      throw Invalid_Argument("Filter: Invalid port number");
×
99
   }
100
   m_port_num = new_port;
×
101
}
×
102

103
/*
104
* Return the next Filter in the logical chain
105
*/
106
Filter* Filter::get_next() const {
28✔
107
   if(m_port_num < m_next.size()) {
28✔
108
      return m_next[m_port_num];
28✔
109
   }
110
   return nullptr;
111
}
112

113
/*
114
* Set the next Filters
115
*/
116
void Filter::set_next(Filter* filters[], size_t size) {
81✔
117
   m_next.clear();
81✔
118

119
   m_port_num = 0;
81✔
120
   m_filter_owns = 0;
81✔
121

122
   while(size && filters && (filters[size - 1] == nullptr)) {
87✔
123
      --size;
6✔
124
   }
125

126
   if(filters && size) {
81✔
127
      m_next.assign(filters, filters + size);
4✔
128
   }
129
}
81✔
130

131
/*
132
* Return the total number of ports
133
*/
134
size_t Filter::total_ports() const {
9,033✔
135
   return m_next.size();
9,033✔
136
}
137

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