|
XenevaOS
|
This file defines reader objects, which together with their sibling writer objects form the basis for the communication between the various layers of the Mbed TLS messaging stack, as well as the communication between the messaging stack and the (D)TLS handshake protocol implementation. More...

Go to the source code of this file.
Classes | |
| struct | mbedtls_mps_reader |
Typedefs | |
| typedef struct mbedtls_mps_reader | mbedtls_mps_reader |
Functions | |
| int | mbedtls_mps_reader_init (mbedtls_mps_reader *reader, unsigned char *acc, mbedtls_mps_size_t acc_len) |
| Initialize a reader object. | |
| int | mbedtls_mps_reader_free (mbedtls_mps_reader *reader) |
| Free a reader object. | |
| int | mbedtls_mps_reader_feed (mbedtls_mps_reader *reader, unsigned char *buf, mbedtls_mps_size_t buflen) |
| Pass chunk of data for the reader to manage. | |
| int | mbedtls_mps_reader_reclaim (mbedtls_mps_reader *reader, int *paused) |
| Reclaim reader's access to the current input buffer. | |
| int | mbedtls_mps_reader_get (mbedtls_mps_reader *reader, mbedtls_mps_size_t desired, unsigned char **buffer, mbedtls_mps_size_t *buflen) |
| Request data from the reader. | |
| int | mbedtls_mps_reader_commit (mbedtls_mps_reader *reader) |
| Mark data obtained from mbedtls_mps_reader_get() as processed. | |
This file defines reader objects, which together with their sibling writer objects form the basis for the communication between the various layers of the Mbed TLS messaging stack, as well as the communication between the messaging stack and the (D)TLS handshake protocol implementation.
Readers provide a means of transferring incoming data from a 'producer' providing it in chunks of arbitrary size, to a 'consumer' which fetches and processes it in chunks of again arbitrary, and potentially different, size.
Readers can thus be seen as datagram-to-stream converters, and they abstract away the following two tasks from the user:
The basic abstract flow of operation is the following:
The abstract states of the reader from the producer's and consumer's perspective are as follows:
Transitioning from the Unset or Accumulating state to Attached is done via successful calls to mbedtls_mps_reader_feed(), while transitioning from Attached to either Unset or Accumulating (depending on what has been processed) is done via mbedtls_mps_reader_reclaim().
The following diagram depicts the producer-state progression:
+------------------+ reclaim
| Unset +<-------------------------------------+ get
+--------|---------+ | +------+
| | | |
| | | |
| feed +---------+---+--+ |
+--------------------------------------> <---+
| Attached |
+--------------------------------------> <---+
| feed, enough data available +---------+---+--+ |
| to serve previous consumer request | | |
| | | |
+--------+---------+ | +------+
+-—> Accumulating |<----------------------------------—+ commit | +—+-----------—+ reclaim, previous read request | | couldn't be fulfilled | | +-----—+ feed, need more data to serve previous consumer request | | producing mode | consuming mode |
| typedef struct mbedtls_mps_reader mbedtls_mps_reader |
| int mbedtls_mps_reader_commit | ( | mbedtls_mps_reader * | reader | ) |
Mark data obtained from mbedtls_mps_reader_get() as processed.
This call indicates that all data received from prior calls to
mbedtls_mps_reader_get() has been or will have been
processed when mbedtls_mps_reader_reclaim() is called,
and thus need not be backed up.
This function has no user observable effect until
mbedtls_mps_reader_reclaim() is called. In particular,
buffers received from mbedtls_mps_reader_get() remain
valid until mbedtls_mps_reader_reclaim() is called.
| reader | The reader context to use. |
0 on success. MBEDTLS_ERR_READER_XXX error code on failure. | int mbedtls_mps_reader_feed | ( | mbedtls_mps_reader * | reader, |
| unsigned char * | buf, | ||
| mbedtls_mps_size_t | buflen | ||
| ) |
Pass chunk of data for the reader to manage.
| reader | The reader context to use. The reader must be in producing mode. |
| buf | The buffer to be managed by the reader. |
| buflen | The size in Bytes of buffer. |
0 on success. In this case, the reader will be moved to consuming mode and obtains read access of buf until mbedtls_mps_reader_reclaim() is called. It is the responsibility of the caller to ensure that the buf persists and is not changed between successful calls to mbedtls_mps_reader_feed() and mbedtls_mps_reader_reclaim(). MBEDTLS_ERR_MPS_READER_NEED_MORE if more input data is required to fulfill a previous request to mbedtls_mps_reader_get(). In this case, the reader remains in producing mode and takes no ownership of the provided buffer (an internal copy is made instead). MBEDTLS_ERR_READER_XXX error code on different kinds of failures. | int mbedtls_mps_reader_free | ( | mbedtls_mps_reader * | reader | ) |
Free a reader object.
| reader | The reader to be freed. |
0 on success. MBEDTLS_ERR_READER_XXX error code on failure. | int mbedtls_mps_reader_get | ( | mbedtls_mps_reader * | reader, |
| mbedtls_mps_size_t | desired, | ||
| unsigned char ** | buffer, | ||
| mbedtls_mps_size_t * | buflen | ||
| ) |
Request data from the reader.
| reader | The reader context to use. The reader must be in consuming mode. |
| desired | The desired amount of data to be read, in Bytes. |
| buffer | The address to store the buffer pointer in. This must not be NULL. |
| buflen | The address to store the actual buffer length in, or NULL. |
0 on success. In this case, *buf holds the address of a buffer of size *buflen (if buflen != NULL) or desired (if buflen == NULL). The user has read access to the buffer and guarantee of stability of the data until the next call to mbedtls_mps_reader_reclaim(). MBEDTLS_ERR_READER_XXX error code for different kinds of failure.NULL as buflen is a convenient way to indicate that fragmentation is not tolerated. It's functionally equivalent to passing a valid address as buflen and checking *buflen == desired afterwards. | int mbedtls_mps_reader_init | ( | mbedtls_mps_reader * | reader, |
| unsigned char * | acc, | ||
| mbedtls_mps_size_t | acc_len | ||
| ) |
Initialize a reader object.
| reader | The reader to be initialized. |
| acc | The buffer to be used as a temporary accumulator in case get requests through mbedtls_mps_reader_get() exceed the buffer provided by mbedtls_mps_reader_feed(). This buffer is owned by the caller and exclusive use for reading and writing is given to the reader for the duration of the reader's lifetime. It is thus the caller's responsibility to maintain (and not touch) the buffer for the lifetime of the reader, and to properly zeroize and free the memory after the reader has been destroyed. |
| acc_len | The size in Bytes of acc. |
0 on success. MBEDTLS_ERR_READER_XXX error code on failure. | int mbedtls_mps_reader_reclaim | ( | mbedtls_mps_reader * | reader, |
| int * | paused | ||
| ) |
Reclaim reader's access to the current input buffer.
| reader | The reader context to use. The reader must be in consuming mode. |
| paused | If not NULL, the integer at address paused will be modified to indicate whether the reader has been paused (value 1) or not (value 0). Pausing happens if there is uncommitted data and a previous request to mbedtls_mps_reader_get() has exceeded the bounds of the input buffer. |
0 on success. MBEDTLS_ERR_READER_XXX error code on failure.