/src/botan/src/lib/tls/tls13/msg_key_update.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Key Update message |
3 | | * (C) 2022 Jack Lloyd |
4 | | * 2022 René Meusel, Hannes Rantzsch - neXenio GmbH |
5 | | * |
6 | | * Botan is released under the Simplified BSD License (see license.txt) |
7 | | */ |
8 | | |
9 | | #include <botan/tls_messages.h> |
10 | | #include <botan/tls_exceptn.h> |
11 | | |
12 | | namespace Botan::TLS { |
13 | | |
14 | | Key_Update::Key_Update(const bool request_peer_update) |
15 | 0 | : m_update_requested(request_peer_update) {} |
16 | | |
17 | | Key_Update::Key_Update(const std::vector<uint8_t>& buf) |
18 | 0 | { |
19 | 0 | if(buf.size() != 1) |
20 | 0 | { |
21 | 0 | throw TLS_Exception(Alert::DECODE_ERROR, "malformed key_update"); |
22 | 0 | } |
23 | | |
24 | | // RFC 8446 4.6.3 |
25 | | // If an implementation receives any other value [than 0 or 1], it MUST |
26 | | // terminate the connection with an "illegal_parameter" alert. |
27 | 0 | const uint8_t update_requested = buf.at(0); |
28 | 0 | if(update_requested > 1) |
29 | 0 | { |
30 | 0 | throw TLS_Exception(Alert::ILLEGAL_PARAMETER, "unexpected key_update parameter"); |
31 | 0 | } |
32 | | |
33 | 0 | m_update_requested = update_requested == 1; |
34 | 0 | } |
35 | | |
36 | | std::vector<uint8_t> Key_Update::serialize() const |
37 | 0 | { |
38 | 0 | return std::vector<uint8_t>(1, (m_update_requested ? 1 : 0)); |
39 | 0 | } |
40 | | |
41 | | } |