Noise-C
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
Data Structures | Macros
Buffer management API

Data Structures

struct  NoiseBuffer
 Type that defines a region of memory for a data buffer. More...
 

Macros

#define noise_buffer_init(buffer)   ((buffer).data = 0, (buffer).size = 0, (buffer).max_size = 0)
 Initializes all fields of a buffer to zero. More...
 
#define noise_buffer_set_inout(buffer, ptr, len, max)   ((buffer).data = (ptr), (buffer).size = (len), (buffer).max_size = (max))
 Sets a NoiseBuffer object to point to an input-output memory region. More...
 
#define noise_buffer_set_input(buffer, ptr, len)   ((buffer).data = (ptr), (buffer).size = (buffer).max_size = (len))
 Sets a NoiseBuffer object to point to an input memory region. More...
 
#define noise_buffer_set_output(buffer, ptr, len)   ((buffer).data = (ptr), (buffer).size = 0, (buffer).max_size = (len))
 Sets a NoiseBuffer object to point to an output memory region. More...
 

Detailed Description

This API defines types and macros to help with managing the passing of buffers to the Noise-C library. NoiseBuffer objects carry their current and maximum sizes around with them wherever they go. The intention is that applications that use NoiseBuffer are less likely to create a buffer overrun situation because the maximum size is always available for checking and never implicit.


Data Structure Documentation

struct NoiseBuffer

Type that defines a region of memory for a data buffer.

Definition at line 33 of file buffer.h.

Data Fields
uint8_t * data

Points to the data in the buffer

size_t max_size

Maximum size of the data in the buffer

size_t size

Current size of the data in the buffer

Macro Definition Documentation

#define noise_buffer_init (   buffer)    ((buffer).data = 0, (buffer).size = 0, (buffer).max_size = 0)

Initializes all fields of a buffer to zero.

#define noise_buffer_set_inout (   buffer,
  ptr,
  len,
  max 
)    ((buffer).data = (ptr), (buffer).size = (len), (buffer).max_size = (max))

Sets a NoiseBuffer object to point to an input-output memory region.

Parameters
bufferThe NoiseBuffer object to set.
ptrPointer to the start of the memory region for the buffer.
lenLength of the memory region in bytes on input.
maxMaximum length of the memory region in bytes.

This function is intended for use when transforming a region of memory; for example to encrypt or decrypt it. The original size is len and during transformation the region can grow in size to no more than max.

#define noise_buffer_set_input (   buffer,
  ptr,
  len 
)    ((buffer).data = (ptr), (buffer).size = (buffer).max_size = (len))

Sets a NoiseBuffer object to point to an input memory region.

Parameters
bufferThe NoiseBuffer object to set.
ptrPointer to the start of the memory region for the buffer.
lenLength of the memory region in bytes.

The buffer's current and maximum size are both set to len.

This macro is intended for passing an existing region of memory to a Noise-C function. It is typically used for input values.

#define noise_buffer_set_output (   buffer,
  ptr,
  len 
)    ((buffer).data = (ptr), (buffer).size = 0, (buffer).max_size = (len))

Sets a NoiseBuffer object to point to an output memory region.

Parameters
bufferThe NoiseBuffer object to set.
ptrPointer to the start of the memory region for the buffer.
lenLength of the memory region in bytes.

The buffer's current size is set to zero and its maximum size is set to len.

This macro is intended for initializing a region of memory to receive data that was output by a Noise-C function. The maximum size indicates how many bytes can be output into the region before overflow occurs.