Botan 3.11.0
Crypto and TLS for C&
msg_cert_verify.cpp
Go to the documentation of this file.
1/*
2* Certificate Verify Message
3* (C) 2004,2006,2011,2012 Jack Lloyd
4* 2017 Harry Reimann, Rohde & Schwarz Cybersecurity
5* 2021 Elektrobit Automotive GmbH
6* 2022 René Meusel, Hannes Rantzsch - neXenio GmbH
7*
8* Botan is released under the Simplified BSD License (see license.txt)
9*/
10
11#include <botan/tls_messages.h>
12
13#include <botan/internal/tls_reader.h>
14
15namespace Botan::TLS {
16
17/*
18* Deserialize a Certificate Verify message
19*/
20Certificate_Verify::Certificate_Verify(const std::vector<uint8_t>& buf) {
21 TLS_Data_Reader reader("CertificateVerify", buf);
22
24 m_signature = reader.get_range<uint8_t>(2, 0, 65535);
25 reader.assert_done();
26
27 if(!m_scheme.is_set()) {
28 throw Decoding_Error("Counterparty did not send hash/sig IDS");
29 }
30}
31
32/*
33* Serialize a Certificate Verify message
34*/
35std::vector<uint8_t> Certificate_Verify::serialize() const {
37 std::vector<uint8_t> buf;
38 buf.reserve(2 + 2 + m_signature.size()); // work around GCC warning
39
40 const auto code = m_scheme.wire_code();
41 buf.push_back(get_byte<0>(code));
42 buf.push_back(get_byte<1>(code));
43
44 if(m_signature.size() > 0xFFFF) {
45 throw Encoding_Error("Certificate_Verify signature too long to encode");
46 }
47
48 const uint16_t sig_len = static_cast<uint16_t>(m_signature.size());
49 buf.push_back(get_byte<0>(sig_len));
50 buf.push_back(get_byte<1>(sig_len));
51 buf += m_signature;
52
53 return buf;
54}
55
56} // namespace Botan::TLS
#define BOTAN_ASSERT_NOMSG(expr)
Definition assert.h:75
std::vector< uint8_t > serialize() const override
std::vector< uint8_t > m_signature
std::vector< T > get_range(size_t len_bytes, size_t min_elems, size_t max_elems)
Definition tls_reader.h:110
constexpr uint8_t get_byte(T input)
Definition loadstor.h:79