libssh: The SSH buffer functions

libssh 0.11.2 The SSH library

Loading...
Searching...
No Matches
The SSH buffer functions
The libssh API

## Macros
#define | buffer_verify(x)

## Functions
struct ssh_buffer_struct * | ssh_buffer_new (void)
| Create a new SSH buffer.
void | ssh_buffer_free (struct ssh_buffer_struct *buffer)
| Deallocate a SSH buffer.
void | ssh_buffer_set_secure (ssh_buffer buffer)
| Sets the buffer as secure.
int | ssh_buffer_reinit (struct ssh_buffer_struct *buffer)
| Reinitialize a SSH buffer.
int | ssh_buffer_add_data (struct ssh_buffer_struct *buffer, const void *data, uint32_t len)
| Add data at the tail of a buffer.
int | ssh_buffer_allocate_size (struct ssh_buffer_struct *buffer, uint32_t len)
| Ensure the buffer has at least a certain preallocated size.
void * | ssh_buffer_allocate (struct ssh_buffer_struct *buffer, uint32_t len)
int | ssh_buffer_add_ssh_string (struct ssh_buffer_struct *buffer, struct ssh_string_struct *string)
int | ssh_buffer_add_u32 (struct ssh_buffer_struct *buffer, uint32_t data)
int | ssh_buffer_add_u16 (struct ssh_buffer_struct *buffer, uint16_t data)
int | ssh_buffer_add_u64 (struct ssh_buffer_struct *buffer, uint64_t data)
int | ssh_buffer_add_u8 (struct ssh_buffer_struct *buffer, uint8_t data)
int | ssh_buffer_prepend_data (struct ssh_buffer_struct *buffer, const void *data, uint32_t len)
int | ssh_buffer_add_buffer (struct ssh_buffer_struct *buffer, struct ssh_buffer_struct *source)
void * | ssh_buffer_get (struct ssh_buffer_struct *buffer)
| Get a pointer to the head of a buffer at the current position.
uint32_t | ssh_buffer_get_len (struct ssh_buffer_struct *buffer)
| Get the length of the buffer from the current position.
uint32_t | ssh_buffer_pass_bytes (struct ssh_buffer_struct *buffer, uint32_t len)
uint32_t | ssh_buffer_pass_bytes_end (struct ssh_buffer_struct *buffer, uint32_t len)
uint32_t | ssh_buffer_get_data (struct ssh_buffer_struct *buffer, void *data, uint32_t len)
| Get the remaining data out of the buffer and adjust the read pointer.
uint32_t | ssh_buffer_get_u8 (struct ssh_buffer_struct *buffer, uint8_t *data)
uint32_t | ssh_buffer_get_u32 (struct ssh_buffer_struct *buffer, uint32_t *data)
uint32_t | ssh_buffer_get_u64 (struct ssh_buffer_struct *buffer, uint64_t *data)
int | ssh_buffer_validate_length (struct ssh_buffer_struct *buffer, size_t len)
| Validates that the given length can be obtained from the buffer.
struct ssh_string_struct * | ssh_buffer_get_ssh_string (struct ssh_buffer_struct *buffer)
int | _ssh_buffer_pack (struct ssh_buffer_struct *buffer, const char *format, size_t argc,...)
int | ssh_buffer_unpack_va (struct ssh_buffer_struct *buffer, const char *format, size_t argc, va_list ap)
int | _ssh_buffer_unpack (struct ssh_buffer_struct *buffer, const char *format, size_t argc,...)

## Detailed Description

Functions to handle SSH buffers.

## Function Documentation

## ◆ ssh_buffer_add_data()

int ssh_buffer_add_data | ( | struct ssh_buffer_struct * | buffer,
|  | const void * | data,
|  | uint32_t | len )

Add data at the tail of a buffer.

Parameters

  [in] | buffer | The buffer to add the data.
  [in] | data | A pointer to the data to add.
  [in] | len | The length of the data to add.

Returns
  0 on success, < 0 on error.

## ◆ ssh_buffer_allocate_size()

int ssh_buffer_allocate_size | ( | struct ssh_buffer_struct * | buffer,
|  | uint32_t | len )

Ensure the buffer has at least a certain preallocated size.

Parameters

  [in] | buffer | The buffer to enlarge.
  [in] | len | The length to ensure as allocated.

Returns
  0 on success, < 0 on error.

## ◆ ssh_buffer_free()

void ssh_buffer_free | ( | struct ssh_buffer_struct * | buffer | ) |

Deallocate a SSH buffer.

Parameters

  [in] | buffer | The buffer to free.

## ◆ ssh_buffer_get()

void * ssh_buffer_get | ( | struct ssh_buffer_struct * | buffer | ) |

Get a pointer to the head of a buffer at the current position.

Parameters

  [in] | buffer | The buffer to get the head pointer.

Returns
  A pointer to the data from current position.

See also
  ssh_buffer_get_len()

## ◆ ssh_buffer_get_data()

uint32_t ssh_buffer_get_data | ( | struct ssh_buffer_struct * | buffer,
|  | void * | data,
|  | uint32_t | len )

Get the remaining data out of the buffer and adjust the read pointer.

Parameters

  [in] | buffer | The buffer to read.
  [in] | data | The data buffer where to store the data.
  [in] | len | The length to read from the buffer.

Returns
  0 if there is not enough data in buffer, len otherwise.

## ◆ ssh_buffer_get_len()

uint32_t ssh_buffer_get_len | ( | struct ssh_buffer_struct * | buffer | ) |

Get the length of the buffer from the current position.

Parameters

  [in] | buffer | The buffer to get the length from.

Returns
  The length of the buffer.

See also
  ssh_buffer_get()

## ◆ ssh_buffer_new()

struct ssh_buffer_struct * ssh_buffer_new | ( | void |  | ) |

Create a new SSH buffer.

Returns
  A newly initialized SSH buffer, NULL on error.

## ◆ ssh_buffer_reinit()

int ssh_buffer_reinit | ( | struct ssh_buffer_struct * | buffer | ) |

Reinitialize a SSH buffer.

In case the buffer has exceeded 64K in size, the buffer will be reallocated to 64K.

Parameters

  [in] | buffer | The buffer to reinitialize.

Returns
  0 on success, < 0 on error.

## ◆ ssh_buffer_set_secure()

void ssh_buffer_set_secure | ( | ssh_buffer | buffer | ) |

Sets the buffer as secure.

A secure buffer will never leave cleartext data in the heap after being reallocated or freed.

Parameters

  [in] | buffer | buffer to set secure.

## ◆ ssh_buffer_validate_length()

int ssh_buffer_validate_length | ( | struct ssh_buffer_struct * | buffer,
|  | size_t | len )

Validates that the given length can be obtained from the buffer.

Parameters

  [in] | buffer | The buffer to read from.
  [in] | len | The length to be checked.

Returns
  SSH_OK if the length is valid, SSH_ERROR otherwise.