/** * \file modp_b2.h * \brief Encode and decode of base 2 strings ("00001110" to 0x43) * */ /* *
* MODP_B2 -- Base 2 (binary) encode/decoder * https://github.com/client9/stringencoders * * Copyright © 2007-2016, Nick Galbreath * All rights reserved. * * Released under MIT license. See LICENSE for details. ** */ #ifndef COM_MODP_STRINGENCODERS_B2 #define COM_MODP_STRINGENCODERS_B2 #include "extern_c_begin.h" #include "modp_stdint.h" /** * encode a string into binary (base 2, '0' and '1') * * \param[out] dest the output string. Must have at least modp_b16_encode_len * bytes allocated * \param[in] str the input string * \param[in] len of the input string * \return strlen of dest */ size_t modp_b2_encode(char* dest, const char* str, size_t len); /** * Decode a hex-encoded string. * * \param[out] dest output, must have at least modp_b16_decode_len bytes allocated, * input must be a multiple of 2, and be different than the source buffer. * \param[in] src the hex encoded source * \param[in] len the length of the source * \return the length of the the output, or 0 if an error (input size not a multiple of 8) */ size_t modp_b2_decode(char* dest, const char* src, size_t len); /** * Encode length. * 2 x the length of A, round up the next high multiple of 2 * +1 for null byte added */ #define modp_b2_encode_len(A) (8 * A + 1) /** * Encode string length */ #define modp_b2_encode_strlen(A) (8 * A) /** * Decode string length */ #define modp_b2_decode_len(A) ((A + 1) / 8) #include "extern_c_end.h" #ifdef __cplusplus #include