Botan  1.11.15
src/lib/tls/msg_next_protocol.cpp
Go to the documentation of this file.
00001 /*
00002 * Next Protocol Negotiation
00003 * (C) 2012 Jack Lloyd
00004 *
00005 * Botan is released under the Simplified BSD License (see license.txt)
00006 */
00007 
00008 #include <botan/internal/tls_messages.h>
00009 #include <botan/internal/tls_extensions.h>
00010 #include <botan/internal/tls_reader.h>
00011 #include <botan/internal/tls_handshake_io.h>
00012 
00013 namespace Botan {
00014 
00015 namespace TLS {
00016 
00017 Next_Protocol::Next_Protocol(Handshake_IO& io,
00018                              Handshake_Hash& hash,
00019                              const std::string& protocol) :
00020    m_protocol(protocol)
00021    {
00022    hash.update(io.send(*this));
00023    }
00024 
00025 Next_Protocol::Next_Protocol(const std::vector<byte>& buf)
00026    {
00027    TLS_Data_Reader reader("NextProtocol", buf);
00028 
00029    m_protocol = reader.get_string(1, 0, 255);
00030 
00031    reader.get_range_vector<byte>(1, 0, 255); // padding, ignored
00032    }
00033 
00034 std::vector<byte> Next_Protocol::serialize() const
00035    {
00036    std::vector<byte> buf;
00037 
00038    append_tls_length_value(buf,
00039                            reinterpret_cast<const byte*>(m_protocol.data()),
00040                            m_protocol.size(),
00041                            1);
00042 
00043    const byte padding_len = 32 - ((m_protocol.size() + 2) % 32);
00044 
00045    buf.push_back(padding_len);
00046 
00047    for(size_t i = 0; i != padding_len; ++i)
00048       buf.push_back(0);
00049 
00050    return buf;
00051    }
00052 
00053 }
00054 
00055 }