BSL v1.1.1 - 39.g9f43410
AMMOS Bundle Protocol Security Library (BSL)
Loading...
Searching...
No Matches
TextUtil.h File Reference

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

#include "Data.h"
#include <stdint.h>
+ Include dependency graph for TextUtil.h:
+ This graph shows which files directly or indirectly include this file:

Macros

#define BSL_LOG_PLAINTEXT_PTR(title, ctx, in_ptr, in_len)
 Log plaintext as hex for debugging only when enabled by compile option BSL_LOG_PLAINTEXT_ENABLE is non-zero.
 

Functions

int BSL_TextUtil_Base16_Encode (BSL_Data_t *out, const BSL_Data_t *in, bool uppercase)
 Encode to base16 text form.
 
int BSL_TextUtil_Base16_Decode (BSL_Data_t *out, const char *ptr, size_t len)
 Decode base16 text form.
 
int BSL_TextUtil_Base64_Encode (BSL_Data_t *out, const BSL_Data_t *in, bool useurl, bool usepad)
 Encode base64 and base64url text forms.
 
int BSL_TextUtil_Base64_Decode (BSL_Data_t *out, const char *ptr, size_t len)
 Decode base64 and base64url text forms.
 

Detailed Description

This file contains definitions for text CODEC functions.

Macro Definition Documentation

◆ BSL_LOG_PLAINTEXT_PTR

#define BSL_LOG_PLAINTEXT_PTR (   title,
  ctx,
  in_ptr,
  in_len 
)

Log plaintext as hex for debugging only when enabled by compile option BSL_LOG_PLAINTEXT_ENABLE is non-zero.

Parameters
titleThe static C string title.
ctcA correlating context pointer to log.
in_ptrThe data start pointer.
in_lenThe data length.

Function Documentation

◆ BSL_TextUtil_Base16_Decode()

int BSL_TextUtil_Base16_Decode ( BSL_Data_t out,
const char *  ptr,
size_t  len 
)

Decode base16 text form.

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

Parameters
[out]outThe output buffer, which will be sized to its data.
[in]ptrThe input buffer to read, which may be null terminated. Whitespace in the input must have already been removed.
lenThe length from ptr to read, not including null terminator.
Returns
Zero upon success.

References ASSERT_ARG_NONNULL, base16_decode_char(), BSL_Data_Resize(), and BSL_Data_t::ptr.

Referenced by BSL_TestUtils_DecodeBase16_cstr(), BSLP_GetBytesHex(), test_BSL_TextUtil_Base16_Decode_invalid(), and test_BSL_TextUtil_Base16_Decode_valid().

◆ BSL_TextUtil_Base16_Encode()

int BSL_TextUtil_Base16_Encode ( BSL_Data_t out,
const BSL_Data_t in,
bool  uppercase 
)

Encode to base16 text form.

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

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

References ASSERT_ARG_NONNULL, BSL_Data_Resize(), BSL_Data_t::len, and BSL_Data_t::ptr.

Referenced by BSL_IdValPair_Print(), BSL_TestUtils_PrintHexToBuffer(), and test_BSL_TextUtil_Base16_Encode().

◆ BSL_TextUtil_Base64_Decode()

int BSL_TextUtil_Base64_Decode ( BSL_Data_t out,
const char *  ptr,
size_t  len 
)

Decode base64 and base64url text forms.

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

Parameters
[out]outThe output buffer, which will be sized to its data.
[in]ptrThe input buffer to read, which may be null terminated. Whitespace in the input must have already been removed.
lenThe length from ptr to read, not including null terminator.
Returns
Zero upon success.

References ASSERT_ARG_NONNULL, base64_decode_char(), BSL_Data_Resize(), BSL_Data_t::len, and BSL_Data_t::ptr.

Referenced by mock_bpa_key_registry_init_jwk(), test_BSL_TextUtil_Base64_Decode_invalid(), and test_BSL_TextUtil_Base64_Decode_valid().

◆ BSL_TextUtil_Base64_Encode()

int BSL_TextUtil_Base64_Encode ( BSL_Data_t out,
const BSL_Data_t in,
bool  useurl,
bool  usepad 
)

Encode base64 and base64url text forms.

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

Parameters
[out]outThe output buffer, which will be resized appropriately and null-terminated.
[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.

References ASSERT_ARG_NONNULL, base64_alphabet, base64url_alphabet, BSL_Data_Resize(), BSL_Data_t::len, and BSL_Data_t::ptr.

Referenced by TEST_CASE().