Botan  1.11.15
src/lib/tls/msg_session_ticket.cpp
Go to the documentation of this file.
00001 /*
00002 * Session Tickets
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 #include <botan/loadstor.h>
00013 
00014 namespace Botan {
00015 
00016 namespace TLS {
00017 
00018 New_Session_Ticket::New_Session_Ticket(Handshake_IO& io,
00019                                        Handshake_Hash& hash,
00020                                        const std::vector<byte>& ticket,
00021                                        u32bit lifetime) :
00022    m_ticket_lifetime_hint(lifetime),
00023    m_ticket(ticket)
00024    {
00025    hash.update(io.send(*this));
00026    }
00027 
00028 New_Session_Ticket::New_Session_Ticket(Handshake_IO& io,
00029                                        Handshake_Hash& hash)
00030    {
00031    hash.update(io.send(*this));
00032    }
00033 
00034 New_Session_Ticket::New_Session_Ticket(const std::vector<byte>& buf)
00035    {
00036    if(buf.size() < 6)
00037       throw Decoding_Error("Session ticket message too short to be valid");
00038 
00039    TLS_Data_Reader reader("SessionTicket", buf);
00040 
00041    m_ticket_lifetime_hint = reader.get_u32bit();
00042    m_ticket = reader.get_range<byte>(2, 0, 65535);
00043    }
00044 
00045 std::vector<byte> New_Session_Ticket::serialize() const
00046    {
00047    std::vector<byte> buf(4);
00048    store_be(m_ticket_lifetime_hint, &buf[0]);
00049    append_tls_length_value(buf, m_ticket, 2);
00050    return buf;
00051    }
00052 
00053 }
00054 
00055 }