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
32namespace Botan {
33
34using namespace std::tr1::placeholders;
35
36/**
37* TLS Record Writer
38*/
39class 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;
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*/
79class 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
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;
110 size_t block_size, mac_size, iv_size;
111 u64bit seq_no;
112 byte major, minor;
113 };
114
115}
116
117#endif
size_t get_record(byte &msg_type, MemoryRegion< byte > &buffer)
Definition rec_read.cpp:119
void set_version(Version_Code version)
Definition rec_read.cpp:34
void add_input(const byte input[], size_t input_size)
Definition rec_read.cpp:111
SecureVector< byte > get_record(byte &msg_type)
void set_keys(const CipherSuite &suite, const SessionKeys &keys, Connection_Side side)
Definition rec_read.cpp:46
void send(byte type, const byte input[], size_t length)
Definition rec_wri.cpp:131
void send(byte type, byte val)
Definition tls_record.h:43
Record_Writer(std::tr1::function< void(const byte[], size_t)> output_fn)
Definition rec_wri.cpp:19
Alert_Type
Definition tls_magic.h:62
unsigned long long u64bit
Definition types.h:49
Connection_Side
Definition tls_magic.h:29
Alert_Level
Definition tls_magic.h:57
Version_Code
Definition tls_magic.h:22