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

randombit / botan / 23225340130

18 Mar 2026 01:53AM UTC coverage: 89.677% (-0.001%) from 89.678%
23225340130

push

github

web-flow
Merge pull request #5456 from randombit/jack/clang-tidy-22

Fix various warnings from clang-tidy 22

104438 of 116460 relevant lines covered (89.68%)

11819947.55 hits per line

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

93.1
/src/cli/cipher.cpp
1
/*
2
* (C) 2015,2017 Simon Warta (Kullo GmbH)
3
* (C) 2020 Jack Lloyd
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include "cli.h"
9

10
#if defined(BOTAN_HAS_CIPHER_MODES)
11

12
   #include <botan/cipher_mode.h>
13
   #include <botan/hex.h>
14
   #include <botan/symkey.h>
15

16
   #if defined(BOTAN_HAS_AEAD_MODES)
17
      #include <botan/aead.h>
18
   #endif
19

20
namespace Botan_CLI {
21

22
namespace {
23

24
class Cipher final : public Command {
25
   public:
26
      Cipher() : Command("cipher --cipher=AES-256/GCM --decrypt --key= --nonce= --ad= --buf-size=4096 input-file") {}
2,786✔
27

28
      std::string group() const override { return "crypto"; }
1✔
29

30
      std::string description() const override { return "Encrypt or decrypt with a symmetric cipher"; }
1✔
31

32
      void go() override {
1,392✔
33
         const std::string cipher_algo = get_arg_or("cipher", "");
2,784✔
34
         const std::string key_hex = get_arg("key");
1,392✔
35
         const std::string nonce_hex = get_arg("nonce");
1,392✔
36
         const std::string ad_hex = get_arg_or("ad", "");
2,784✔
37
         const std::string input_file = get_arg_or("input-file", "-");
2,784✔
38
         const size_t buf_size = get_arg_sz("buf-size");
1,392✔
39

40
         const Botan::SymmetricKey key(key_hex);
1,392✔
41
         const Botan::InitializationVector nonce(nonce_hex);
1,392✔
42
         const std::vector<uint8_t> ad = Botan::hex_decode(ad_hex);
1,392✔
43

44
         auto direction = flag_set("decrypt") ? Botan::Cipher_Dir::Decryption : Botan::Cipher_Dir::Encryption;
2,088✔
45

46
         auto cipher = Botan::Cipher_Mode::create(cipher_algo, direction);
1,392✔
47
         if(!cipher) {
1,392✔
48
            throw CLI_Error_Unsupported("Cipher algorithm '" + cipher_algo + "' not available");
×
49
         }
50

51
         // Set key
52
         cipher->set_key(key);
1,392✔
53

54
         // Set associated data
55
         if(!ad.empty()) {
1,392✔
56
   #if defined(BOTAN_HAS_AEAD_MODES)
57
            if(Botan::AEAD_Mode* aead = dynamic_cast<Botan::AEAD_Mode*>(cipher.get())) {
388✔
58
               aead->set_associated_data(ad);
388✔
59
            } else
60
   #endif
61
            {
62
               throw CLI_Usage_Error("Cannot specify associated data with non-AEAD mode");
×
63
            }
64
         }
65

66
         // Set nonce
67
         cipher->start(nonce.bits_of());
1,392✔
68

69
         const std::vector<uint8_t> input = this->slurp_file(input_file, buf_size);
1,392✔
70

71
         Botan::secure_vector<uint8_t> buf(input.begin(), input.end());
1,392✔
72
         cipher->finish(buf);
1,392✔
73

74
         write_output(buf);
1,392✔
75
      }
8,300✔
76
};
77

78
BOTAN_REGISTER_COMMAND("cipher", Cipher);
1,393✔
79

80
}  // namespace
81

82
}  // namespace Botan_CLI
83

84
#endif
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