• 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

86.79
/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/internal/out_buf.h>
13

14
namespace Botan {
15

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

25
   if(msg >= message_count())
194✔
26
      throw Invalid_Message_Number(func_name, msg);
1✔
27

28
   return msg;
193✔
29
}
30

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

40
/*
41
* Write a string into a Pipe
42
*/
43
void Pipe::write(std::string_view str) { write(cast_char_ptr_to_uint8(str.data()), str.size()); }
2✔
44

45
/*
46
* Write a single byte into a Pipe
47
*/
48
void Pipe::write(uint8_t input) { write(&input, 1); }
1✔
49

50
/*
51
* Write the contents of a DataSource into a Pipe
52
*/
53
void Pipe::write(DataSource& source) {
5✔
54
   secure_vector<uint8_t> buffer(BOTAN_DEFAULT_BUFFER_SIZE);
5✔
55
   while(!source.end_of_data()) {
10✔
56
      size_t got = source.read(buffer.data(), buffer.size());
5✔
57
      write(buffer.data(), got);
5✔
58
   }
59
}
5✔
60

61
/*
62
* Read some data from the pipe
63
*/
64
size_t Pipe::read(uint8_t output[], size_t length, message_id msg) {
117✔
65
   return m_outputs->read(output, length, get_message_no("read", msg));
117✔
66
}
67

68
/*
69
* Read some data from the pipe
70
*/
71
size_t Pipe::read(uint8_t output[], size_t length) { return read(output, length, DEFAULT_MESSAGE); }
7✔
72

73
/*
74
* Read a single byte from the pipe
75
*/
76
size_t Pipe::read(uint8_t& out, message_id msg) { return read(&out, 1, msg); }
×
77

78
/*
79
* Return all data in the pipe
80
*/
81
secure_vector<uint8_t> Pipe::read_all(message_id msg) {
17✔
82
   msg = ((msg != DEFAULT_MESSAGE) ? msg : default_msg());
17✔
83
   secure_vector<uint8_t> buffer(remaining(msg));
17✔
84
   size_t got = read(buffer.data(), buffer.size(), msg);
17✔
85
   buffer.resize(got);
17✔
86
   return buffer;
17✔
87
}
×
88

89
/*
90
* Return all data in the pipe as a string
91
*/
92
std::string Pipe::read_all_as_string(message_id msg) {
46✔
93
   msg = ((msg != DEFAULT_MESSAGE) ? msg : default_msg());
46✔
94
   secure_vector<uint8_t> buffer(BOTAN_DEFAULT_BUFFER_SIZE);
46✔
95
   std::string str;
46✔
96
   str.reserve(remaining(msg));
46✔
97

98
   while(true) {
92✔
99
      size_t got = read(buffer.data(), buffer.size(), msg);
92✔
100
      if(got == 0)
92✔
101
         break;
102
      str.append(cast_uint8_ptr_to_char(buffer.data()), got);
46✔
103
   }
104

105
   return str;
46✔
106
}
46✔
107

108
/*
109
* Find out how many bytes are ready to read
110
*/
111
size_t Pipe::remaining(message_id msg) const { return m_outputs->remaining(get_message_no("remaining", msg)); }
76✔
112

113
/*
114
* Peek at some data in the pipe
115
*/
116
size_t Pipe::peek(uint8_t output[], size_t length, size_t offset, message_id msg) const {
1✔
117
   return m_outputs->peek(output, length, offset, get_message_no("peek", msg));
1✔
118
}
119

120
/*
121
* Peek at some data in the pipe
122
*/
123
size_t Pipe::peek(uint8_t output[], size_t length, size_t offset) const {
1✔
124
   return peek(output, length, offset, DEFAULT_MESSAGE);
1✔
125
}
126

127
/*
128
* Peek at a byte in the pipe
129
*/
130
size_t Pipe::peek(uint8_t& out, size_t offset, message_id msg) const { return peek(&out, 1, offset, msg); }
×
131

132
size_t Pipe::get_bytes_read() const { return m_outputs->get_bytes_read(default_msg()); }
4✔
133

134
size_t Pipe::get_bytes_read(message_id msg) const { return m_outputs->get_bytes_read(msg); }
4✔
135

136
bool Pipe::check_available(size_t n) { return (n <= remaining(default_msg())); }
×
137

138
bool Pipe::check_available_msg(size_t n, message_id msg) const { return (n <= remaining(msg)); }
×
139

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