Digest-BLAKE2
view release on metacpan or search on metacpan
stringencoders/modp_b64r.h view on Meta::CPAN
* return false;
* }
* }
* // foo is filled out now
* \endcode
*/
#define modp_b64r_encode_strlen(A) ((A + 2)/ 3 * 4)
END_C
#ifdef __cplusplus
#include <cstring>
#include <string>
namespace modp {
/** \brief b64r encode a cstr with len
*
* \param[in] s the input string to encode
* \param[in] len the length of the input string
* \return a newly allocated b64r string. Empty if failed.
*/
inline std::string b64r_encode(const char* s, size_t len)
{
std::string x(modp_b64r_encode_len(len), '\0');
size_t d = modp_b64r_encode(const_cast<char*>(x.data()), s,
static_cast<int>(len));
if (d == (size_t)-1) {
x.clear();
} else {
x.erase(d, std::string::npos);
}
return x;
}
/** \brief b64r encode a cstr
*
* \param[in] s the input string to encode
* \return a newly allocated b64r string. Empty if failed.
*/
inline std::string b64r_encode(const char* s)
{
return b64r_encode(s, static_cast<int>(strlen(s)));
}
/** \brief b64r encode a const std::string
*
* \param[in] s the input string to encode
* \return a newly allocated b64r string. Empty if failed.
*/
inline std::string b64r_encode(const std::string& s)
{
return b64r_encode(s.data(), s.size());
}
/** \brief self-modifing b64r encode
*
* web-safe base 64 decode a string (self-modifing)
* On failure, the string is empty.
*
* \param[in,out] s the string to be decoded
* \return a reference to the input string
*/
inline std::string& b64r_encode(std::string& s)
{
std::string x(b64r_encode(s.data(), s.size()));
s.swap(x);
return s;
}
inline std::string b64r_decode(const char* src, size_t len)
{
std::string x(modp_b64r_decode_len(len)+1, '\0');
size_t d = modp_b64r_decode(const_cast<char*>(x.data()), src,
static_cast<int>(len));
if (d == (size_t)-1) {
x.clear();
} else {
x.erase(d, std::string::npos);
}
return x;
}
inline std::string b64r_decode(const char* src)
{
return b64r_decode(src, strlen(src));
}
/**
* base 64 decode a string (self-modifing)
* On failure, the string is empty.
*
* This function is for C++ only (duh)
*
* \param[in,out] s the string to be decoded
* \return a reference to the input string
*/
inline std::string& b64r_decode(std::string& s)
{
std::string x(b64r_decode(s.data(), s.size()));
s.swap(x);
return s;
}
inline std::string b64r_decode(const std::string& s)
{
return b64r_decode(s.data(), s.size());
}
}
#endif /* __cplusplus */
#endif /* MODP_B64R */
( run in 0.415 second using v1.01-cache-2.11-cpan-39bf76dae61 )