• 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

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

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

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

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

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

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

38
BOTAN_REGISTER_COMMAND("gen_bcrypt", Generate_Bcrypt);
2✔
39

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

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

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

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

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

56
         const bool ok = Botan::check_bcrypt(password, hash);
2✔
57

58
         output() << "Password is " << (ok ? "valid" : "NOT valid") << std::endl;
3✔
59

60
         if(ok == false)
2✔
61
            set_return_code(1);
2✔
62
      }
2✔
63
};
64

65
BOTAN_REGISTER_COMMAND("check_bcrypt", Check_Bcrypt);
3✔
66

67
#endif  // bcrypt
68

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