BSL v0.0.0 - 0.geda3e66
AMMOS Bundle Protocol Security Library (BSL)
Loading...
Searching...
No Matches
text_util.h File Reference

This file contains definitions for text CODEC functions. More...

#include <m-string.h>
#include <m-bstring.h>
#include <stdint.h>
+ Include dependency graph for text_util.h:
+ This graph shows which files directly or indirectly include this file:

Functions

int mock_bpa_uri_percent_encode (m_string_t out, const m_string_t in, const char *safe)
 Encode to URI percent-encoding text form.
 
int mock_bpa_uri_percent_decode (m_string_t out, const m_string_t in)
 Decode from URI percent-encoding text form.
 
int mock_bpa_slash_escape (m_string_t out, const m_string_t in, const char quote)
 Escape backslashes in tstr or bstr text form.
 
int mock_bpa_slash_unescape (m_string_t out, const m_string_t in)
 Unescape backslashes in tstr/bstr text form.
 
void mock_bpa_strip_space (m_string_t out, const char *in, size_t in_len)
 Remove whitespace characters from a text string.
 
void mock_bpa_string_tolower (m_string_t out)
 Convert a text string to lowercase.
 
void mock_bpa_string_toupper (m_string_t out)
 Convert a text string to uppercase.
 
int mock_bpa_base16_encode (m_string_t out, const m_bstring_t in, bool uppercase)
 Encode to base16 text form.
 
int mock_bpa_base16_decode (m_bstring_t out, const m_string_t in)
 Decode base16 text form.
 
int mock_bpa_base64_encode (m_string_t out, const m_bstring_t in, bool useurl, bool usepad)
 Encode base64 and base64url text forms.
 
int mock_bpa_base64_decode (m_bstring_t out, const m_string_t in)
 Decode base64 and base64url text forms.
 

Detailed Description

This file contains definitions for text CODEC functions.

Function Documentation

◆ mock_bpa_base16_decode()

int mock_bpa_base16_decode ( m_bstring_t  out,
const m_string_t  in 
)

Decode base16 text form.

This is defined in Section 8 of RFC 4648 [14].

Parameters
[out]outThe output buffer, which will be sized to its data.
[in]inThe input buffer to read, which must be null terminated. Whitespace in the input must have already been removed with strip_space().
Returns
Zero upon success.

References CHKERR1.

◆ mock_bpa_base16_encode()

int mock_bpa_base16_encode ( m_string_t  out,
const m_bstring_t  in,
bool  uppercase 
)

Encode to base16 text form.

This is defined in Section 8 of RFC 4648 [14].

Parameters
[out]outThe output buffer, which will be appended to.
[in]inThe input buffer to read.
uppercaseTrue to use upper-case letters, false to use lower-case.
Returns
Zero upon success.

◆ mock_bpa_base64_decode()

int mock_bpa_base64_decode ( m_bstring_t  out,
const m_string_t  in 
)

Decode base64 and base64url text forms.

These is defined in Section 4 and 5 of RFC 4648 [14].

Parameters
[out]outThe output buffer, which will be sized to its data.
[in]inThe input buffer to read, which must be null terminated. Whitespace in the input must have already been removed with strip_space().
Returns
Zero upon success.

References CHKERR1.

◆ mock_bpa_base64_encode()

int mock_bpa_base64_encode ( m_string_t  out,
const m_bstring_t  in,
bool  useurl,
bool  usepad 
)

Encode base64 and base64url text forms.

These is defined in Section 4 and 5 of RFC 4648 [14].

Parameters
[out]outThe output buffer, which will be appended to.
[in]inThe input buffer to read.
useurlTrue to use the base64url alphabet, false to use the base64 alphabet.
usepadTrue to include padding characters (=), false to not use padding.
Returns
Zero upon success.

◆ mock_bpa_slash_escape()

int mock_bpa_slash_escape ( m_string_t  out,
const m_string_t  in,
const char  quote 
)

Escape backslashes in tstr or bstr text form.

This is defined in Section G.2 of RFC 8610 [2] and Section 7 of RFC 8259 [5].

Parameters
[out]outThe output buffer, which will be appended to.
inThe input buffer to read, which must be null terminated.
quoteThe character used to quote the string.
Returns
Zero upon success.

References CHKERR1.

◆ mock_bpa_slash_unescape()

int mock_bpa_slash_unescape ( m_string_t  out,
const m_string_t  in 
)

Unescape backslashes in tstr/bstr text form.

This is defined in Section G.2 of RFC8610 [2].

Parameters
[out]outThe output buffer, which will be appended to.
inThe input buffer to read, which may be null terminated.
Returns
Zero upon success.

References CHKERR1.

◆ mock_bpa_string_tolower()

void mock_bpa_string_tolower ( m_string_t  out)

Convert a text string to lowercase.

This is written to work on byte strings, not unicode.

Parameters
[out]outThe output buffer, which will be replaced.

References CHKVOID.

◆ mock_bpa_string_toupper()

void mock_bpa_string_toupper ( m_string_t  out)

Convert a text string to uppercase.

This is written to work on byte strings, not unicode.

Parameters
[out]outThe output buffer, which will be replaced.

References CHKVOID.

◆ mock_bpa_strip_space()

void mock_bpa_strip_space ( m_string_t  out,
const char *  in,
size_t  in_len 
)

Remove whitespace characters from a text string.

This is based on isspace() inspection.

Parameters
[out]outThe output buffer, which will be replaced.
[in]inThe input text to read.
in_lenThe length of text not including null terminator.

◆ mock_bpa_uri_percent_decode()

int mock_bpa_uri_percent_decode ( m_string_t  out,
const m_string_t  in 
)

Decode from URI percent-encoding text form.

This is defined in Section 2.1 of RFC 3986 [1].

Parameters
[out]outThe output buffer, which will be appended to.
[in]inThe input encoded text which may be null-terminated.
Returns
Zero upon success.

References CHKERR1.

◆ mock_bpa_uri_percent_encode()

int mock_bpa_uri_percent_encode ( m_string_t  out,
const m_string_t  in,
const char *  safe 
)

Encode to URI percent-encoding text form.

This is defined in Section 2.1 of RFC 3986 [1]. The set of unreserved characters are alpha, digits, and _.-~ characters. in accordance with Section 2.3 of RFC 3986 [1].

Parameters
[out]outThe output buffer, which will be appended to.
inThe input encoded text which is null-terminated.
safeA set of additional safe characters to not be encoded, which is null-terminated.
Returns
Zero upon success.

References CHKERR1.