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

randombit / botan / 6704830136

31 Oct 2023 09:55AM UTC coverage: 91.722% (+0.001%) from 91.721%
6704830136

push

github

web-flow
Merge pull request #3752 from randombit/jack/allocator-helper

Split out allocator helpers to allocator.h

80150 of 87384 relevant lines covered (91.72%)

8593301.14 hits per line

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

83.08
/src/lib/filters/pipe_rw.cpp
1
/*
2
* Pipe Reading/Writing
3
* (C) 1999-2007 Jack Lloyd
4
*     2012 Markus Wanner
5
*
6
* Botan is released under the Simplified BSD License (see license.txt)
7
*/
8

9
#include <botan/pipe.h>
10

11
#include <botan/filter.h>
12
#include <botan/mem_ops.h>
13
#include <botan/internal/out_buf.h>
14

15
namespace Botan {
16

17
/*
18
* Look up the canonical ID for a queue
19
*/
20
Pipe::message_id Pipe::get_message_no(std::string_view func_name, message_id msg) const {
194✔
21
   if(msg == DEFAULT_MESSAGE) {
194✔
22
      msg = default_msg();
20✔
23
   } else if(msg == LAST_MESSAGE) {
174✔
24
      msg = message_count() - 1;
×
25
   }
26

27
   if(msg >= message_count()) {
194✔
28
      throw Invalid_Message_Number(func_name, msg);
1✔
29
   }
30

31
   return msg;
193✔
32
}
33

34
/*
35
* Write into a Pipe
36
*/
37
void Pipe::write(const uint8_t input[], size_t length) {
984✔
38
   if(!m_inside_msg) {
984✔
39
      throw Invalid_State("Cannot write to a Pipe while it is not processing");
×
40
   }
41
   m_pipe->write(input, length);
984✔
42
}
984✔
43

44
/*
45
* Write a string into a Pipe
46
*/
47
void Pipe::write(std::string_view str) {
2✔
48
   write(cast_char_ptr_to_uint8(str.data()), str.size());
2✔
49
}
2✔
50

51
/*
52
* Write a single byte into a Pipe
53
*/
54
void Pipe::write(uint8_t input) {
1✔
55
   write(&input, 1);
1✔
56
}
1✔
57

58
/*
59
* Write the contents of a DataSource into a Pipe
60
*/
61
void Pipe::write(DataSource& source) {
5✔
62
   secure_vector<uint8_t> buffer(BOTAN_DEFAULT_BUFFER_SIZE);
5✔
63
   while(!source.end_of_data()) {
10✔
64
      size_t got = source.read(buffer.data(), buffer.size());
5✔
65
      write(buffer.data(), got);
5✔
66
   }
67
}
5✔
68

69
/*
70
* Read some data from the pipe
71
*/
72
size_t Pipe::read(uint8_t output[], size_t length, message_id msg) {
117✔
73
   return m_outputs->read(output, length, get_message_no("read", msg));
117✔
74
}
75

76
/*
77
* Read some data from the pipe
78
*/
79
size_t Pipe::read(uint8_t output[], size_t length) {
7✔
80
   return read(output, length, DEFAULT_MESSAGE);
7✔
81
}
82

83
/*
84
* Read a single byte from the pipe
85
*/
86
size_t Pipe::read(uint8_t& out, message_id msg) {
×
87
   return read(&out, 1, msg);
×
88
}
89

90
/*
91
* Return all data in the pipe
92
*/
93
secure_vector<uint8_t> Pipe::read_all(message_id msg) {
17✔
94
   msg = ((msg != DEFAULT_MESSAGE) ? msg : default_msg());
17✔
95
   secure_vector<uint8_t> buffer(remaining(msg));
17✔
96
   size_t got = read(buffer.data(), buffer.size(), msg);
17✔
97
   buffer.resize(got);
17✔
98
   return buffer;
17✔
99
}
×
100

101
/*
102
* Return all data in the pipe as a string
103
*/
104
std::string Pipe::read_all_as_string(message_id msg) {
46✔
105
   msg = ((msg != DEFAULT_MESSAGE) ? msg : default_msg());
46✔
106
   secure_vector<uint8_t> buffer(BOTAN_DEFAULT_BUFFER_SIZE);
46✔
107
   std::string str;
46✔
108
   str.reserve(remaining(msg));
46✔
109

110
   while(true) {
92✔
111
      size_t got = read(buffer.data(), buffer.size(), msg);
92✔
112
      if(got == 0) {
92✔
113
         break;
114
      }
115
      str.append(cast_uint8_ptr_to_char(buffer.data()), got);
46✔
116
   }
117

118
   return str;
46✔
119
}
46✔
120

121
/*
122
* Find out how many bytes are ready to read
123
*/
124
size_t Pipe::remaining(message_id msg) const {
76✔
125
   return m_outputs->remaining(get_message_no("remaining", msg));
76✔
126
}
127

128
/*
129
* Peek at some data in the pipe
130
*/
131
size_t Pipe::peek(uint8_t output[], size_t length, size_t offset, message_id msg) const {
1✔
132
   return m_outputs->peek(output, length, offset, get_message_no("peek", msg));
1✔
133
}
134

135
/*
136
* Peek at some data in the pipe
137
*/
138
size_t Pipe::peek(uint8_t output[], size_t length, size_t offset) const {
1✔
139
   return peek(output, length, offset, DEFAULT_MESSAGE);
1✔
140
}
141

142
/*
143
* Peek at a byte in the pipe
144
*/
145
size_t Pipe::peek(uint8_t& out, size_t offset, message_id msg) const {
×
146
   return peek(&out, 1, offset, msg);
×
147
}
148

149
size_t Pipe::get_bytes_read() const {
4✔
150
   return m_outputs->get_bytes_read(default_msg());
4✔
151
}
152

153
size_t Pipe::get_bytes_read(message_id msg) const {
4✔
154
   return m_outputs->get_bytes_read(msg);
4✔
155
}
156

157
bool Pipe::check_available(size_t n) {
×
158
   return (n <= remaining(default_msg()));
×
159
}
160

161
bool Pipe::check_available_msg(size_t n, message_id msg) const {
×
162
   return (n <= remaining(msg));
×
163
}
164

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