diff options
author | lloyd <[email protected]> | 2012-02-20 18:35:02 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2012-02-20 18:35:02 +0000 |
commit | 73e7730306b524aeee6fcfe8dd9f41b9673cf31b (patch) | |
tree | ded41f30316a7eb17b7e80c9b92351d457c753f0 /doc | |
parent | 7fb2de6b49d8bf42ede7b4dfda7c358bb67e5c9f (diff) |
Fix examples. Use crazy hack of compiling asio tls server using 4.6.0
but linking using 4.7.0 - asio seems to have problems with the 4.7.0
libstdc++ in C++11 mode, mostly related to missing noexcept and trying
to copy things that are move only.
Diffstat (limited to 'doc')
-rw-r--r-- | doc/examples/GNUmakefile | 11 | ||||
-rw-r--r-- | doc/examples/bench.cpp | 41 | ||||
-rw-r--r-- | doc/examples/credentials.h | 5 | ||||
-rw-r--r-- | doc/examples/gen_certs.cpp | 2 | ||||
-rw-r--r-- | doc/examples/rsa_dec.cpp | 2 | ||||
-rw-r--r-- | doc/examples/tls_client.cpp | 4 | ||||
-rw-r--r-- | doc/examples/tls_server.cpp | 14 |
7 files changed, 49 insertions, 30 deletions
diff --git a/doc/examples/GNUmakefile b/doc/examples/GNUmakefile index 5616b5abe..947db8fec 100644 --- a/doc/examples/GNUmakefile +++ b/doc/examples/GNUmakefile @@ -1,9 +1,9 @@ BOTAN_CONFIG = botan-config -CXX = g++-4.5-20091112 +CXX = g++-4.7.0 CFLAGS = -O2 -ansi -std=c++0x -W -Wall -I../../build/include -LIBS = -L../.. -lbotan-1.10 +LIBS = -L../.. -lbotan-1.99 SRCS=$(wildcard *.cpp) @@ -20,5 +20,8 @@ clean: eax_test: eax_test.cpp $(CXX) $(CFLAGS) $? $(LIBS) -lboost_regex -o $@ -asio_tls_server: asio_tls_server.cpp - $(CXX) $(CFLAGS) $? $(LIBS) -lboost_thread -lboost_system -o $@ +asio_tls_server.o: asio_tls_server.cpp + g++-4.6.0 -c $(CFLAGS) -I/usr/local/asio-1.5.3/include $? -o $@ + +asio_tls_server: asio_tls_server.o + $(CXX) $? $(LIBS) -lboost_thread -lboost_system -lpthread -o $@ diff --git a/doc/examples/bench.cpp b/doc/examples/bench.cpp index 884bc2ecc..87b3a57f7 100644 --- a/doc/examples/bench.cpp +++ b/doc/examples/bench.cpp @@ -67,29 +67,42 @@ const std::string algos[] = { "", }; -int main() + +void benchmark_algo(const std::string& algo, + RandomNumberGenerator& rng) { - LibraryInitializer init; + const u32bit milliseconds = 1000; + Algorithm_Factory& af = global_state().algorithm_factory(); std::map<std::string, double> speeds = algorithm_benchmark(algo, af, rng, milliseconds, 16*1024); - Algorithm_Factory& af = global_state().algorithm_factory(); + std::cout << algo << ":"; - for(u32bit i = 0; algos[i] != ""; ++i) + for(std::map<std::string, double>::const_iterator i = speeds.begin(); + i != speeds.end(); ++i) { - std::string algo = algos[i]; + std::cout << " " << i->second << " [" << i->first << "]"; + } + std::cout << "\n"; + } - std::map<std::string, double> speeds = - algorithm_benchmark(algos[i], milliseconds, rng, af); +} - std::cout << algo << ":"; +int main(int argc, char* argv[]) + { + LibraryInitializer init; + + AutoSeeded_RNG rng; - for(std::map<std::string, double>::const_iterator i = speeds.begin(); - i != speeds.end(); ++i) - { - std::cout << " " << i->second << " [" << i->first << "]"; - } - std::cout << "\n"; + if(argc == 1) // no args, benchmark everything + { + for(size_t i = 0; algos[i] != ""; ++i) + benchmark_algo(algos[i], rng); + } + else + { + for(size_t i = 1; argv[i]; ++i) + benchmark_algo(argv[i], rng); } } diff --git a/doc/examples/credentials.h b/doc/examples/credentials.h index d6350963c..48aa00571 100644 --- a/doc/examples/credentials.h +++ b/doc/examples/credentials.h @@ -9,6 +9,7 @@ #include <botan/ecdsa.h> #include <iostream> #include <fstream> +#include <memory> bool value_exists(const std::vector<std::string>& vec, const std::string& val) @@ -60,7 +61,7 @@ class Credentials_Manager_Simple : public Botan::Credentials_Manager X509_Certificate cert(cert_file_name); Private_Key* key = PKCS8::load_key(key_file_name, rng); - std::cout << "Loaded existing key/cert from " << cert_file_name << " and " << key_file_name << "\n"; + //std::cout << "Loaded existing key/cert from " << cert_file_name << " and " << key_file_name << "\n"; return std::make_pair(cert, key); } @@ -77,7 +78,7 @@ class Credentials_Manager_Simple : public Botan::Credentials_Manager opts.email = "root@" + hostname; opts.dns = hostname; - std::auto_ptr<Private_Key> key; + std::unique_ptr<Private_Key> key; if(key_type == "rsa") key.reset(new RSA_PrivateKey(rng, 2048)); else if(key_type == "dsa") diff --git a/doc/examples/gen_certs.cpp b/doc/examples/gen_certs.cpp index 73d667edb..14ae5a0a9 100644 --- a/doc/examples/gen_certs.cpp +++ b/doc/examples/gen_certs.cpp @@ -79,6 +79,8 @@ void save_pair(const std::string& name, key_out.close(); } +} + typedef std::chrono::duration<int, std::ratio<31556926>> years; int main() diff --git a/doc/examples/rsa_dec.cpp b/doc/examples/rsa_dec.cpp index 81592328c..9c470b8e9 100644 --- a/doc/examples/rsa_dec.cpp +++ b/doc/examples/rsa_dec.cpp @@ -41,7 +41,7 @@ int main(int argc, char* argv[]) AutoSeeded_RNG rng; std::auto_ptr<PKCS8_PrivateKey> key( - PKCS8::load_key(argv[1], rng, argv[3])); + PKCS8::load_key(std::string(argv[1]), rng, std::string(argv[3]))); RSA_PrivateKey* rsakey = dynamic_cast<RSA_PrivateKey*>(key.get()); if(!rsakey) diff --git a/doc/examples/tls_client.cpp b/doc/examples/tls_client.cpp index 1cca002af..654a3ccfe 100644 --- a/doc/examples/tls_client.cpp +++ b/doc/examples/tls_client.cpp @@ -20,7 +20,7 @@ using namespace Botan; -using namespace std::tr1::placeholders; +using namespace std::placeholders; int connect_to_host(const std::string& host, u16bit port) { @@ -120,7 +120,7 @@ void doit(RandomNumberGenerator& rng, { int sockfd = connect_to_host(host, port); - TLS::Client client(std::tr1::bind(socket_write, sockfd, _1, _2), + TLS::Client client(std::bind(socket_write, sockfd, _1, _2), process_data, handshake_complete, session_manager, diff --git a/doc/examples/tls_server.cpp b/doc/examples/tls_server.cpp index a5f2c5d78..6bbcfd8b5 100644 --- a/doc/examples/tls_server.cpp +++ b/doc/examples/tls_server.cpp @@ -12,7 +12,7 @@ using namespace Botan; -using namespace std::tr1::placeholders; +using namespace std::placeholders; #include <stdio.h> #include <string> @@ -33,8 +33,8 @@ bool handshake_complete(const TLS::Session& session) class Blocking_TLS_Server { public: - Blocking_TLS_Server(std::tr1::function<void (const byte[], size_t)> output_fn, - std::tr1::function<size_t (byte[], size_t)> input_fn, + Blocking_TLS_Server(std::function<void (const byte[], size_t)> output_fn, + std::function<size_t (byte[], size_t)> input_fn, std::vector<std::string>& protocols, TLS::Session_Manager& sessions, Credentials_Manager& creds, @@ -43,7 +43,7 @@ class Blocking_TLS_Server input_fn(input_fn), server( output_fn, - std::tr1::bind(&Blocking_TLS_Server::reader_fn, std::tr1::ref(*this), _1, _2, _3), + std::bind(&Blocking_TLS_Server::reader_fn, std::ref(*this), _1, _2, _3), handshake_complete, sessions, creds, @@ -119,7 +119,7 @@ class Blocking_TLS_Server read_queue.write(buf, buf_len); } - std::tr1::function<size_t (byte[], size_t)> input_fn; + std::function<size_t (byte[], size_t)> input_fn; TLS::Server server; SecureQueue read_queue; bool exit; @@ -161,8 +161,8 @@ int main(int argc, char* argv[]) printf("Got new connection\n"); Blocking_TLS_Server tls( - std::tr1::bind(&Socket::write, std::tr1::ref(sock), _1, _2), - std::tr1::bind(&Socket::read, std::tr1::ref(sock), _1, _2, true), + std::bind(&Socket::write, std::ref(sock), _1, _2), + std::bind(&Socket::read, std::ref(sock), _1, _2, true), protocols, sessions, creds, |