• 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

92.31
/src/cli/bcrypt.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_BCRYPT)
10
   #include <botan/bcrypt.h>
11
#endif
12

13
namespace Botan_CLI {
14

15
namespace {
16

17
#if defined(BOTAN_HAS_BCRYPT)
18

19
class Generate_Bcrypt final : public Command {
20
   public:
21
      Generate_Bcrypt() : Command("gen_bcrypt --work-factor=12 password") {}
4✔
22

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

25
      std::string description() const override { return "Calculate bcrypt password hash"; }
1✔
26

27
      void go() override {
1✔
28
         const std::string password = get_passphrase_arg("Passphrase to hash", "password");
2✔
29
         const size_t wf = get_arg_sz("work-factor");
1✔
30

31
         if(wf < 4 || wf > 18) {
1✔
32
            error_output() << "Invalid bcrypt work factor\n";
×
33
         } else {
34
            const uint16_t wf16 = static_cast<uint16_t>(wf);
1✔
35
            output() << Botan::generate_bcrypt(password, rng(), wf16) << "\n";
3✔
36
         }
37
      }
1✔
38
};
39

40
BOTAN_REGISTER_COMMAND("gen_bcrypt", Generate_Bcrypt);
2✔
41

42
class Check_Bcrypt final : public Command {
43
   public:
44
      Check_Bcrypt() : Command("check_bcrypt password hash") {}
6✔
45

46
      std::string group() const override { return "passhash"; }
1✔
47

48
      std::string description() const override { return "Verify bcrypt password hash"; }
1✔
49

50
      void go() override {
2✔
51
         const std::string password = get_passphrase_arg("Password to check", "password");
4✔
52
         const std::string hash = get_arg("hash");
2✔
53

54
         if(hash.length() != 60) {
2✔
55
            error_output() << "Note: bcrypt '" << hash << "' has wrong length and cannot be valid\n";
×
56
         }
57

58
         const bool ok = Botan::check_bcrypt(password, hash);
2✔
59

60
         output() << "Password is " << (ok ? "valid" : "NOT valid") << "\n";
3✔
61

62
         if(!ok) {
2✔
63
            set_return_code(1);
1✔
64
         }
65
      }
2✔
66
};
67

68
BOTAN_REGISTER_COMMAND("check_bcrypt", Check_Bcrypt);
3✔
69

70
#endif  // bcrypt
71

72
}  // namespace
73

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