aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/examples/cpuid.cpp18
-rw-r--r--doc/examples/passhash.cpp50
-rw-r--r--src/examples/asn1.cpp (renamed from doc/examples/asn1.cpp)12
-rw-r--r--src/examples/examples.h2
-rw-r--r--src/examples/factor.cpp (renamed from doc/examples/factor.cpp)9
-rw-r--r--src/main.cpp24
6 files changed, 34 insertions, 81 deletions
diff --git a/doc/examples/cpuid.cpp b/doc/examples/cpuid.cpp
deleted file mode 100644
index 0a94d8717..000000000
--- a/doc/examples/cpuid.cpp
+++ /dev/null
@@ -1,18 +0,0 @@
-/*
-* (C) 2009 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#include <iostream>
-#include <string>
-#include <botan/cpuid.h>
-
-using namespace Botan;
-
-int main()
- {
- CPUID::initialize();
-
- CPUID::print(std::cout);
- }
diff --git a/doc/examples/passhash.cpp b/doc/examples/passhash.cpp
deleted file mode 100644
index 586c28c3f..000000000
--- a/doc/examples/passhash.cpp
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
-* (C) 2009 Jack Lloyd
-*
-* Distributed under the terms of the Botan license
-*/
-
-#include <botan/botan.h>
-#include <botan/passhash9.h>
-#include <iostream>
-#include <memory>
-
-#include <stdio.h>
-
-int main(int argc, char* argv[])
- {
- if(argc != 2 && argc != 3)
- {
- std::cerr << "Usage: " << argv[0] << " password\n";
- std::cerr << "Usage: " << argv[0] << " password hash\n";
- return 1;
- }
-
- Botan::LibraryInitializer init;
-
- try
- {
-
- if(argc == 2)
- {
- Botan::AutoSeeded_RNG rng;
-
- std::cout << "H('" << argv[1] << "') = "
- << Botan::generate_passhash9(argv[1], rng) << '\n';
- }
- else
- {
- bool ok = Botan::check_passhash9(argv[1], argv[2]);
- if(ok)
- std::cout << "Password and hash match\n";
- else
- std::cout << "Password and hash do not match\n";
- }
- }
- catch(std::exception& e)
- {
- std::cerr << e.what() << '\n';
- return 1;
- }
- return 0;
- }
diff --git a/doc/examples/asn1.cpp b/src/examples/asn1.cpp
index 12ba43e15..40f597fc3 100644
--- a/doc/examples/asn1.cpp
+++ b/src/examples/asn1.cpp
@@ -1,4 +1,5 @@
-#include <botan/botan.h>
+#include "examples.h"
+
#include <botan/bigint.h>
#include <botan/der_enc.h>
#include <botan/ber_dec.h>
@@ -6,7 +7,6 @@
#include <botan/asn1_str.h>
#include <botan/oids.h>
#include <botan/pem.h>
-#include <botan/hex.h>
#include <botan/charset.h>
using namespace Botan;
@@ -28,6 +28,8 @@ void decode(BER_Decoder&, size_t);
void emit(const std::string&, size_t, size_t, const std::string& = "");
std::string type_name(ASN1_Tag);
+namespace {
+
std::string url_encode(const std::vector<byte>& in)
{
std::ostringstream out;
@@ -43,7 +45,9 @@ std::string url_encode(const std::vector<byte>& in)
return out.str();
}
-int main(int argc, char* argv[])
+}
+
+int asn1_example(int argc, char* argv[])
{
if(argc != 2)
{
@@ -51,8 +55,6 @@ int main(int argc, char* argv[])
return 1;
}
- LibraryInitializer init;
-
try {
DataSource_Stream in(argv[1]);
diff --git a/src/examples/examples.h b/src/examples/examples.h
index 0fdc27121..a3dfa85f5 100644
--- a/src/examples/examples.h
+++ b/src/examples/examples.h
@@ -6,4 +6,6 @@
using namespace Botan;
+int asn1_example(int argc, char* argv[]);
int bcrypt_example(int argc, char* argv[]);
+int factor_example(int argc, char* argv[]);
diff --git a/doc/examples/factor.cpp b/src/examples/factor.cpp
index 58b12d9a5..822b62b71 100644
--- a/doc/examples/factor.cpp
+++ b/src/examples/factor.cpp
@@ -7,7 +7,8 @@
* primes, and Pollard's Rho algorithm
*/
-#include <botan/botan.h>
+#include "examples.h"
+
#include <botan/reducer.h>
#include <botan/numthry.h>
using namespace Botan;
@@ -120,16 +121,14 @@ std::vector<BigInt> factorize(const BigInt& n_in,
}
-int main(int argc, char* argv[])
+int factor_example(int argc, char* argv[])
{
if(argc != 2)
{
- std::cerr << "Usage: " << argv[0] << " integer\n";
+ std::cout << "Usage: " << argv[0] << " <integer>\n";
return 1;
}
- Botan::LibraryInitializer init;
-
try
{
BigInt n(argv[1]);
diff --git a/src/main.cpp b/src/main.cpp
index 7446eef62..4dccce41d 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -21,6 +21,8 @@
#include <botan/init.h>
#include <botan/version.h>
#include <botan/auto_rng.h>
+#include <botan/cpuid.h>
+#include <botan/http_util.h>
using namespace Botan;
@@ -118,10 +120,26 @@ int main(int argc, char* argv[])
return failures ? 1 : 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 == "bcrypt")
- {
- bcrypt_example(argc - 1, argv + 1);
- }
+ return bcrypt_example(argc - 1, argv + 1);
+
+ if(cmd == "factor")
+ return factor_example(argc - 1, argv + 1);
+
+ if(cmd == "asn1")
+ return asn1_example(argc - 1, argv + 1);
if(cmd == "speed")
{