• 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

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
#if defined(BOTAN_HAS_HASH)
16

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

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

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

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

31
         auto hash_fn = Botan::HashFunction::create(hash_algo);
22✔
32

33
         if(!hash_fn) {
22✔
34
            throw CLI_Error_Unsupported("hashing", hash_algo);
×
35
         }
36

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

42
         for(const std::string& fsname : files) {
44✔
43
            try {
22✔
44
               auto update_hash = [&](const uint8_t b[], size_t l) { hash_fn->update(b, l); };
30✔
45
               read_file(fsname, update_hash, buf_size);
22✔
46

47
               const std::string digest = format_blob(format, hash_fn->final());
44✔
48

49
               if(no_fsname) {
22✔
50
                  output() << digest << "\n";
19✔
51
               } else {
52
                  output() << digest << " " << fsname << "\n";
3✔
53
               }
54
            } catch(CLI_IO_Error& e) {
22✔
55
               error_output() << e.what() << "\n";
×
56
            }
×
57
         }
58
      }
44✔
59
};
60

61
BOTAN_REGISTER_COMMAND("hash", Hash);
23✔
62

63
#endif
64

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