• 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

97.37
/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
   return round_up(target_size, update_granularity);
4✔
23
}
24

25
}
26

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

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

35
void Cipher_Mode_Filter::set_iv(const InitializationVector& iv) { m_nonce = unlock(iv.bits_of()); }
10✔
36

37
void Cipher_Mode_Filter::set_key(const SymmetricKey& key) { m_mode->set_key(key); }
4✔
38

39
Key_Length_Specification Cipher_Mode_Filter::key_spec() const { return m_mode->key_spec(); }
2✔
40

41
bool Cipher_Mode_Filter::valid_iv_length(size_t length) const { return m_mode->valid_nonce_length(length); }
2✔
42

43
void Cipher_Mode_Filter::write(const uint8_t input[], size_t input_length) {
37✔
44
   Buffered_Filter::write(input, input_length);
37✔
45
}
37✔
46

47
void Cipher_Mode_Filter::end_msg() { Buffered_Filter::end_msg(); }
33✔
48

49
void Cipher_Mode_Filter::start_msg() {
33✔
50
   if(m_nonce.empty() && !m_mode->valid_nonce_length(0))
33✔
51
      throw Invalid_State("Cipher " + m_mode->name() + " requires a fresh nonce for each message");
×
52

53
   m_mode->start(m_nonce);
33✔
54
   m_nonce.clear();
33✔
55
}
33✔
56

57
void Cipher_Mode_Filter::buffered_block(const uint8_t input[], size_t input_length) {
2✔
58
   while(input_length) {
10✔
59
      const size_t take = std::min(m_mode->ideal_granularity(), input_length);
8✔
60

61
      m_buffer.assign(input, input + take);
8✔
62
      m_mode->update(m_buffer);
8✔
63

64
      send(m_buffer);
8✔
65

66
      input += take;
8✔
67
      input_length -= take;
8✔
68
   }
69
}
2✔
70

71
void Cipher_Mode_Filter::buffered_final(const uint8_t input[], size_t input_length) {
33✔
72
   secure_vector<uint8_t> buf(input, input + input_length);
33✔
73
   m_mode->finish(buf);
33✔
74
   send(buf);
66✔
75
}
33✔
76

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