diff options
author | lloyd <[email protected]> | 2010-10-19 04:59:46 +0000 |
---|---|---|
committer | lloyd <[email protected]> | 2010-10-19 04:59:46 +0000 |
commit | fafe810679e01949ddd8ac86c8367f3c15b0bedc (patch) | |
tree | 3f6c1784aa8bc718fbe3a19e5645521d26ceaf4a /src | |
parent | 221f9bd1469de9248b0233d366cdc2f0613fc182 (diff) |
Make Record_Writer call a callback instead of writing directly to the socket
Diffstat (limited to 'src')
-rw-r--r-- | src/ssl/info.txt | 2 | ||||
-rw-r--r-- | src/ssl/rec_wri.cpp | 10 | ||||
-rw-r--r-- | src/ssl/tls_client.cpp | 4 | ||||
-rw-r--r-- | src/ssl/tls_record.h | 12 | ||||
-rw-r--r-- | src/ssl/tls_server.cpp | 2 |
5 files changed, 20 insertions, 10 deletions
diff --git a/src/ssl/info.txt b/src/ssl/info.txt index 8f1eda497..8b566ae60 100644 --- a/src/ssl/info.txt +++ b/src/ssl/info.txt @@ -1,5 +1,7 @@ define SSL_TLS +uses_tr1 yes + <header:public> socket.h tls_client.h diff --git a/src/ssl/rec_wri.cpp b/src/ssl/rec_wri.cpp index f3525a7d1..59dead3cd 100644 --- a/src/ssl/rec_wri.cpp +++ b/src/ssl/rec_wri.cpp @@ -16,8 +16,9 @@ namespace Botan { /** * Record_Writer Constructor */ -Record_Writer::Record_Writer(Socket& sock) : - socket(sock), buffer(DEFAULT_BUFFERSIZE) +Record_Writer::Record_Writer(std::tr1::function<void (const byte[], size_t)> out) : + output_fn(out), + buffer(DEFAULT_BUFFERSIZE) { mac = 0; reset(); @@ -188,7 +189,6 @@ void Record_Writer::send_record(byte type, const byte buf[], size_t length) send_record(type, major, minor, buf, length); else { - mac->update_be(seq_no); mac->update(type); @@ -253,8 +253,8 @@ void Record_Writer::send_record(byte type, byte major, byte minor, for(size_t i = 0; i != 2; ++i) header[i+3] = get_byte<u16bit>(i, length); - socket.write(header, 5); - socket.write(out, length); + output_fn(header, 5); + output_fn(out, length); } /** diff --git a/src/ssl/tls_client.cpp b/src/ssl/tls_client.cpp index 976b7c917..8c3d4db99 100644 --- a/src/ssl/tls_client.cpp +++ b/src/ssl/tls_client.cpp @@ -87,7 +87,7 @@ TLS_Client::TLS_Client(const TLS_Policy& pol, policy(pol), rng(r), peer(sock), - writer(sock) + writer(std::tr1::bind(&Socket::write, std::tr1::ref(peer), _1, _2)) { initialize(); } @@ -103,7 +103,7 @@ TLS_Client::TLS_Client(const TLS_Policy& pol, policy(pol), rng(r), peer(sock), - writer(sock) + writer(std::tr1::bind(&Socket::write, std::tr1::ref(peer), _1, _2)) { certs.push_back(cert); keys.push_back(PKCS8::copy_key(key, rng)); diff --git a/src/ssl/tls_record.h b/src/ssl/tls_record.h index 7ad866c6e..84929b0ff 100644 --- a/src/ssl/tls_record.h +++ b/src/ssl/tls_record.h @@ -16,6 +16,14 @@ #include <botan/secqueue.h> #include <vector> +#if defined(BOTAN_USE_STD_TR1) + #include <tr1/functional> +#elif defined(BOTAN_USE_BOOST_TR1) + #include <boost/tr1/functional.hpp> +#endif + +using namespace std::tr1::placeholders; + namespace Botan { /** @@ -37,7 +45,7 @@ class BOTAN_DLL Record_Writer void reset(); - Record_Writer(Socket& socket); + Record_Writer(std::tr1::function<void (const byte[], size_t)> output_fn); ~Record_Writer() { delete mac; } private: @@ -45,7 +53,7 @@ class BOTAN_DLL Record_Writer void send_record(byte type, byte major, byte minor, const byte input[], size_t length); - Socket& socket; + std::tr1::function<void (const byte[], size_t)> output_fn; Pipe cipher; MessageAuthenticationCode* mac; diff --git a/src/ssl/tls_server.cpp b/src/ssl/tls_server.cpp index 5412771ff..6f79fe0fb 100644 --- a/src/ssl/tls_server.cpp +++ b/src/ssl/tls_server.cpp @@ -93,7 +93,7 @@ TLS_Server::TLS_Server(const TLS_Policy& pol, policy(pol), rng(r), peer(sock), - writer(sock) + writer(std::tr1::bind(&Socket::write, std::tr1::ref(peer), _1, _2)) { state = 0; |