Botan: src/ssl/tls_record.h Source File

Botan 1.10.17

tls_record.h
Go to the documentation of this file.
1 /*
2 * TLS Record Handling
3 * (C) 2004-2010 Jack Lloyd
4 *
5 * Released under the terms of the Botan license
6 */
7
8 #ifndef BOTAN_TLS_RECORDS_H__
9 #define BOTAN_TLS_RECORDS_H__
10
11 #include <botan/tls_session_key.h>
12 #include <botan/tls_suites.h>
13 #include <botan/pipe.h>
14 #include <botan/mac.h>
15 #include <botan/secqueue.h>
16 #include <vector>
17
18 #if defined(BOTAN_USE_STD_TR1)
19
20 #if defined(BOTAN_BUILD_COMPILER_IS_MSVC)
21 #include <functional>
22 #else
23 #include <tr1/functional>
24 #endif
25
26 #elif defined(BOTAN_USE_BOOST_TR1)
27 #include <boost/tr1/functional.hpp>
28 #else
29 #error "No TR1 library defined for use"
30 #endif
31
32 namespace Botan {
33
34 using namespace std::tr1::placeholders;
35
36 /**
37 * TLS Record Writer
38 */
39 class BOTAN_DLL Record_Writer
40 {
41 public:
42 void send(byte type, const byte input[], size_t length);
43 void send(byte type, byte val) { send(type, &val, 1); }
44
45 void flush();
46
47 void alert(Alert_Level, Alert_Type);
48
49 void set_keys(const CipherSuite&, const SessionKeys&, Connection_Side);
50
51 void set_version(Version_Code);
52
53 void reset();
54
55 Record_Writer(std::tr1::function<void (const byte[], size_t)> output_fn);
56
57 ~Record_Writer() { delete mac; }
58 private:
59 void send_record(byte type, const byte input[], size_t length);
60 void send_record(byte type, byte major, byte minor,
61 const byte input[], size_t length);
62
63 std::tr1::function<void (const byte[], size_t)> output_fn;
64 Pipe cipher;
65 MessageAuthenticationCode* mac;
66
67 SecureVector<byte> buffer;
68 size_t buf_pos;
69
70 size_t block_size, mac_size, iv_size;
71
72 u64bit seq_no;
73 byte major, minor, buf_type;
74 };
75
76 /**
77 * TLS Record Reader
78 */
79 class BOTAN_DLL Record_Reader
80 {
81 public:
82 void add_input(const byte input[], size_t input_size);
83
84 /**
85 * @param msg_type (output variable)
86 * @param buffer (output variable)
87 * @return Number of bytes still needed (minimum), or 0 if success
88 */
89 size_t get_record(byte& msg_type,
90 MemoryRegion<byte>& buffer);
91
92 SecureVector<byte> get_record(byte& msg_type);
93
94 void set_keys(const CipherSuite& suite,
95 const SessionKeys& keys,
96 Connection_Side side);
97
98 void set_version(Version_Code version);
99
100 void reset();
101
102 Record_Reader() { mac = 0; reset(); }
103
104 ~Record_Reader() { delete mac; }
105 private:
106 SecureQueue input_queue;
107
108 Pipe cipher;
109 MessageAuthenticationCode* mac;
110 size_t block_size, mac_size, iv_size;
111 u64bit seq_no;
112 byte major, minor;
113 };
114
115 }
116
117 #endif
Botan::SecureQueue
Definition: secqueue.h:19
Botan::Record_Reader::Record_Reader
Record_Reader()
Definition: tls_record.h:102
Botan::MessageAuthenticationCode
Definition: mac.h:20
Botan::byte
unsigned char byte
Definition: types.h:22
Botan::Alert_Level
Alert_Level
Definition: tls_magic.h:57
Botan::Connection_Side
Connection_Side
Definition: tls_magic.h:29
Botan::u64bit
unsigned long long u64bit
Definition: types.h:49
Botan::Record_Reader
Definition: tls_record.h:79
Botan::Record_Writer::send
void send(byte type, byte val)
Definition: tls_record.h:43
Botan::SessionKeys
Definition: tls_session_key.h:20
Botan::Version_Code
Version_Code
Definition: tls_magic.h:22
Botan::MemoryRegion< byte >
Botan
Definition: algo_base.h:14
Botan::Record_Reader::~Record_Reader
~Record_Reader()
Definition: tls_record.h:104
Botan::Record_Writer
Definition: tls_record.h:39
Botan::Alert_Type
Alert_Type
Definition: tls_magic.h:62
Botan::CipherSuite
Definition: tls_suites.h:20
Botan::SecureVector< byte >
Botan::Pipe
Definition: pipe.h:25
Botan::Record_Writer::~Record_Writer
~Record_Writer()
Definition: tls_record.h:57
placeholders