blob: 1f271d70a05d030877567a371a98b805ed1bc4e9 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
/*
* TLS Handshake Reader
* (C) 2012 Jack Lloyd
*
* Released under the terms of the Botan license
*/
#include <botan/internal/tls_handshake_reader.h>
#include <botan/exceptn.h>
namespace Botan {
namespace TLS {
namespace {
inline size_t load_be24(const byte q[3])
{
return make_u32bit(0,
q[0],
q[1],
q[2]);
}
}
void Stream_Handshake_Reader::add_input(const byte record[],
size_t record_size)
{
m_queue.insert(m_queue.end(), record, record + record_size);
}
bool Stream_Handshake_Reader::empty() const
{
return m_queue.empty();
}
bool Stream_Handshake_Reader::have_full_record() const
{
if(m_queue.size() >= 4)
{
const size_t length = load_be24(&m_queue[1]);
return (m_queue.size() >= length + 4);
}
return false;
}
std::pair<Handshake_Type, std::vector<byte> > Stream_Handshake_Reader::get_next_record()
{
if(m_queue.size() >= 4)
{
const size_t length = load_be24(&m_queue[1]);
if(m_queue.size() >= length + 4)
{
Handshake_Type type = static_cast<Handshake_Type>(m_queue[0]);
std::vector<byte> contents(m_queue.begin() + 4,
m_queue.begin() + 4 + length);
m_queue.erase(m_queue.begin(), m_queue.begin() + 4 + length);
return std::make_pair(type, contents);
}
}
throw Internal_Error("Stream_Handshake_Reader::get_next_record called without a full record");
}
}
}
|