• 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

97.87
/src/lib/filters/cipher_filter.cpp
1
/*
2
* Filter interface for Cipher_Modes
3
* (C) 2013,2014,2017 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include <botan/filters.h>
9

10
#include <botan/internal/rounding.h>
11

12
namespace Botan {
13

14
namespace {
15

16
size_t choose_update_size(size_t update_granularity) {
4✔
17
   const size_t target_size = 1024;
4✔
18

19
   if(update_granularity >= target_size) {
4✔
20
      return update_granularity;
21
   }
22

23
   return round_up(target_size, update_granularity);
4✔
24
}
25

26
}  // namespace
27

28
Cipher_Mode_Filter::Cipher_Mode_Filter(Cipher_Mode* mode) :
4✔
29
      Buffered_Filter(choose_update_size(mode->ideal_granularity()), mode->minimum_final_size()),
8✔
30
      m_mode(mode),
4✔
31
      m_nonce(mode->default_nonce_length()),
4✔
32
      m_buffer(m_mode->ideal_granularity()) {}
8✔
33

34
std::string Cipher_Mode_Filter::name() const {
1✔
35
   return m_mode->name();
1✔
36
}
37

38
void Cipher_Mode_Filter::set_iv(const InitializationVector& iv) {
5✔
39
   m_nonce = unlock(iv.bits_of());
5✔
40
}
5✔
41

42
void Cipher_Mode_Filter::set_key(const SymmetricKey& key) {
4✔
43
   m_mode->set_key(key);
4✔
44
}
4✔
45

46
Key_Length_Specification Cipher_Mode_Filter::key_spec() const {
2✔
47
   return m_mode->key_spec();
2✔
48
}
49

50
bool Cipher_Mode_Filter::valid_iv_length(size_t length) const {
2✔
51
   return m_mode->valid_nonce_length(length);
2✔
52
}
53

54
void Cipher_Mode_Filter::write(const uint8_t input[], size_t input_length) {
37✔
55
   Buffered_Filter::write(input, input_length);
37✔
56
}
37✔
57

58
void Cipher_Mode_Filter::end_msg() {
33✔
59
   Buffered_Filter::end_msg();
33✔
60
}
33✔
61

62
void Cipher_Mode_Filter::start_msg() {
33✔
63
   if(m_nonce.empty() && !m_mode->valid_nonce_length(0)) {
33✔
64
      throw Invalid_State("Cipher " + m_mode->name() + " requires a fresh nonce for each message");
×
65
   }
66

67
   m_mode->start(m_nonce);
33✔
68
   m_nonce.clear();
33✔
69
}
33✔
70

71
void Cipher_Mode_Filter::buffered_block(const uint8_t input[], size_t input_length) {
2✔
72
   while(input_length) {
10✔
73
      const size_t take = std::min(m_mode->ideal_granularity(), input_length);
8✔
74

75
      m_buffer.assign(input, input + take);
8✔
76
      m_mode->update(m_buffer);
8✔
77

78
      send(m_buffer);
8✔
79

80
      input += take;
8✔
81
      input_length -= take;
8✔
82
   }
83
}
2✔
84

85
void Cipher_Mode_Filter::buffered_final(const uint8_t input[], size_t input_length) {
33✔
86
   secure_vector<uint8_t> buf(input, input + input_length);
33✔
87
   m_mode->finish(buf);
33✔
88
   send(buf);
66✔
89
}
33✔
90

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