Azure SDK for Embedded C
Functions
az_base64.h File Reference

Defines APIs to convert between binary data and UTF-8 encoded text that is represented in base 64. More...

#include <azure/core/az_result.h>
#include <azure/core/az_span.h>
#include <stdint.h>
#include <azure/core/_az_cfg_prefix.h>
#include <azure/core/_az_cfg_suffix.h>

Go to the source code of this file.

Functions

AZ_NODISCARD az_result az_base64_encode (az_span destination_base64_text, az_span source_bytes, int32_t *out_written)
 Encodes the span of binary data into UTF-8 encoded text represented as base 64. More...
 
AZ_NODISCARD int32_t az_base64_get_max_encoded_size (int32_t source_bytes_size)
 Returns the maximum length of the result if you were to encode an az_span of the specified length which contained binary data. More...
 
AZ_NODISCARD az_result az_base64_decode (az_span destination_bytes, az_span source_base64_text, int32_t *out_written)
 Decodes the span of UTF-8 encoded text represented as base 64 into binary data. More...
 
AZ_NODISCARD int32_t az_base64_get_max_decoded_size (int32_t source_base64_text_size)
 Returns the maximum length of the result if you were to decode an az_span of the specified length which contained base 64 encoded text. More...
 
AZ_NODISCARD az_result az_base64_url_decode (az_span destination_bytes, az_span source_base64_url_text, int32_t *out_written)
 Decodes the span of UTF-8 encoded text represented as base 64 url into binary data. More...
 
AZ_NODISCARD int32_t az_base64_url_get_max_decoded_size (int32_t source_base64_url_text_size)
 Returns the maximum length of the result if you were to decode an az_span of the specified length which contained base 64 url encoded text. More...
 

Detailed Description

Defines APIs to convert between binary data and UTF-8 encoded text that is represented in base 64.

Note
You MUST NOT use any symbols (macros, functions, structures, enums, etc.) prefixed with an underscore ('_') directly in your application code. These symbols are part of Azure SDK's internal implementation; we do not document these symbols and they are subject to change in future versions of the SDK which would break your code.

Function Documentation

◆ az_base64_decode()

AZ_NODISCARD az_result az_base64_decode ( az_span  destination_bytes,
az_span  source_base64_text,
int32_t *  out_written 
)

Decodes the span of UTF-8 encoded text represented as base 64 into binary data.

Parameters
destination_bytesThe output az_span where the decoded binary data should be copied to as a result of the operation.
[in]source_base64_textThe input az_span that contains the base 64 text to be decoded.
[out]out_writtenA pointer to an int32_t that receives the number of bytes written into the destination az_span. This can be used to slice the output for subsequent calls, if necessary.
Returns
An az_result value indicating the result of the operation.
Return values
AZ_OKSuccess.
AZ_ERROR_NOT_ENOUGH_SPACEThe destination_bytes is not large enough to contain the decoded text.
AZ_ERROR_UNEXPECTED_CHARThe input source_base64_text contains characters outside of the expected base 64 range, has invalid or more than two padding characters, or is incomplete (that is, not a multiple of 4).
AZ_ERROR_UNEXPECTED_ENDThe input source_base64_text is incomplete (that is, it is not of a size which is a multiple of 4).

◆ az_base64_encode()

AZ_NODISCARD az_result az_base64_encode ( az_span  destination_base64_text,
az_span  source_bytes,
int32_t *  out_written 
)

Encodes the span of binary data into UTF-8 encoded text represented as base 64.

Parameters
destination_base64_textThe output az_span where the encoded base 64 text should be copied to as a result of the operation.
[in]source_bytesThe input az_span that contains binary data to be encoded.
[out]out_writtenA pointer to an int32_t that receives the number of bytes written into the destination az_span. This can be used to slice the output for subsequent calls, if necessary.
Returns
An az_result value indicating the result of the operation.
Return values
AZ_OKSuccess.
AZ_ERROR_NOT_ENOUGH_SPACEThe destination_base64_text is not large enough to contain the encoded bytes.

◆ az_base64_get_max_decoded_size()

AZ_NODISCARD int32_t az_base64_get_max_decoded_size ( int32_t  source_base64_text_size)

Returns the maximum length of the result if you were to decode an az_span of the specified length which contained base 64 encoded text.

Parameters
source_base64_text_sizeThe size of the span containing base 64 encoded text.
Returns
The maximum length of the result.

◆ az_base64_get_max_encoded_size()

AZ_NODISCARD int32_t az_base64_get_max_encoded_size ( int32_t  source_bytes_size)

Returns the maximum length of the result if you were to encode an az_span of the specified length which contained binary data.

Parameters
source_bytes_sizeThe size of the span containing binary data.
Returns
The maximum length of the result.

◆ az_base64_url_decode()

AZ_NODISCARD az_result az_base64_url_decode ( az_span  destination_bytes,
az_span  source_base64_url_text,
int32_t *  out_written 
)

Decodes the span of UTF-8 encoded text represented as base 64 url into binary data.

Parameters
destination_bytesThe output az_span where the decoded binary data should be copied to as a result of the operation.
[in]source_base64_url_textThe input az_span that contains the base 64 text to be decoded.
[out]out_writtenA pointer to an int32_t that receives the number of bytes written into the destination az_span. This can be used to slice the output for subsequent calls, if necessary.
Returns
An az_result value indicating the result of the operation.
Return values
AZ_OKSuccess.
AZ_ERROR_NOT_ENOUGH_SPACEThe destination_bytes is not large enough to contain the decoded text.
AZ_ERROR_UNEXPECTED_CHARThe input source_base64_url_text contains characters outside of the expected base 64 range or is incomplete (that is, has length % 4 == 1 characters).
AZ_ERROR_UNEXPECTED_ENDThe input source_base64_url_text is incomplete (that is, it is of a size which is length % 4 == 1 characters).

◆ az_base64_url_get_max_decoded_size()

AZ_NODISCARD int32_t az_base64_url_get_max_decoded_size ( int32_t  source_base64_url_text_size)

Returns the maximum length of the result if you were to decode an az_span of the specified length which contained base 64 url encoded text.

Parameters
source_base64_url_text_sizeThe size of the span containing base 64 encoded text.
Returns
The maximum length of the result.