• 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

84.62
/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
#if defined(BOTAN_HAS_HMAC)
19

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

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

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

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

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

38
         hmac->set_key(slurp_file(get_arg("key")));
3✔
39

40
         const size_t buf_size = get_arg_sz("buf-size");
1✔
41

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

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

53
               if(no_fsname == false)
1✔
54
                  output() << " " << fsname;
×
55

56
               output() << "\n";
1✔
57
            } catch(CLI_IO_Error& e) { error_output() << e.what() << "\n"; }
×
58
         }
59
      }
2✔
60
};
61

62
BOTAN_REGISTER_COMMAND("hmac", HMAC);
2✔
63

64
#endif  // hmac
65

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