The SSH buffer functions.

Overview

Functions to handle SSH buffers. More…

// global functions

LIBSSH_API ssh_buffer
ssh_buffer_new(void);

void
ssh_buffer_set_secure(ssh_buffer buffer);

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

int
_ssh_buffer_pack(
    struct ssh_buffer_struct* buffer,
    const char* format,
    int argc,
    ...
);

int
_ssh_buffer_unpack(
    struct ssh_buffer_struct* buffer,
    const char* format,
    int argc,
    ...
);

int
buffer_add_buffer(
    struct ssh_buffer_struct* buffer,
    struct ssh_buffer_struct* source
);

int
buffer_add_ssh_string(
    struct ssh_buffer_struct* buffer,
    struct ssh_string_struct* string
);

int
buffer_add_u16(
    struct ssh_buffer_struct* buffer,
    uint16_t data
);

int
buffer_add_u32(
    struct ssh_buffer_struct* buffer,
    uint32_t data
);

int
buffer_add_u64(
    struct ssh_buffer_struct* buffer,
    uint64_t data
);

int
buffer_add_u8(
    struct ssh_buffer_struct* buffer,
    uint8_t data
);

uint32_t
buffer_get_data(
    struct ssh_buffer_struct* buffer,
    void* data,
    uint32_t len
);

struct ssh_string_struct*
buffer_get_mpint(struct ssh_buffer_struct* buffer);

void*
buffer_get_rest(struct ssh_buffer_struct* buffer);

uint32_t
buffer_get_rest_len(struct ssh_buffer_struct* buffer);

struct ssh_string_struct*
buffer_get_ssh_string(struct ssh_buffer_struct* buffer);

int
buffer_get_u32(
    struct ssh_buffer_struct* buffer,
    uint32_t* data
);

int
buffer_get_u64(
    struct ssh_buffer_struct* buffer,
    uint64_t* data
);

int
buffer_get_u8(
    struct ssh_buffer_struct* buffer,
    uint8_t* data
);

uint32_t
buffer_pass_bytes(
    struct ssh_buffer_struct* buffer,
    uint32_t len
);

uint32_t
buffer_pass_bytes_end(
    struct ssh_buffer_struct* buffer,
    uint32_t len
);

int
buffer_prepend_data(
    struct ssh_buffer_struct* buffer,
    const void* data,
    uint32_t len
);

static
void
buffer_shift(ssh_buffer buffer);

static
int
realloc_buffer(
    struct ssh_buffer_struct* buffer,
    size_t needed
);

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

void
ssh_buffer_free(struct ssh_buffer_struct* buffer);

void*
ssh_buffer_get_begin(struct ssh_buffer_struct* buffer);

uint32_t
ssh_buffer_get_len(struct ssh_buffer_struct* buffer);

int
ssh_buffer_pack_va(
    struct ssh_buffer_struct* buffer,
    const char* format,
    int argc,
    va_list ap
);

int
ssh_buffer_reinit(struct ssh_buffer_struct* buffer);

int
ssh_buffer_unpack_va(
    struct ssh_buffer_struct* buffer,
    const char* format,
    int argc,
    va_list ap
);

// macros

#define buffer_verify(x)

Detailed Documentation

Functions to handle SSH buffers.

Global Functions

LIBSSH_API ssh_buffer
ssh_buffer_new(void)

Create a new SSH buffer.

Returns:

A newly initialized SSH buffer, NULL on error.

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:

buffer

buffer to set secure.

int
ssh_buffer_validate_length(
    struct ssh_buffer_struct* buffer,
    size_t len
)

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

Parameters:

buffer

The buffer to read from.

len

The length to be checked.

Returns:

SSH_OK if the length is valid, SSH_ERROR otherwise.

void
ssh_buffer_free(struct ssh_buffer_struct* buffer)

Deallocate a SSH buffer.

Parameters:

buffer

The buffer to free.

void*
ssh_buffer_get_begin(struct ssh_buffer_struct* buffer)

Get a pointer on the head of a buffer.

Warning

Don’t expect data to be nul-terminated.

Parameters:

buffer

The buffer to get the head pointer.

Returns:

A data pointer on the head. It doesn’t take the position into account.

See also:

buffer_get_rest()

buffer_get_len()

uint32_t
ssh_buffer_get_len(struct ssh_buffer_struct* buffer)

Get the length of the buffer, not counting position.

Parameters:

buffer

The buffer to get the length from.

Returns:

The length of the buffer.

See also:

buffer_get()