aboutsummaryrefslogtreecommitdiffstats
path: root/src/tls/next_protocol.cpp
blob: 97b07244055715cecaf32ad4227790dea8feb040 (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
/*
* Next Protocol Negotation
* (C) 2012 Jack Lloyd
*
* Released under the terms of the Botan license
*/

#include <botan/internal/tls_messages.h>
#include <botan/internal/tls_extensions.h>
#include <botan/internal/tls_reader.h>

namespace Botan {

namespace TLS {

Next_Protocol::Next_Protocol(Record_Writer& writer,
                             Handshake_Hash& hash,
                             const std::string& protocol) :
   m_protocol(protocol)
   {
   send(writer, hash);
   }

Next_Protocol::Next_Protocol(const MemoryRegion<byte>& buf)
   {
   TLS_Data_Reader reader(buf);

   m_protocol = reader.get_string(1, 0, 255);

   reader.get_range_vector<byte>(1, 0, 255); // padding, ignored
   }

MemoryVector<byte> Next_Protocol::serialize() const
   {
   MemoryVector<byte> buf;

   append_tls_length_value(buf,
                           reinterpret_cast<const byte*>(m_protocol.data()),
                           m_protocol.size(),
                           1);

   const byte padding_len = 32 - ((m_protocol.size() + 2) % 32);

   buf.push_back(padding_len);

   for(size_t i = 0; i != padding_len; ++i)
      buf.push_back(0);

   return buf;
   }

}

}