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

randombit / botan / 5134090420

31 May 2023 03:12PM UTC coverage: 91.721% (-0.3%) from 91.995%
5134090420

push

github

randombit
Merge GH #3565 Disable noisy/pointless pylint warnings

76048 of 82912 relevant lines covered (91.72%)

11755290.1 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
#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

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

65
BOTAN_REGISTER_COMMAND("hmac", HMAC);
2✔
66

67
#endif  // hmac
68

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

© 2025 Coveralls, Inc