Botan  1.11.15
Public Types | Public Member Functions | Protected Member Functions
Botan::TLS::Blocking_Client Class Reference

#include <tls_blocking.h>

List of all members.

Public Types

typedef Client::next_protocol_fn next_protocol_fn
typedef std::function< size_t(byte[],
size_t)> 
read_fn
typedef std::function< void(const
byte[], size_t)> 
write_fn

Public Member Functions

 Blocking_Client (read_fn reader, write_fn writer, Session_Manager &session_manager, Credentials_Manager &creds, const Policy &policy, RandomNumberGenerator &rng, const Server_Information &server_info=Server_Information(), const Protocol_Version offer_version=Protocol_Version::latest_tls_version(), next_protocol_fn npn=next_protocol_fn())
void close ()
void do_handshake ()
bool is_closed () const
std::vector< X509_Certificatepeer_cert_chain () const
size_t pending () const
size_t read (byte buf[], size_t buf_len)
const TLS::Channelunderlying_channel () const
TLS::Channelunderlying_channel ()
void write (const byte buf[], size_t buf_len)
virtual ~Blocking_Client ()

Protected Member Functions

virtual void alert_notification (const Alert &)
virtual bool handshake_complete (const Session &)

Detailed Description

Blocking TLS Client Can be used directly, or subclass to get handshake and alert notifications

Definition at line 25 of file tls_blocking.h.


Member Typedef Documentation

Definition at line 35 of file tls_blocking.h.

typedef std::function<size_t (byte[], size_t)> Botan::TLS::Blocking_Client::read_fn

Definition at line 32 of file tls_blocking.h.

typedef std::function<void (const byte[], size_t)> Botan::TLS::Blocking_Client::write_fn

Definition at line 33 of file tls_blocking.h.


Constructor & Destructor Documentation

Botan::TLS::Blocking_Client::Blocking_Client ( read_fn  reader,
write_fn  writer,
Session_Manager session_manager,
Credentials_Manager creds,
const Policy policy,
RandomNumberGenerator rng,
const Server_Information server_info = Server_Information(),
const Protocol_Version  offer_version = Protocol_Version::latest_tls_version(),
next_protocol_fn  npn = next_protocol_fn() 
)

Definition at line 16 of file tls_blocking.cpp.

                                                       :
   m_read(reader),
   m_channel(writer,
             std::bind(&Blocking_Client::data_cb, this, _1, _2),
             std::bind(&Blocking_Client::alert_cb, this, _1, _2, _3),
             std::bind(&Blocking_Client::handshake_cb, this, _1),
             session_manager,
             creds,
             policy,
             rng,
             server_info,
             offer_version,
             npn)
   {
   }
virtual Botan::TLS::Blocking_Client::~Blocking_Client ( ) [inline, virtual]

Definition at line 75 of file tls_blocking.h.

{}

Member Function Documentation

virtual void Botan::TLS::Blocking_Client::alert_notification ( const Alert ) [inline, protected, virtual]

Application can override to get notification of alerts

Definition at line 86 of file tls_blocking.h.

{}

Definition at line 68 of file tls_blocking.h.

{ m_channel.close(); }

Completes full handshake then returns

Definition at line 55 of file tls_blocking.cpp.

References Botan::TLS::Channel::is_active(), Botan::TLS::Channel::is_closed(), and Botan::TLS::Channel::received_data().

   {
   std::vector<byte> readbuf(4096);

   while(!m_channel.is_closed() && !m_channel.is_active())
      {
      const size_t from_socket = m_read(&readbuf[0], readbuf.size());
      m_channel.received_data(&readbuf[0], from_socket);
      }
   }
virtual bool Botan::TLS::Blocking_Client::handshake_complete ( const Session ) [inline, protected, virtual]

Application can override to get the handshake complete notification

Definition at line 81 of file tls_blocking.h.

{ return true; }
bool Botan::TLS::Blocking_Client::is_closed ( ) const [inline]

Definition at line 70 of file tls_blocking.h.

{ return m_channel.is_closed(); }

Definition at line 72 of file tls_blocking.h.

         { return m_channel.peer_cert_chain(); }
size_t Botan::TLS::Blocking_Client::pending ( ) const [inline]

Number of bytes pending read in the plaintext buffer (bytes readable without blocking)

Definition at line 56 of file tls_blocking.h.

{ return m_plaintext.size(); }
size_t Botan::TLS::Blocking_Client::read ( byte  buf[],
size_t  buf_len 
)

Blocking read, will return at least 1 byte or 0 on connection close

Definition at line 66 of file tls_blocking.cpp.

References BOTAN_ASSERT_IMPLICATION, Botan::TLS::Channel::is_closed(), and Botan::TLS::Channel::received_data().

   {
   std::vector<byte> readbuf(4096);

   while(m_plaintext.empty() && !m_channel.is_closed())
      {
      const size_t from_socket = m_read(&readbuf[0], readbuf.size());
      m_channel.received_data(&readbuf[0], from_socket);
      }

   const size_t returned = std::min(buf_len, m_plaintext.size());

   for(size_t i = 0; i != returned; ++i)
      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;
   }

Definition at line 65 of file tls_blocking.h.

{ return m_channel; }

Definition at line 66 of file tls_blocking.h.

{ return m_channel; }
void Botan::TLS::Blocking_Client::write ( const byte  buf[],
size_t  buf_len 
) [inline]

Definition at line 63 of file tls_blocking.h.

{ m_channel.send(buf, buf_len); }

The documentation for this class was generated from the following files: