/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/internal/loadstor.h> |
13 | | |
14 | | namespace Botan::TLS { |
15 | | |
16 | | New_Session_Ticket_12::New_Session_Ticket_12(Handshake_IO& io, |
17 | | Handshake_Hash& hash, |
18 | | const std::vector<uint8_t>& ticket, |
19 | | uint32_t lifetime) : |
20 | | m_ticket_lifetime_hint(lifetime), |
21 | | m_ticket(ticket) |
22 | 203 | { |
23 | 203 | hash.update(io.send(*this)); |
24 | 203 | } |
25 | | |
26 | | New_Session_Ticket_12::New_Session_Ticket_12(Handshake_IO& io, |
27 | | Handshake_Hash& hash) |
28 | 0 | { |
29 | 0 | hash.update(io.send(*this)); |
30 | 0 | } |
31 | | |
32 | | New_Session_Ticket_12::New_Session_Ticket_12(const std::vector<uint8_t>& buf) |
33 | 0 | { |
34 | 0 | if(buf.size() < 6) |
35 | 0 | throw Decoding_Error("Session ticket message too short to be valid"); |
36 | | |
37 | 0 | TLS_Data_Reader reader("SessionTicket", buf); |
38 | |
|
39 | 0 | m_ticket_lifetime_hint = reader.get_uint32_t(); |
40 | 0 | m_ticket = reader.get_range<uint8_t>(2, 0, 65535); |
41 | 0 | reader.assert_done(); |
42 | 0 | } |
43 | | |
44 | | std::vector<uint8_t> New_Session_Ticket_12::serialize() const |
45 | 203 | { |
46 | 203 | std::vector<uint8_t> buf(4); |
47 | 203 | store_be(m_ticket_lifetime_hint, buf.data()); |
48 | 203 | append_tls_length_value(buf, m_ticket, 2); |
49 | 203 | return buf; |
50 | 203 | } |
51 | | |
52 | | } |