The SSH string functions

Overview

String manipulations used in libssh. More…

// global functions

void
ssh_string_free_char(char* s);

ssh_string
ssh_string_from_char(const char* what);

ssh_string
ssh_string_new(size_t size);

void
ssh_string_burn(struct ssh_string_struct* s);

struct ssh_string_struct*
ssh_string_copy(struct ssh_string_struct* s);

void*
ssh_string_data(struct ssh_string_struct* s);

int
ssh_string_fill(
    struct ssh_string_struct* s,
    const void* data,
    size_t len
);

void
ssh_string_free(struct ssh_string_struct* s);

const char*
ssh_string_get_char(struct ssh_string_struct* s);

size_t
ssh_string_len(struct ssh_string_struct* s);

char*
ssh_string_to_char(struct ssh_string_struct* s);

Detailed Documentation

String manipulations used in libssh.

Global Functions

void
ssh_string_free_char(char* s)

Deallocate a char string object.

Parameters:

s

The string to delete.

ssh_string
ssh_string_from_char(const char* what)

Create a ssh string using a C string.

Note

The nul byte is not copied nor counted in the ouput string.

Parameters:

what

The source 0-terminated C string.

Returns:

The newly allocated string, NULL on error with errno set.

ssh_string
ssh_string_new(size_t size)

Create a new SSH String object.

Parameters:

size

The size of the string.

Returns:

The newly allocated string, NULL on error.

void
ssh_string_burn(struct ssh_string_struct* s)

Destroy the data in a string so it couldn’t appear in a core dump.

Parameters:

s

The string to burn.

struct ssh_string_struct*
ssh_string_copy(struct ssh_string_struct* s)

Copy a string, return a newly allocated string.

The caller has to free the string.

Parameters:

s

String to copy.

Returns:

Newly allocated copy of the string, NULL on error.

void*
ssh_string_data(struct ssh_string_struct* s)

Get the payload of the string.

Parameters:

s

The string to get the data from.

Returns:

Return the data of the string or NULL on error.

int
ssh_string_fill(
    struct ssh_string_struct* s,
    const void* data,
    size_t len
)

Fill a string with given data.

The string should be big enough.

Parameters:

s

An allocated string to fill with data.

data

The data to fill the string with.

len

Size of data.

Returns:

0 on success, < 0 on error.

void
ssh_string_free(struct ssh_string_struct* s)

Deallocate a SSH string object.

Parameters:

s

The SSH string to delete.

const char*
ssh_string_get_char(struct ssh_string_struct* s)

Get the the string as a C nul-terminated string.

This is only available as long as the SSH string exists.

Parameters:

s

The SSH string to get the C string from.

Returns:

The char pointer, NULL on error.

size_t
ssh_string_len(struct ssh_string_struct* s)

Return the size of a SSH string.

Parameters:

s

The the input SSH string.

Returns:

The size of the content of the string, 0 on error.

char*
ssh_string_to_char(struct ssh_string_struct* s)

Convert a SSH string to a C nul-terminated string.

Note

If the input SSH string contains zeroes, some parts of the output string may not be readable with regular libc functions.

Parameters:

s

The SSH input string.

Returns:

An allocated string pointer, NULL on error with errno set.