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

randombit / botan / 23111636944

15 Mar 2026 01:45PM UTC coverage: 89.732% (+0.002%) from 89.73%
23111636944

Pull #5446

github

web-flow
Merge 75b20e42b into e9952d62f
Pull Request #5446: Address (or silence) various new warnings from clang-tidy 22

104217 of 116142 relevant lines covered (89.73%)

11426748.42 hits per line

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

78.57
/src/cli/hmac.cpp
1
/*
2
* (C) 2009,2010,2014,2015 Jack Lloyd
3
* (C) 2017 René Korthaus, Rohde & Schwarz Cybersecurity
4
*
5
* Botan is released under the Simplified BSD License (see license.txt)
6
*/
7

8
#include "cli.h"
9

10
#include <botan/hex.h>
11

12
#if defined(BOTAN_HAS_MAC)
13
   #include <botan/mac.h>
14
#endif
15

16
namespace Botan_CLI {
17

18
namespace {
19

20
#if defined(BOTAN_HAS_HMAC)
21

22
class HMAC final : public Command {
23
   public:
24
      HMAC() : Command("hmac --hash=SHA-256 --buf-size=4096 --no-fsname key *files") {}
4✔
25

26
      std::string group() const override { return "hmac"; }
1✔
27

28
      std::string description() const override { return "Compute the HMAC tag of given file(s)"; }
1✔
29

30
      void go() override {
1✔
31
         const bool no_fsname = flag_set("no-fsname");
1✔
32
         const std::string hash_algo = get_arg("hash");
1✔
33
         std::unique_ptr<Botan::MessageAuthenticationCode> hmac =
1✔
34
            Botan::MessageAuthenticationCode::create("HMAC(" + hash_algo + ")");
3✔
35

36
         if(!hmac) {
1✔
37
            throw CLI_Error_Unsupported("HMAC", hash_algo);
×
38
         }
39

40
         hmac->set_key(slurp_file(get_arg("key")));
2✔
41

42
         const size_t buf_size = get_arg_sz("buf-size");
1✔
43

44
         std::vector<std::string> files = get_arg_list("files");
1✔
45
         if(files.empty()) {
1✔
46
            files.push_back("-");
×
47
         }  // read stdin if no arguments on command line
48

49
         for(const std::string& fsname : files) {
2✔
50
            try {
1✔
51
               auto update_hmac = [&](const uint8_t b[], size_t l) { hmac->update(b, l); };
1✔
52
               read_file(fsname, update_hmac, buf_size);
1✔
53
               output() << Botan::hex_encode(hmac->final());
1✔
54

55
               if(!no_fsname) {
1✔
56
                  output() << " " << fsname;
×
57
               }
58

59
               output() << "\n";
1✔
60
            } catch(CLI_IO_Error& e) {
×
61
               error_output() << e.what() << "\n";
×
62
            }
×
63
         }
64
      }
2✔
65
};
66

67
BOTAN_REGISTER_COMMAND("hmac", HMAC);
2✔
68

69
#endif  // hmac
70

71
}  // namespace
72

73
}  // namespace Botan_CLI
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