diff options
author | lloyd <[email protected]> | 2014-01-01 21:49:13 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2014-01-01 21:49:13 +0000 |
commit | ba238d04531a4e76ed88635871fd82e5459b3cc4 (patch) | |
tree | 5de580b3b43b68c93dc3f5268538066d3c75c2aa | |
parent | 9f9811125846fb7fce6bec8c8439894bd43e6ace (diff) |
Move bcrypt example to run from test app
-rw-r--r-- | doc/examples/bcrypt.cpp | 38 | ||||
-rw-r--r-- | src/examples/bcrypt.cpp | 32 | ||||
-rw-r--r-- | src/examples/examples.h | 9 | ||||
-rw-r--r-- | src/main.cpp | 8 |
4 files changed, 48 insertions, 39 deletions
diff --git a/doc/examples/bcrypt.cpp b/doc/examples/bcrypt.cpp deleted file mode 100644 index 4154b26ad..000000000 --- a/doc/examples/bcrypt.cpp +++ /dev/null @@ -1,38 +0,0 @@ -#include <botan/botan.h> -#include <botan/bcrypt.h> -#include <iostream> - -using namespace Botan; - -int main(int argc, char* argv[]) - { - if(argc != 2 && argc != 3) - { - std::cout << "Usage: " << argv[0] << " password\n" - << " " << argv[0] << " password passhash\n"; - return 1; - } - - LibraryInitializer init; - - if(argc == 2) - { - AutoSeeded_RNG rng; - - std::cout << generate_bcrypt(argv[1], rng, 12) << "\n"; - } - else if(argc == 3) - { - if(strlen(argv[2]) != 60) - { - std::cout << "Note: hash " << argv[2] - << " has wrong length and cannot be valid\n"; - } - - const bool ok = check_bcrypt(argv[1], argv[2]); - - std::cout << "Password is " << (ok ? "valid" : "NOT valid") << "\n"; - } - - return 0; - } diff --git a/src/examples/bcrypt.cpp b/src/examples/bcrypt.cpp new file mode 100644 index 000000000..50205cd4d --- /dev/null +++ b/src/examples/bcrypt.cpp @@ -0,0 +1,32 @@ +#include "examples.h" +#include <botan/bcrypt.h> + +int bcrypt_example(int argc, char* argv[]) + { + if(argc == 2) + { + AutoSeeded_RNG rng; + + const std::string password = argv[1]; + + std::cout << generate_bcrypt(password, rng, 12) << "\n"; + return 0; + } + else if(argc == 3) + { + const std::string password = argv[1]; + const std::string hash = argv[2]; + + if(hash.length() != 60) + std::cout << "Note: bcrypt '" << hash << "' has wrong length and cannot be valid\n"; + + const bool ok = check_bcrypt(password, hash); + + std::cout << "Password is " << (ok ? "valid" : "NOT valid") << "\n"; + return (ok ? 0 : 1); + } + + std::cout << "Usage: " << argv[0] << " password\n" + << " " << argv[0] << " password passhash\n"; + return 1; + } diff --git a/src/examples/examples.h b/src/examples/examples.h new file mode 100644 index 000000000..0fdc27121 --- /dev/null +++ b/src/examples/examples.h @@ -0,0 +1,9 @@ + +#include "../common.h" +#include <botan/auto_rng.h> +#include <botan/hex.h> +#include <iostream> + +using namespace Botan; + +int bcrypt_example(int argc, char* argv[]); diff --git a/src/main.cpp b/src/main.cpp index 05b0eed85..7446eef62 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,6 +27,7 @@ using namespace Botan; #include "common.h" #include "speed/speed.h" #include "tests/tests.h" +#include "examples/examples.h" // from common.h void strip_comments(std::string& line) @@ -99,7 +100,7 @@ int main(int argc, char* argv[]) if(opts.is_set("help") || argc < 2) { - std::cout << "Commands: test version time\n"; + std::cout << "Commands: test version time bcrypt\n"; return 1; } @@ -117,6 +118,11 @@ int main(int argc, char* argv[]) return failures ? 1 : 0; } + if(cmd == "bcrypt") + { + bcrypt_example(argc - 1, argv + 1); + } + if(cmd == "speed") { double seconds = 5; |