aboutsummaryrefslogtreecommitdiffstats
path: root/src/tls
diff options
context:
space:
mode:
Diffstat (limited to 'src/tls')
-rw-r--r--src/tls/rec_wri.cpp11
-rw-r--r--src/tls/tls_alert.cpp14
-rw-r--r--src/tls/tls_alert.h25
-rw-r--r--src/tls/tls_channel.cpp2
-rw-r--r--src/tls/tls_client.cpp6
-rw-r--r--src/tls/tls_record.h2
6 files changed, 31 insertions, 29 deletions
diff --git a/src/tls/rec_wri.cpp b/src/tls/rec_wri.cpp
index 4eff52f78..09a6803f4 100644
--- a/src/tls/rec_wri.cpp
+++ b/src/tls/rec_wri.cpp
@@ -280,17 +280,6 @@ void Record_Writer::send_record(byte type, const byte input[], size_t length)
m_seq_no++;
}
-/*
-* Send an alert
-*/
-void Record_Writer::send_alert(const Alert& alert)
- {
- const byte alert_bits[2] = { static_cast<byte>(alert.is_fatal() ? 2 : 1),
- static_cast<byte>(alert.type()) };
-
- send_array(ALERT, alert_bits, sizeof(alert_bits));
- }
-
}
}
diff --git a/src/tls/tls_alert.cpp b/src/tls/tls_alert.cpp
index 5bc2e7484..540fdd838 100644
--- a/src/tls/tls_alert.cpp
+++ b/src/tls/tls_alert.cpp
@@ -18,8 +18,8 @@ Alert::Alert(const std::vector<byte>& buf)
throw Decoding_Error("Alert: Bad size " + std::to_string(buf.size()) +
" for alert message");
- if(buf[0] == 1) fatal = false;
- else if(buf[0] == 2) fatal = true;
+ if(buf[0] == 1) m_fatal = false;
+ else if(buf[0] == 2) m_fatal = true;
else
throw Decoding_Error("Alert: Bad code for alert level");
@@ -32,7 +32,15 @@ Alert::Alert(const std::vector<byte>& buf)
if(dc == 255)
throw Internal_Error("Alert: description code 255, rejecting");
- type_code = static_cast<Type>(dc);
+ m_type_code = static_cast<Type>(dc);
+ }
+
+std::vector<byte> Alert::serialize() const
+ {
+ std::vector<byte> alert(2);
+ alert[0] = static_cast<byte>(is_fatal() ? 2 : 1);
+ alert[1] = static_cast<byte>(type());
+ return alert;
}
std::string Alert::type_string() const
diff --git a/src/tls/tls_alert.h b/src/tls/tls_alert.h
index f2c270704..acbcc56d6 100644
--- a/src/tls/tls_alert.h
+++ b/src/tls/tls_alert.h
@@ -64,17 +64,17 @@ class BOTAN_DLL Alert
/**
* @return true iff this alert is non-empty
*/
- bool is_valid() const { return (type_code != NULL_ALERT); }
+ bool is_valid() const { return (m_type_code != NULL_ALERT); }
/**
* @return if this alert is a fatal one or not
*/
- bool is_fatal() const { return fatal; }
+ bool is_fatal() const { return m_fatal; }
/**
* @return type of alert
*/
- Type type() const { return type_code; }
+ Type type() const { return m_type_code; }
/**
* @return type of alert
@@ -82,6 +82,11 @@ class BOTAN_DLL Alert
std::string type_string() const;
/**
+ * Serialize an alert
+ */
+ std::vector<byte> serialize() const;
+
+ /**
* Deserialize an Alert message
* @param buf the serialized alert
*/
@@ -89,16 +94,16 @@ class BOTAN_DLL Alert
/**
* Create a new Alert
- * @param alert_type the type of alert
- * @param is_fatal specifies if this is a fatal alert
+ * @param type_code the type of alert
+ * @param fatal specifies if this is a fatal alert
*/
- Alert(Type alert_type, bool is_fatal = false) :
- fatal(is_fatal), type_code(alert_type) {}
+ Alert(Type type_code, bool fatal = false) :
+ m_fatal(fatal), m_type_code(type_code) {}
- Alert() : fatal(false), type_code(NULL_ALERT) {}
+ Alert() : m_fatal(false), m_type_code(NULL_ALERT) {}
private:
- bool fatal;
- Type type_code;
+ bool m_fatal;
+ Type m_type_code;
};
}
diff --git a/src/tls/tls_channel.cpp b/src/tls/tls_channel.cpp
index 63a496358..453ef9062 100644
--- a/src/tls/tls_channel.cpp
+++ b/src/tls/tls_channel.cpp
@@ -221,7 +221,7 @@ void Channel::send_alert(const Alert& alert)
{
try
{
- m_writer.send_alert(alert);
+ m_writer.send(ALERT, alert.serialize());
}
catch(...) { /* swallow it */ }
}
diff --git a/src/tls/tls_client.cpp b/src/tls/tls_client.cpp
index 7fa1ad8bc..dfcd89acf 100644
--- a/src/tls/tls_client.cpp
+++ b/src/tls/tls_client.cpp
@@ -67,8 +67,10 @@ Handshake_State* Client::new_handshake_state()
using namespace std::placeholders;
return new Client_Handshake_State(
- new Stream_Handshake_IO(std::bind(&Record_Writer::send,
- std::ref(m_writer), _1, _2)));
+ new Stream_Handshake_IO(
+ std::bind(&Record_Writer::send, std::ref(m_writer), _1, _2)
+ )
+ );
}
/*
diff --git a/src/tls/tls_record.h b/src/tls/tls_record.h
index 3d3e4d7a7..5dfcb7625 100644
--- a/src/tls/tls_record.h
+++ b/src/tls/tls_record.h
@@ -35,8 +35,6 @@ class BOTAN_DLL Record_Writer
void send(byte type, const std::vector<byte>& input)
{ send_array(type, &input[0], input.size()); }
- void send_alert(const Alert& alert);
-
void change_cipher_spec(Connection_Side side,
const Ciphersuite& suite,
const Session_Keys& keys,