aboutsummaryrefslogtreecommitdiffstats
path: root/src/tls/tls_blocking.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/tls/tls_blocking.cpp')
-rw-r--r--src/tls/tls_blocking.cpp24
1 files changed, 18 insertions, 6 deletions
diff --git a/src/tls/tls_blocking.cpp b/src/tls/tls_blocking.cpp
index ee94f086e..7b773cd81 100644
--- a/src/tls/tls_blocking.cpp
+++ b/src/tls/tls_blocking.cpp
@@ -6,6 +6,7 @@
*/
#include <botan/tls_blocking.h>
+#include <botan/internal/assert.h>
namespace Botan {
@@ -50,16 +51,24 @@ void Blocking_Client::process_data(const byte data[], size_t data_len,
alert_notification(alert);
}
-size_t Blocking_Client::read(byte buf[], size_t buf_len)
+void Blocking_Client::do_handshake()
{
- secure_vector<byte> readbuf(4096);
+ std::vector<byte> readbuf(4096);
- while(m_plaintext.empty())
+ while(!m_channel.is_closed() && !m_channel.is_active())
{
- const size_t readbuf_size = 4096;
- byte readbuf[readbuf_size] = { 0 };
+ const size_t from_socket = m_read_fn(&readbuf[0], readbuf.size());
+ m_channel.received_data(&readbuf[0], from_socket);
+ }
+ }
- const size_t from_socket = m_read_fn(&readbuf[0], readbuf_size);
+size_t Blocking_Client::read(byte buf[], size_t buf_len)
+ {
+ std::vector<byte> readbuf(4096);
+
+ while(m_plaintext.empty() && !m_channel.is_closed())
+ {
+ const size_t from_socket = m_read_fn(&readbuf[0], readbuf.size());
m_channel.received_data(&readbuf[0], from_socket);
}
@@ -69,6 +78,9 @@ size_t Blocking_Client::read(byte buf[], size_t buf_len)
buf[i] = m_plaintext[i];
m_plaintext.erase(m_plaintext.begin(), m_plaintext.begin() + returned);
+ BOTAN_ASSERT_IMPLICATION(returned == 0, m_channel.is_closed(),
+ "Only return zero if channel is closed");
+
return returned;
}