/src/botan/src/lib/tls/msg_session_ticket.cpp
Line | Count | Source (jump to first uncovered line) |
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/internal/tls_reader.h> |
10 | | #include <botan/internal/tls_handshake_io.h> |
11 | | #include <botan/internal/tls_handshake_hash.h> |
12 | | #include <botan/loadstor.h> |
13 | | |
14 | | namespace Botan { |
15 | | |
16 | | namespace TLS { |
17 | | |
18 | | New_Session_Ticket::New_Session_Ticket(Handshake_IO& io, |
19 | | Handshake_Hash& hash, |
20 | | const std::vector<uint8_t>& ticket, |
21 | | uint32_t lifetime) : |
22 | | m_ticket_lifetime_hint(lifetime), |
23 | | m_ticket(ticket) |
24 | 288 | { |
25 | 288 | hash.update(io.send(*this)); |
26 | 288 | } |
27 | | |
28 | | New_Session_Ticket::New_Session_Ticket(Handshake_IO& io, |
29 | | Handshake_Hash& hash) |
30 | 0 | { |
31 | 0 | hash.update(io.send(*this)); |
32 | 0 | } |
33 | | |
34 | | New_Session_Ticket::New_Session_Ticket(const std::vector<uint8_t>& buf) |
35 | 6 | { |
36 | 6 | if(buf.size() < 6) |
37 | 1 | throw Decoding_Error("Session ticket message too short to be valid"); |
38 | 5 | |
39 | 5 | TLS_Data_Reader reader("SessionTicket", buf); |
40 | 5 | |
41 | 5 | m_ticket_lifetime_hint = reader.get_uint32_t(); |
42 | 5 | m_ticket = reader.get_range<uint8_t>(2, 0, 65535); |
43 | 5 | reader.assert_done(); |
44 | 5 | } |
45 | | |
46 | | std::vector<uint8_t> New_Session_Ticket::serialize() const |
47 | 288 | { |
48 | 288 | std::vector<uint8_t> buf(4); |
49 | 288 | store_be(m_ticket_lifetime_hint, buf.data()); |
50 | 288 | append_tls_length_value(buf, m_ticket, 2); |
51 | 288 | return buf; |
52 | 288 | } |
53 | | |
54 | | } |
55 | | |
56 | | } |