diff options
-rw-r--r-- | src/examples/examples.h | 6 | ||||
-rw-r--r-- | src/examples/fpe.cpp (renamed from doc/examples/fpe.cpp) | 11 | ||||
-rw-r--r-- | src/examples/read_ssh.cpp (renamed from doc/examples/read_ssh.cpp) | 24 | ||||
-rw-r--r-- | src/examples/self_sig.cpp (renamed from doc/examples/self_sig.cpp) | 6 | ||||
-rw-r--r-- | src/examples/x509print.cpp | 17 | ||||
-rw-r--r-- | src/main.cpp | 32 |
6 files changed, 68 insertions, 28 deletions
diff --git a/src/examples/examples.h b/src/examples/examples.h index a3dfa85f5..2a9a361c7 100644 --- a/src/examples/examples.h +++ b/src/examples/examples.h @@ -9,3 +9,9 @@ using namespace Botan; int asn1_example(int argc, char* argv[]); int bcrypt_example(int argc, char* argv[]); int factor_example(int argc, char* argv[]); +int fpe_example(int argc, char* argv[]); +int read_ssh_example(int argc, char* argv[]); + +int self_sig_example(int argc, char* argv[]); + +int x509_example(int argc, char* argv[]); diff --git a/doc/examples/fpe.cpp b/src/examples/fpe.cpp index 8f5eaca9f..cccb602fd 100644 --- a/doc/examples/fpe.cpp +++ b/src/examples/fpe.cpp @@ -1,4 +1,4 @@ -#include <botan/botan.h> +#include "examples.h" #include <botan/fpe_fe1.h> #include <botan/sha160.h> @@ -102,10 +102,8 @@ u64bit decrypt_cc_number(u64bit enc_cc, } -int main(int argc, char* argv[]) +int fpe_example(int argc, char* argv[]) { - LibraryInitializer init; - if(argc != 4) { std::cout << "Usage: " << argv[0] << " cc-number acct-name passwd\n"; @@ -136,5 +134,10 @@ int main(int argc, char* argv[]) << ' ' << luhn_check(dec_cc) << '\n'; if(dec_cc != cc_number) + { std::cout << "Something went wrong :( Bad CC checksum?\n"; + return 2; + } + + return 0; } diff --git a/doc/examples/read_ssh.cpp b/src/examples/read_ssh.cpp index 7ef81b346..83f7ff89e 100644 --- a/doc/examples/read_ssh.cpp +++ b/src/examples/read_ssh.cpp @@ -8,6 +8,8 @@ * Example of reading SSH2 format public keys (see RFC 4716) */ +#include "examples.h" + #include <botan/x509_key.h> #include <botan/filters.h> #include <botan/loadstor.h> @@ -61,7 +63,7 @@ Public_Key* read_ssh_pubkey(const std::string& file) std::getline(in, line); if(line != ssh_header) - return 0; + return nullptr; while(in.good()) { @@ -86,7 +88,7 @@ Public_Key* read_ssh_pubkey(const std::string& file) std::string key_type = read_string(pipe); if(key_type != "ssh-rsa" && key_type != "ssh-dss") - return 0; + return nullptr; if(key_type == "ssh-rsa") { @@ -104,23 +106,25 @@ Public_Key* read_ssh_pubkey(const std::string& file) return new DSA_PublicKey(DL_Group(p, q, g), y); } - return 0; + return nullptr; } } -#include <botan/init.h> -#include <iostream> - -int main() +int read_ssh_example(int argc, char* argv[]) { - LibraryInitializer init; + if(argc != 2) + { + std::cout << "Usage: " << argv[0] << " file"; + return 1; + } - std::unique_ptr<Public_Key> key(read_ssh_pubkey("dsa.ssh")); + const std::string filename = argv[1]; + std::unique_ptr<Public_Key> key(read_ssh_pubkey(filename)); if(key == 0) { - std::cout << "Failed\n"; + std::cout << "Failed to read" << filename << "\n"; return 1; } diff --git a/doc/examples/self_sig.cpp b/src/examples/self_sig.cpp index 7cb159db9..89d9f84e7 100644 --- a/doc/examples/self_sig.cpp +++ b/src/examples/self_sig.cpp @@ -1,4 +1,4 @@ -#include <botan/botan.h> +#include "examples.h" #include <botan/x509self.h> #include <botan/rsa.h> #include <botan/dsa.h> @@ -8,7 +8,7 @@ using namespace Botan; #include <fstream> #include <memory> -int main(int argc, char* argv[]) +int self_sig_example(int argc, char* argv[]) { if(argc != 7) { @@ -18,8 +18,6 @@ int main(int argc, char* argv[]) return 1; } - Botan::LibraryInitializer init; - std::string CA_flag = argv[2]; bool do_CA = false; diff --git a/src/examples/x509print.cpp b/src/examples/x509print.cpp new file mode 100644 index 000000000..88e1dfbaa --- /dev/null +++ b/src/examples/x509print.cpp @@ -0,0 +1,17 @@ +#include "examples.h" +#include <botan/x509cert.h> + +int x509_example(int argc, char* argv[]) + { + if(argc < 1) + { + std::cout << "Usage: " << argv[0] << " cert.pem\n"; + return 1; + } + + X509_Certificate cert(argv[1]); + + std::cout << cert.to_string() << "\n"; + + return 0; + } diff --git a/src/main.cpp b/src/main.cpp index 4dccce41d..baf37e895 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -120,21 +120,33 @@ int main(int argc, char* argv[]) return failures ? 1 : 0; } -if(cmd == "cpuid") - { - CPUID::print(std::cout); -return 0; -} + if(cmd == "cpuid") + { + CPUID::print(std::cout); + return 0; + } -if(cmd == "http_get") - { -auto resp = HTTP::GET_sync(argv[2]); -std::cout << resp << "\n"; -} + if(cmd == "http_get") + { + auto resp = HTTP::GET_sync(argv[2]); + std::cout << resp << "\n"; + } if(cmd == "bcrypt") return bcrypt_example(argc - 1, argv + 1); + if(cmd == "fpe") + return fpe_example(argc - 1, argv + 1); + + if(cmd == "read_ssh_key") + return read_ssh_example(argc - 1, argv + 1); + + if(cmd == "self_sig") + return self_sig_example(argc - 1, argv + 1); + + if(cmd == "x509") + return x509_example(argc - 1, argv + 1); + if(cmd == "factor") return factor_example(argc - 1, argv + 1); |