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

randombit / botan / 5230455705

10 Jun 2023 02:30PM UTC coverage: 91.715% (-0.03%) from 91.746%
5230455705

push

github

randombit
Merge GH #3584 Change clang-format AllowShortFunctionsOnASingleLine config from All to Inline

77182 of 84154 relevant lines covered (91.72%)

11975295.43 hits per line

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

88.14
/src/lib/filters/comp_filter.cpp
1
/*
2
* Filter interface for compression
3
* (C) 2014,2015,2016 Jack Lloyd
4
* (C) 2015 Matej Kenda
5
*
6
* Botan is released under the Simplified BSD License (see license.txt)
7
*/
8

9
#include <botan/filters.h>
10

11
#include <botan/exceptn.h>
12
#include <botan/internal/fmt.h>
13

14
#if defined(BOTAN_HAS_COMPRESSION)
15
   #include <botan/compression.h>
16
#endif
17

18
namespace Botan {
19

20
#if defined(BOTAN_HAS_COMPRESSION)
21

22
Compression_Filter::Compression_Filter(std::string_view type, size_t level, size_t bs) :
2✔
23
      m_comp(Compression_Algorithm::create(type)), m_buffersize(std::max<size_t>(bs, 256)), m_level(level) {
2✔
24
   if(!m_comp) {
2✔
25
      throw Invalid_Argument(fmt("Compression type '{}' not found", type));
×
26
   }
27
}
2✔
28

29
Compression_Filter::~Compression_Filter() { /* for unique_ptr */
4✔
30
}
8✔
31

32
std::string Compression_Filter::name() const {
2✔
33
   return m_comp->name();
2✔
34
}
35

36
void Compression_Filter::start_msg() {
2✔
37
   m_comp->start(m_level);
2✔
38
}
2✔
39

40
void Compression_Filter::write(const uint8_t input[], size_t input_length) {
2✔
41
   while(input_length) {
4✔
42
      const size_t take = std::min(m_buffersize, input_length);
2✔
43
      BOTAN_ASSERT(take > 0, "Consumed something");
2✔
44

45
      m_buffer.assign(input, input + take);
2✔
46
      m_comp->update(m_buffer);
2✔
47

48
      send(m_buffer);
2✔
49

50
      input += take;
2✔
51
      input_length -= take;
2✔
52
   }
53
}
2✔
54

55
void Compression_Filter::flush() {
×
56
   m_buffer.clear();
×
57
   m_comp->update(m_buffer, 0, true);
×
58
   send(m_buffer);
×
59
}
×
60

61
void Compression_Filter::end_msg() {
2✔
62
   m_buffer.clear();
2✔
63
   m_comp->finish(m_buffer);
2✔
64
   send(m_buffer);
2✔
65
}
2✔
66

67
Decompression_Filter::Decompression_Filter(std::string_view type, size_t bs) :
2✔
68
      m_comp(Decompression_Algorithm::create(type)), m_buffersize(std::max<size_t>(bs, 256)) {
2✔
69
   if(!m_comp) {
2✔
70
      throw Invalid_Argument(fmt("Compression type '{}' not found", type));
×
71
   }
72
}
2✔
73

74
Decompression_Filter::~Decompression_Filter() { /* for unique_ptr */
4✔
75
}
8✔
76

77
std::string Decompression_Filter::name() const {
2✔
78
   return m_comp->name();
2✔
79
}
80

81
void Decompression_Filter::start_msg() {
2✔
82
   m_comp->start();
2✔
83
}
2✔
84

85
void Decompression_Filter::write(const uint8_t input[], size_t input_length) {
2✔
86
   while(input_length) {
4✔
87
      const size_t take = std::min(m_buffersize, input_length);
2✔
88
      BOTAN_ASSERT(take > 0, "Consumed something");
2✔
89

90
      m_buffer.assign(input, input + take);
2✔
91
      m_comp->update(m_buffer);
2✔
92

93
      send(m_buffer);
2✔
94

95
      input += take;
2✔
96
      input_length -= take;
2✔
97
   }
98
}
2✔
99

100
void Decompression_Filter::end_msg() {
2✔
101
   m_buffer.clear();
2✔
102
   m_comp->finish(m_buffer);
2✔
103
   send(m_buffer);
2✔
104
}
2✔
105

106
#endif
107

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