|
BSL v1.0.0 - 16.g9d98179
AMMOS Bundle Protocol Security Library (BSL)
|
#include "text_util.h"#include <BPSecLib_Private.h>#include <string.h>#include <strings.h>#include <inttypes.h>#include <stdlib.h>#include <math.h>
Include dependency graph for text_util.c:Functions | |
| static int | take_hex_1byte (uint8_t *out, const char **curs, const char *end) |
| static int | take_hex_2byte (uint16_t *out, const char **curs, const char *end) |
| 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. | |
| static void | strip_chars (m_string_t out, const char *in, size_t in_len, const char *chars) |
| 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. | |
| static int | base16_decode_char (uint8_t chr) |
| Decode a single character. | |
| 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. | |
| static int | base64_decode_char (uint8_t chr) |
| Decode a single character. | |
| int | mock_bpa_base64_decode (m_bstring_t out, const m_string_t in) |
| Decode base64 and base64url text forms. | |
Variables | |
| static const char * | unreserved = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_.-~" |
| Set of unreserved characters from Section 2.3 of RFC 3986 [1]. | |
| static const size_t | base16_decode_lim = 0x80 |
| Size of the base16_decode_table. | |
| static const int | base16_decode_table [0x80] |
| Decode table for base16. | |
| static const char * | base64_alphabet |
| static const char * | base64url_alphabet |
| static const size_t | base64_decode_lim = 0x80 |
| Size of the base16_decode_table. | |
| static const int | base64_decode_table [0x80] |
| Decode table for base64 and base64uri. | |
|
static |
Decode a single character.
| chr | The character to decode. |
References base16_decode_lim, and base16_decode_table.
Referenced by mock_bpa_base16_decode().
|
static |
Decode a single character.
| chr | The character to decode. |
References base64_decode_lim, and base64_decode_table.
Referenced by mock_bpa_base64_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 [15].
| [out] | out | The output buffer, which will be sized to its data. |
| [in] | in | The input buffer to read, which must be null terminated. Whitespace in the input must have already been removed with strip_space(). |
References base16_decode_char(), and BSL_CHKERR1.
Referenced by test_mock_bpa_base16_decode_invalid(), and test_mock_bpa_base16_decode_valid().
| 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 [15].
| [out] | out | The output buffer, which will be appended to. |
| [in] | in | The input buffer to read. |
| uppercase | True to use upper-case letters, false to use lower-case. |
Referenced by test_mock_bpa_base16_encode().
| 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 [15].
| [out] | out | The output buffer, which will be sized to its data. |
| [in] | in | The input buffer to read, which must be null terminated. Whitespace in the input must have already been removed with strip_space(). |
References base64_decode_char(), and BSL_CHKERR1.
Referenced by mock_bpa_key_registry_init(), test_mock_bpa_base64_decode_invalid(), and test_mock_bpa_base64_decode_valid().
| 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 [15].
| [out] | out | The output buffer, which will be appended to. |
| [in] | in | The input buffer to read. |
| useurl | True to use the base64url alphabet, false to use the base64 alphabet. | |
| usepad | True to include padding characters (=), false to not use padding. |
References base64_alphabet, and base64url_alphabet.
Referenced by TEST_CASE().
| 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].
| [out] | out | The output buffer, which will be appended to. |
| in | The input buffer to read, which must be null terminated. | |
| quote | The character used to quote the string. |
References BSL_CHKERR1.
Referenced by test_mock_bpa_slash_escape_valid().
| 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].
| [out] | out | The output buffer, which will be appended to. |
| in | The input buffer to read, which may be null terminated. |
References BSL_CHKERR1, and take_hex_2byte().
Referenced by test_mock_bpa_slash_unescape_invalid(), and test_mock_bpa_slash_unescape_valid().
| 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.
| [out] | out | The output buffer, which will be replaced. |
References BSL_CHKVOID.
| 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.
| [out] | out | The output buffer, which will be replaced. |
References BSL_CHKVOID.
| 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.
| [out] | out | The output buffer, which will be replaced. |
| [in] | in | The input text to read. |
| in_len | The length of text not including null terminator. |
References strip_chars().
| 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].
| [out] | out | The output buffer, which will be appended to. |
| [in] | in | The input encoded text which may be null-terminated. |
References BSL_CHKERR1, and take_hex_1byte().
Referenced by test_mock_bpa_uri_percent_decode_invalid(), and test_mock_bpa_uri_percent_decode_valid().
| 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].
| [out] | out | The output buffer, which will be appended to. |
| in | The input encoded text which is null-terminated. | |
| safe | A set of additional safe characters to not be encoded, which is null-terminated. |
References BSL_CHKERR1, and unreserved.
Referenced by test_mock_bpa_uri_percent_encode_valid().
|
static |
Referenced by mock_bpa_strip_space().
|
static |
References buf.
Referenced by mock_bpa_uri_percent_decode().
|
static |
References buf.
Referenced by mock_bpa_slash_unescape().
|
static |
Size of the base16_decode_table.
Referenced by base16_decode_char().
|
static |
Decode table for base16.
Referenced by base16_decode_char().
|
static |
Referenced by mock_bpa_base64_encode().
|
static |
Size of the base16_decode_table.
Referenced by base64_decode_char().
|
static |
Decode table for base64 and base64uri.
Referenced by base64_decode_char().
|
static |
Referenced by mock_bpa_base64_encode().
|
static |
Set of unreserved characters from Section 2.3 of RFC 3986 [1].
Referenced by mock_bpa_uri_percent_encode().