Botan 2.1.0 Crypto and TLS for C++11

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

msg_session_ticket.cpp
Go to the documentation of this file.
1 /*
2 * Session Tickets
3 * (C) 2012 Jack Lloyd
4 *
5 * Botan is released under the Simplified BSD License (see license.txt)
6 */
7
8 #include <botan/tls_messages.h>
9 #include <botan/tls_extensions.h>
10 #include <botan/internal/tls_reader.h>
11 #include <botan/internal/tls_handshake_io.h>
12 #include <botan/internal/tls_handshake_hash.h>
13 #include <botan/loadstor.h>
14
15 namespace Botan {
16
17 namespace TLS {
18
19 New_Session_Ticket::New_Session_Ticket(Handshake_IO& io,
20 Handshake_Hash& hash,
21 const std::vector<uint8_t>& ticket,
22 uint32_t lifetime) :
23 m_ticket_lifetime_hint(lifetime),
24 m_ticket(ticket)
25 {
26 hash.update(io.send(*this));
27 }
28
29 New_Session_Ticket::New_Session_Ticket(Handshake_IO& io,
30 Handshake_Hash& hash)
31 {
32 hash.update(io.send(*this));
33 }
34
35 New_Session_Ticket::New_Session_Ticket(const std::vector<uint8_t>& buf)
36 {
37 if(buf.size() < 6)
38 throw Decoding_Error("Session ticket message too short to be valid");
39
40 TLS_Data_Reader reader("SessionTicket", buf);
41
42 m_ticket_lifetime_hint = reader.get_uint32_t();
43 m_ticket = reader.get_range<uint8_t>(2, 0, 65535);
44 }
45
46 std::vector<uint8_t> New_Session_Ticket::serialize() const
47 {
48 std::vector<uint8_t> buf(4);
49 store_be(m_ticket_lifetime_hint, buf.data());
50 append_tls_length_value(buf, m_ticket, 2);
51 return buf;
52 }
53
54 }
55
56 }
Botan::TLS::Handshake_IO::send
virtual std::vector< uint8_t > send(const Handshake_Message &msg)=0
Botan::TLS::TLS_Data_Reader::get_uint32_t
uint32_t get_uint32_t()
Definition: tls_reader.h:53
Botan::store_be
void store_be(uint16_t in, uint8_t out[2])
Definition: loadstor.h:441
Botan::TLS::Handshake_Hash
Definition: tls_handshake_hash.h:22
Botan::TLS::TLS_Data_Reader::get_range
std::vector< T > get_range(size_t len_bytes, size_t min_elems, size_t max_elems)
Definition: tls_reader.h:94
Botan::TLS::Handshake_Hash::update
void update(const uint8_t in[], size_t length)
Definition: tls_handshake_hash.h:25
Botan::Decoding_Error
Definition: exceptn.h:189
Botan::TLS::Handshake_IO
Definition: tls_handshake_io.h:30
Botan
Definition: alg_id.cpp:13
Botan::TLS::TLS_Data_Reader
Definition: tls_reader.h:24
hash
MechanismType hash
Definition: p11_mechanism.cpp:63
Botan::TLS::New_Session_Ticket::New_Session_Ticket
New_Session_Ticket(Handshake_IO &io, Handshake_Hash &hash, const std::vector< uint8_t > &ticket, uint32_t lifetime)
Definition: msg_session_ticket.cpp:19
Botan::TLS::append_tls_length_value
void append_tls_length_value(std::vector< uint8_t, Alloc > &buf, const T *vals, size_t vals_size, size_t tag_size)
Definition: tls_reader.h:185