• 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

88.89
/src/cli/hash.cpp
1
/*
2
* (C) 2009,2010,2014,2015,2019 Jack Lloyd
3
*
4
* Botan is released under the Simplified BSD License (see license.txt)
5
*/
6

7
#include "cli.h"
8

9
#if defined(BOTAN_HAS_HASH)
10
   #include <botan/hash.h>
11
#endif
12

13
namespace Botan_CLI {
14

15
namespace {
16

17
#if defined(BOTAN_HAS_HASH)
18

19
class Hash final : public Command {
20
   public:
21
      Hash() : Command("hash --algo=SHA-256 --buf-size=4096 --no-fsname --format=hex *files") {}
36✔
22

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

25
      std::string description() const override { return "Compute the message digest of given file(s)"; }
1✔
26

27
      void go() override {
17✔
28
         const std::string hash_algo = get_arg("algo");
17✔
29
         const std::string format = get_arg("format");
17✔
30
         const size_t buf_size = get_arg_sz("buf-size");
17✔
31
         const bool no_fsname = flag_set("no-fsname");
17✔
32

33
         auto hash_fn = Botan::HashFunction::create(hash_algo);
17✔
34

35
         if(!hash_fn) {
17✔
36
            throw CLI_Error_Unsupported("hashing", hash_algo);
×
37
         }
38

39
         std::vector<std::string> files = get_arg_list("files");
17✔
40
         if(files.empty()) {
17✔
41
            files.push_back("-");
10✔
42
         }  // read stdin if no arguments on command line
43

44
         for(const std::string& fsname : files) {
34✔
45
            try {
17✔
46
               auto update_hash = [&](const uint8_t b[], size_t l) { hash_fn->update(b, l); };
21✔
47
               read_file(fsname, update_hash, buf_size);
17✔
48

49
               const std::string digest = format_blob(format, hash_fn->final());
34✔
50

51
               if(no_fsname) {
17✔
52
                  output() << digest << "\n";
14✔
53
               } else {
54
                  output() << digest << " " << fsname << "\n";
3✔
55
               }
56
            } catch(CLI_IO_Error& e) {
17✔
57
               error_output() << e.what() << "\n";
×
58
            }
×
59
         }
60
      }
34✔
61
};
62

63
BOTAN_REGISTER_COMMAND("hash", Hash);
18✔
64

65
#endif
66

67
}  // namespace
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

© 2026 Coveralls, Inc