aboutsummaryrefslogtreecommitdiffstats
path: root/src/tls/msg_next_protocol.cpp
diff options
context:
space:
mode:
authorlloyd <[email protected]>2012-08-03 14:42:44 +0000
committerlloyd <[email protected]>2012-08-03 14:42:44 +0000
commit3b8478fbf7aced5b1ab5d56757b6ca70f37e7557 (patch)
treed48fc9257d9eac73b12a1335bbd22d86e610830e /src/tls/msg_next_protocol.cpp
parentdb2a5f10716f69a58f8c554c8e65d21e198ffbc5 (diff)
Rename all the message source files to msg_
Diffstat (limited to 'src/tls/msg_next_protocol.cpp')
-rw-r--r--src/tls/msg_next_protocol.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/tls/msg_next_protocol.cpp b/src/tls/msg_next_protocol.cpp
new file mode 100644
index 000000000..71bb0eb9e
--- /dev/null
+++ b/src/tls/msg_next_protocol.cpp
@@ -0,0 +1,55 @@
+/*
+* Next Protocol Negotation
+* (C) 2012 Jack Lloyd
+*
+* Released under the terms of the Botan license
+*/
+
+#include <botan/internal/tls_messages.h>
+#include <botan/internal/tls_extensions.h>
+#include <botan/internal/tls_reader.h>
+#include <botan/internal/tls_handshake_io.h>
+
+namespace Botan {
+
+namespace TLS {
+
+Next_Protocol::Next_Protocol(Handshake_IO& io,
+ Handshake_Hash& hash,
+ const std::string& protocol) :
+ m_protocol(protocol)
+ {
+ hash.update(io.send(*this));
+ }
+
+Next_Protocol::Next_Protocol(const std::vector<byte>& buf)
+ {
+ TLS_Data_Reader reader(buf);
+
+ m_protocol = reader.get_string(1, 0, 255);
+
+ reader.get_range_vector<byte>(1, 0, 255); // padding, ignored
+ }
+
+std::vector<byte> Next_Protocol::serialize() const
+ {
+ std::vector<byte> buf;
+
+ append_tls_length_value(buf,
+ reinterpret_cast<const byte*>(m_protocol.data()),
+ m_protocol.size(),
+ 1);
+
+ const byte padding_len = 32 - ((m_protocol.size() + 2) % 32);
+
+ buf.push_back(padding_len);
+
+ for(size_t i = 0; i != padding_len; ++i)
+ buf.push_back(0);
+
+ return buf;
+ }
+
+}
+
+}