Base64¶
An xsd:base64Binary is arbitrary binary data in base64 encoding.
-
size_t
exess_base64_decoded_size
(size_t length)¶ Return the maximum number of bytes required to decode
length
bytes of base64.The returned value is an upper bound which is only exact for canonical strings.
- Parameters
length – The number of input (text) bytes to decode.
- Returns
The size of a decoded value in bytes.
-
ExessResult
exess_read_base64
(ExessBlob *out, const char *str)¶ Read a binary value from a base64 string.
Canonical syntax is a multiple of 4 base64 characters, with either 1 or 2 trailing “=” characters as necessary, like “Zm9vYg==”, with no whitespace. All whitespace is skipped when reading.
The caller must allocate a large enough buffer to read the value, otherwise an
ExessStatus.EXESS_NO_SPACE
error will be returned. The required space can be calculated withexess_base64_decoded_size()
.When this is called, the output blob must have the size of the available buffer in bytes, and a pointer to the buffer. On return, the size will be set to the exact size of the decoded data, which may be smaller than the initial available size. Only these first bytes are written, the rest of the buffer is not modified.
- Parameters
out – The blob to set to the decoded binary data.
str – String to parse.
- Returns
The
count
of characters read, and astatus
code.
-
ExessResult
exess_write_base64
(size_t data_size, const void *data, size_t buf_size, char *buf)¶ Write a canonical xsd:base64Binary string.
The data is always written in canonical form, as a multiple of 4 characters with no whitespace and 1 or 2 trailing “=” characters as padding if necessary.
- Parameters
data_size – The size of
data
in bytes.data – Data to write to a string.
buf_size – The size of
buf
in bytes.buf – Output buffer, or null to only measure.
- Returns
The
count
of characters in the output, andstatus
ExessStatus.EXESS_SUCCESS
, orExessStatus.EXESS_NO_SPACE
if the buffer is too small.