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

randombit / botan / 39195077976

18 Oct 2026 05:18PM UTC coverage: 92.258% (+0.06%) from 92.195%
39195077976

push

github

randombit
Update release notes [ci skip]

137358 of 148884 relevant lines covered (92.26%)

8967647.39 hits per line

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

90.32
/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") {}
6 ✔
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 {
2 ✔
31
         const bool no_fsname = flag_set("no-fsname");
2 ✔
32
         const std::string hash_algo = get_arg("hash");
2 ✔
33
         std::unique_ptr<Botan::MessageAuthenticationCode> hmac =
2 ✔
34
            Botan::MessageAuthenticationCode::create("HMAC(" + hash_algo + ")");
6 ✔
35

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

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

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

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

49
         for(const std::string& fsname : files) {
5 ✔
50
            try {
3 ✔
51
               const auto update_hmac = [&](const uint8_t b[], size_t l) { hmac->update(b, l); };
2 ✔
52
               read_file(fsname, update_hmac, buf_size);
4 ✔
53
            } catch(CLI_IO_Error& e) {
1 ✔
54
               error_output() << e.what() << "\n";
1 ✔
55
               set_return_code(1);
1 ✔
56
               hmac->final();  // discard any partial input
1 ✔
57
               continue;
1 ✔
58
            }
1 ✔
59

60
            output() << Botan::hex_encode(hmac->final());
2 ✔
61

62
            if(!no_fsname) {
2 ✔
63
               output() << " " << fsname;
×
64
            }
65

66
            output() << "\n";
2 ✔
67
         }
68
      }
4 ✔
69
};
70

71
BOTAN_REGISTER_COMMAND("hmac", HMAC);
3 ✔
72

73
#endif  // hmac
74

75
}  // namespace
76

77
}  // namespace Botan_CLI
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc