- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Types | Public Member Functions | Static Public Member Functions | List of all members
GSsl::Protocol Class Reference

An SSL protocol class. More...

`#include <gssl.h>`

## Public Types
enum | Result { Result_ok, Result_read, Result_write, Result_error, Result_more }
typedef size_t | size_type
typedef ssize_t | ssize_type
typedef void(* | LogFn) (int, const std::string &)

## Public Member Functions
| Protocol (const Library &)
| Constructor. More...
| Protocol (const Library &, LogFn)
| Constructor. More...
| ~Protocol ()
| Destructor. More...
Result | connect (int fd)
| Starts the protocol actively. More...
Result | accept (int fd)
| Starts the protocol passively. More...
Result | stop ()
| Initiates the protocol shutdown. More...
Result | read (char *buffer, size_type buffer_size_in, ssize_type &data_size_out)
| Reads user data into the supplied buffer. More...
Result | write (const char *buffer, size_type data_size_in, ssize_type &data_size_out)
| Writes user data. More...
std::pair< std::string, bool > | peerCertificate (int format=0)
| Returns the peer certificate and a verified flag. More...

## Static Public Member Functions
static std::string | str (Result result)
| Converts a result enumeration into a printable string. More...

## Detailed Description

An SSL protocol class.

The protocol object is associated with a particular socket file descriptor by the connect() and accept() calls.

The protocol is half-duplex in the sense that it is not possible to read() data while a write() is incomplete. (Nor is it allowed to issue a second write() while the first write() is still incomplete.) Client code will typically need at least two states: a reading state and a writing state. In each state the file descriptor read events and write events will be handled identically; in the reading state by a call to Protocol::read(), and in the writing state by a call to Protocol::write().

All logging is done indirectly through a logging function pointer; the first parameter is the logging level which is 0 for hex dump data, 1 for verbose debug messages and 2 for more important errors and warnings. Some implemetations do not log anything useful.

Definition at line 58 of file gssl.h.

## Member Typedef Documentation

typedef void(* GSsl::Protocol::LogFn) (int, const std::string &)

Definition at line 64 of file gssl.h.

typedef size_t GSsl::Protocol::size_type

Definition at line 61 of file gssl.h.

typedef ssize_t GSsl::Protocol::ssize_type

Definition at line 62 of file gssl.h.

## Member Enumeration Documentation

enum GSsl::Protocol::Result

Enumerator
Result_ok |
Result_read |
Result_write |
Result_error |
Result_more |

Definition at line 63 of file gssl.h.

## Constructor & Destructor Documentation

GSsl::Protocol::Protocol | ( | const Library & | library | ) |
| explicit

Constructor.

Definition at line 378 of file gssl_openssl.cpp.

GSsl::Protocol::Protocol | ( | const Library & | library,
|  | LogFn | log_fn
| ) |  |

Constructor.

Definition at line 383 of file gssl_openssl.cpp.

GSsl::Protocol::~Protocol | ( |  | ) |

Destructor.

Definition at line 388 of file gssl_openssl.cpp.

## Member Function Documentation

GSsl::Protocol::Result GSsl::Protocol::accept | ( | int | fd | ) |

Starts the protocol passively.

Definition at line 412 of file gssl_openssl.cpp.

GSsl::Protocol::Result GSsl::Protocol::connect | ( | int | fd | ) |

Starts the protocol actively.

Definition at line 407 of file gssl_openssl.cpp.

std::pair< std::string, bool > GSsl::Protocol::peerCertificate | ( | int | format = `0` | ) |

Returns the peer certificate and a verified flag.

The default format of the certificate is printable with embedded newlines but otherwise unspecified.

Definition at line 393 of file gssl_openssl.cpp.

GSsl::Protocol::Result GSsl::Protocol::read | ( | char * | buffer,
|  | size_type | buffer_size_in,
|  | ssize_type & | data_size_out
| ) |  |

Reads user data into the supplied buffer.

Returns Result_read if there is not enough transport data to complete the internal SSL data packet. In this case the file descriptor should remain in the select() read list and the Protocol::read() should be retried using the same parameters when the file descriptor is ready to be read.

Returns Result_write if the SSL layer tried to write to the file descriptor and had flow control asserted. In this case the file descriptor should be added to the select() write list and the Protocol::read() should be retried using the same parameters when the file descriptor is ready to be written.

Returns Result_ok if the internal SSL data packet is complete and it has been completely deposited in the supplied buffer.

Returns Result_more if the internal SSL data packet is complete and the supplied buffer was too small to take it all.

Returns Result_error if the transport connnection was lost or if the SSL session was shut down by the peer or on error.

Definition at line 422 of file gssl_openssl.cpp.

GSsl::Protocol::Result GSsl::Protocol::stop | ( |  | ) |

Initiates the protocol shutdown.

Definition at line 417 of file gssl_openssl.cpp.

std::string GSsl::Protocol::str | ( | Protocol::Result | result | ) |
| static

Converts a result enumeration into a printable string.

Used in logging and diagnostics.

Definition at line 398 of file gssl_openssl.cpp.

GSsl::Protocol::Result GSsl::Protocol::write | ( | const char * | buffer,
|  | size_type | data_size_in,
|  | ssize_type & | data_size_out
| ) |  |

Writes user data.

Returns Result_ok if fully sent.

Returns Result_read if the SSL layer needs more transport data (eg. for a renegotiation). The write() should be repeated using the same parameters on the file descriptor's next readable event.

Returns Result_write if the SSL layer was blocked in writing transport data. The write() should be repeated using the same parameters on the file descriptor's next writable event.

Returns Result_error if the transport connnection was lost or if the SSL session was shut down by the peer or on error.

Definition at line 427 of file gssl_openssl.cpp.

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

- gssl.h
- gssl_openssl.cpp