Base64

Public API for decoding

bde_error_t bde_base64_decode_length(const bde_enc_t *const encoded, const size_t encoded_len, size_t *const decoded_len)

Obtains the length of the decoded data from the length of the Base64 encoded string.

This function does not check if the Base64 encoded string contains invalid data.

Parameters:
  • encoded[in] Base64 encoded string, if NULL a worst case length is returned to accomodate maximum padding.

  • encoded_len[in] Length of the Base64 encoded string, not including the NULL terminator.

  • decoded_len[out] Length of the decoded data.

Return values:
  • bde_error_ok – Success.

  • bde_error_args – Invalid arguments.

  • bde_error_encoded_string – The Base64 encoded string has an invalid form.

bde_error_t bde_base64_decode(const bde_enc_t *const encoded, const size_t encoded_len, const size_t decoded_max_len, bde_dec_t *const decoded, size_t *const decoded_len)

Obtains the decoded data from the Base64 encoded string.

This function can decode inplace, it is possible to use the same buffer for the encoded and decoded data.

Parameters:
  • encoded[in] Base64 encoded string.

  • encoded_len[in] Length of encoded, not including the NULL terminator.

  • decoded_max_len[in] Length of decoded.

  • decoded[out] Buffer where the decoded data will be written.

  • decoded_len[out] Amount of data written to decoded, can be NULL if not required by caller.

Return values:
  • bde_error_ok – Success.

  • bde_error_args – Invalid arguments.

  • bde_error_encoded_string – The Base64 encoded string given is not valid.

Public API for encoding

bde_error_t bde_base64_encode_length(const size_t decoded_len, size_t *const encoded_len)

Obtains the length of the Base64 encoded string from the length of the decoded data.

Parameters:
  • decoded_len[in] Length of the decoded data.

  • encoded_len[out] Length of the Base64 encoded string, not including the NULL terminator.

Return values:
  • bde_error_ok – Success.

  • bde_error_args – Invalid arguments.

bde_error_t bde_base64_encode(const bde_dec_t *const decoded, const size_t decoded_len, const size_t encoded_max_len, bde_enc_t *const encoded, size_t *const encoded_len)

Obtains the Base64 encoded string from the decoded data.

This function can encode inplace, it is possible to use the same buffer for the encoded and decoded data.

Parameters:
  • decoded[in] Decoded data.

  • decoded_len[in] Length of decoded.

  • encoded_max_len[in] Length of encoded.

  • encoded[out] Buffer where the Base64 encoded string and the NULL terminator will be written.

  • encoded_len[out] Amount of data written to encoded, not including the NULL terminator, can be NULL if not required by caller.

Return values:
  • bde_error_ok – Success.

  • bde_error_args – Invalid arguments.