Function rcutils_decode_base64

Function Documentation

rcutils_ret_t rcutils_decode_base64(const char *base64_str, rcutils_uint8_array_t *byte_array, const rcutils_allocator_t *allocator)

Decode a base64-encoded string into a byte array.

This function converts a base64-encoded string into its original binary representation. Base64 encoding uses 4 ASCII characters to represent 3 bytes of data.

Parameters:
  • base64_str – The null-terminated base64 string to decode.

  • byte_array – Pointer to rcutils_uint8_array_t to store the decoded byte array (output). The array must be zero-initialized by rcutils_get_zero_initialized_uint8_array before calling this function.

  • allocator – The allocator to use for memory allocation.

Returns:

RCUTILS_RET_OK on success.

Returns:

RCUTILS_RET_INVALID_ARGUMENT if base64_str is NULL, or if byte_array is NULL, or if allocator is NULL or invalid, or if byte_array is not zero-initialized.

Returns:

RCUTILS_RET_ERROR if base64 string length exceeds RCUTILS_BASE64_ENCODED_MAX_LENGTH, or if base64 string length is not a multiple of 4, or if base64 string contains invalid characters, or if base64 string has invalid padding.

Returns:

RCUTILS_RET_BAD_ALLOC if memory allocation fails.