aboutsummaryrefslogtreecommitdiffstats
path: root/src/tls/tls_record.h
diff options
context:
space:
mode:
authorlloyd <[email protected]>2011-12-23 16:17:29 +0000
committerlloyd <[email protected]>2011-12-23 16:17:29 +0000
commit67c1645ae151f5dd0f2bafce926ff8690fd97f19 (patch)
tree9af9c1c22ab58093328cdfd00dbe42292d8b5ed6 /src/tls/tls_record.h
parentd363602f95f1514b4b595d9912fba2e503edcb21 (diff)
Rename ssl module to tls
Diffstat (limited to 'src/tls/tls_record.h')
-rw-r--r--src/tls/tls_record.h119
1 files changed, 119 insertions, 0 deletions
diff --git a/src/tls/tls_record.h b/src/tls/tls_record.h
new file mode 100644
index 000000000..6d5dd057d
--- /dev/null
+++ b/src/tls/tls_record.h
@@ -0,0 +1,119 @@
+/*
+* TLS Record Handling
+* (C) 2004-2010 Jack Lloyd
+*
+* Released under the terms of the Botan license
+*/
+
+#ifndef BOTAN_TLS_RECORDS_H__
+#define BOTAN_TLS_RECORDS_H__
+
+#include <botan/tls_session_key.h>
+#include <botan/tls_suites.h>
+#include <botan/pipe.h>
+#include <botan/mac.h>
+#include <botan/secqueue.h>
+#include <vector>
+
+#if defined(BOTAN_USE_STD_TR1)
+
+#if defined(BOTAN_BUILD_COMPILER_IS_MSVC)
+ #include <functional>
+#else
+ #include <tr1/functional>
+#endif
+
+#elif defined(BOTAN_USE_BOOST_TR1)
+ #include <boost/tr1/functional.hpp>
+#else
+ #error "No TR1 library defined for use"
+#endif
+
+namespace Botan {
+
+using namespace std::tr1::placeholders;
+
+/**
+* TLS Record Writer
+*/
+class BOTAN_DLL Record_Writer
+ {
+ public:
+ void send(byte type, const byte input[], size_t length);
+ void send(byte type, byte val) { send(type, &val, 1); }
+
+ void flush();
+
+ void alert(Alert_Level, Alert_Type);
+
+ void set_keys(const CipherSuite&, const SessionKeys&, Connection_Side);
+
+ void set_version(Version_Code);
+
+ void reset();
+
+ Record_Writer(std::tr1::function<void (const byte[], size_t)> output_fn);
+
+ ~Record_Writer() { delete mac; }
+ private:
+ void send_record(byte type, const byte input[], size_t length);
+ void send_record(byte type, byte major, byte minor,
+ const byte input[], size_t length);
+
+ std::tr1::function<void (const byte[], size_t)> output_fn;
+ Pipe cipher;
+ MessageAuthenticationCode* mac;
+
+ SecureVector<byte> buffer;
+ size_t buf_pos;
+
+ size_t block_size, mac_size, iv_size;
+
+ u64bit seq_no;
+ byte major, minor, buf_type;
+ };
+
+/**
+* TLS Record Reader
+*/
+class BOTAN_DLL Record_Reader
+ {
+ public:
+ void add_input(const byte input[], size_t input_size);
+
+ /**
+ * @param msg_type (output variable)
+ * @param buffer (output variable)
+ * @return Number of bytes still needed (minimum), or 0 if success
+ */
+ size_t get_record(byte& msg_type,
+ MemoryRegion<byte>& buffer);
+
+ SecureVector<byte> get_record(byte& msg_type);
+
+ void set_keys(const CipherSuite& suite,
+ const SessionKeys& keys,
+ Connection_Side side);
+
+ void set_version(Version_Code version);
+
+ void reset();
+
+ bool currently_empty() const { return input_queue.size() == 0; }
+
+ Record_Reader() { mac = 0; reset(); }
+
+ ~Record_Reader() { delete mac; }
+ private:
+ SecureQueue input_queue;
+
+ Pipe cipher;
+ MessageAuthenticationCode* mac;
+ size_t block_size, mac_size, iv_size;
+ u64bit seq_no;
+ byte major, minor;
+ };
+
+}
+
+#endif