|
size_t | M_bincodec_encode_size (size_t inLen, size_t wrap, M_bincodec_codec_t codec) |
|
char * | M_bincodec_encode_alloc (const M_uint8 *in, size_t inLen, size_t wrap, M_bincodec_codec_t codec) M_WARN_UNUSED_RESULT M_MALLOC |
|
size_t | M_bincodec_encode (char *out, size_t outLen, const M_uint8 *in, size_t inLen, size_t wrap, M_bincodec_codec_t codec) |
|
size_t | M_bincodec_decode_size (size_t inLen, M_bincodec_codec_t codec) |
|
M_uint8 * | M_bincodec_decode_alloc (const char *in, size_t inLen, size_t *outLen, M_bincodec_codec_t codec) M_WARN_UNUSED_RESULT M_MALLOC |
|
char * | M_bincodec_decode_str_alloc (const char *in, M_bincodec_codec_t codec) |
|
size_t | M_bincodec_decode (M_uint8 *out, size_t outLen, const char *in, size_t inLen, M_bincodec_codec_t codec) |
|
char * | M_bincodec_convert_alloc (const char *in, size_t inLen, size_t wrap, M_bincodec_codec_t inCodec, M_bincodec_codec_t outCodec) M_WARN_UNUSED_RESULT M_MALLOC |
|
size_t | M_bincodec_convert (char *out, size_t outLen, size_t wrap, M_bincodec_codec_t outCodec, const char *in, size_t inLen, M_bincodec_codec_t inCodec) |
|
Text to binary and binary to text conversion. Supports conversion of binary to or from base64 or hex.
Example:
const char *data = "abcd";
char *out[16];
char *odata;
M_uint8 * M_bincodec_decode_alloc(const char *in, size_t inLen, size_t *outLen, M_bincodec_codec_t codec) M_WARN_UNUSED_RESULT M_MALLOC
size_t M_bincodec_encode(char *out, size_t outLen, const M_uint8 *in, size_t inLen, size_t wrap, M_bincodec_codec_t codec)
@ M_BINCODEC_BASE64ORHEX
Definition: m_bincodec.h:70
@ M_BINCODEC_HEX
Definition: m_bincodec.h:69
@ M_BINCODEC_BASE64
Definition: m_bincodec.h:68
ssize_t M_printf(const char *fmt,...)
void M_free(void *ptr) M_FREE(1)
size_t M_str_len(const char *s) M_WARN_UNUSED_RESULT
◆ M_BINCODEC_PEM_LINE_LEN
#define M_BINCODEC_PEM_LINE_LEN 64 |
◆ M_bincodec_codec_t
Binary conversion types.
Enumerator |
---|
M_BINCODEC_BASE64 | Base64 encoding.
|
M_BINCODEC_HEX | Hex encoding.
|
M_BINCODEC_BASE64ORHEX | Auto detected between base64 and hex encoding.
|
M_BINCODEC_BASE32 | Base32 encoding.
|
◆ M_bincodec_encode_size()
The maximum number of bytes necessary to encode using the specified codec.
- Parameters
-
[in] | inLen | Number of bytes that will be passed to the encoder. |
[in] | wrap | The maximum length of a given line. Longer lines will be split with a new line. Pass 0 if line splitting is not desired. |
[in] | codec | The binary codec that will be used for encoding. |
- Returns
- The maximum number of bytes needed to store the data after encoding.
◆ M_bincodec_encode_alloc()
char * M_bincodec_encode_alloc |
( |
const M_uint8 * |
in, |
|
|
size_t |
inLen, |
|
|
size_t |
wrap, |
|
|
M_bincodec_codec_t |
codec |
|
) |
| |
Encodes data passed into it using the specified binary codec.
- Parameters
-
[in] | in | The binary data to encode. |
[in] | inLen | The length of the input data. |
[in] | wrap | The maximum length of a given line. Longer lines will be split with a new line. Pass 0 if line splitting is not desired. |
[in] | codec | The binary codec to use for encoding. |
- Returns
- A new NULL terminated string with the encoded data. Otherwise NULL on error.
- See also
- M_free
◆ M_bincodec_encode()
size_t M_bincodec_encode |
( |
char * |
out, |
|
|
size_t |
outLen, |
|
|
const M_uint8 * |
in, |
|
|
size_t |
inLen, |
|
|
size_t |
wrap, |
|
|
M_bincodec_codec_t |
codec |
|
) |
| |
Encodes data passed into it using the specified binary codec.
- Parameters
-
[out] | out | A buffer large enough to hold the encoded data. |
[in] | outLen | The length of the output buffer. |
[in] | in | The binary data to encode. |
[in] | inLen | The length of the input data. |
[in] | wrap | The maximum length of a given line. Longer lines will be split with a new line. Pass 0 if line splitting is not desired. |
[in] | codec | The binary codec to use for encoding. |
- Returns
- The number of bytes written into the output buffer.
◆ M_bincodec_decode_size()
The maximum number of bytes necessary to encode using the specified codec.
- Parameters
-
[in] | inLen | Number of bytes that will be passed to the decoder. |
[in] | codec | The binary codec that will be used for decoding. |
- Returns
- The maximum number of bytes needed to store the data after decoding.
◆ M_bincodec_decode_alloc()
M_uint8 * M_bincodec_decode_alloc |
( |
const char * |
in, |
|
|
size_t |
inLen, |
|
|
size_t * |
outLen, |
|
|
M_bincodec_codec_t |
codec |
|
) |
| |
Decodes data passed into it using the specified binary codec.
- Parameters
-
[in] | in | The string data to decode. |
[in] | inLen | The length of the input data. |
[out] | outLen | The length ouf the buffer. |
[in] | codec | The binary codec to use for decoding. |
- Returns
- A new array with the decoded data. Otherwise NULL on error.
- See also
- M_free
◆ M_bincodec_decode_str_alloc()
Convenience function for validating decoded data is a string. Some protocols may encode string data even if it is not necessary, so this function helps validate that data is really in string form to prevent issues.
- Parameters
-
[in] | in | The string data to decode. |
[in] | codec | The binary codec to use for decoding. |
- Returns
- A new buffer with decoded data, otherwise NULL on error.
◆ M_bincodec_decode()
size_t M_bincodec_decode |
( |
M_uint8 * |
out, |
|
|
size_t |
outLen, |
|
|
const char * |
in, |
|
|
size_t |
inLen, |
|
|
M_bincodec_codec_t |
codec |
|
) |
| |
Decodes data passed into it using the specified binary codec.
- Parameters
-
[out] | out | A buffer large enought to hold the decoded data. |
[in] | outLen | The length of the output buffer. |
[in] | in | The string data to decode. |
[in] | inLen | The length of the input data. |
[in] | codec | The binary codec to use for decoding. |
- Returns
- The number of bytes written into the output buffer, or 0 on error.
◆ M_bincodec_convert_alloc()
Convert a string from one binary encoding to another.
A conversion will always be performed even when using the same input and output codecs.
- Parameters
-
[in] | in | The data to convert. |
[in] | inLen | The length of the input data. |
[in] | wrap | The maximum length of a given line. Longer lines will be split with a new line. Pass 0 if line splitting is not desired. |
[in] | inCodec | The format the input data is encoded using. |
[in] | outCodec | The output format to convert into. |
- Returns
- A new NULL terminated string with the converted data. Otherwise NULL on error.
- See also
- M_free
◆ M_bincodec_convert()
Convert a string from one binary encoding to another.
A conversion will always be performed even when using the same input and output codecs.
- Parameters
-
[out] | out | A buffer large enought to hold the converted data. |
[in] | outLen | The length of the output buffer. |
[in] | wrap | The maximum length of a given line. Longer lines will be split with a new line. Pass 0 if line splitting is not desired. |
[in] | outCodec | The output format to convert into. |
[in] | in | The data to convert. |
[in] | inLen | The length of the input data. |
[in] | inCodec | The format the input data is encoded using. |
- Returns
- The number of bytes written into the output buffer.