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

randombit / botan / 5123321399

30 May 2023 04:06PM UTC coverage: 92.213% (+0.004%) from 92.209%
5123321399

Pull #3558

github

web-flow
Merge dd72f7389 into 057bcbc35
Pull Request #3558: Add braces around all if/else statements

75602 of 81986 relevant lines covered (92.21%)

11859779.3 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

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 { return m_mode->name(); }
1✔
35

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

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

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

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

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

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

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

55
   m_mode->start(m_nonce);
33✔
56
   m_nonce.clear();
33✔
57
}
33✔
58

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

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

66
      send(m_buffer);
8✔
67

68
      input += take;
8✔
69
      input_length -= take;
8✔
70
   }
71
}
2✔
72

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

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

© 2025 Coveralls, Inc