Void base64_encode(string & out, const uint8_t* buf, size_t bufLen) Part of file base64.hpp: void base64_encode(string & out, const vector& buf) It avoids copying the parameters at the expense of a couple of tests.Īdds some handy functions for dealing with strings, although usually the input data is binary and may have zero bytes inside, so typically should not be manipulated as a string (which often implies null-terminated data).Īlso adds some casts to fix compiler warnings (at least on GCC, I haven't run it through MSVC yet). Std::vector decoded = Base64::decode(encoded) Ī bonus here is that the decode function can also decode the URL variant of Base64 encoding. Std::string encoded = Base64::encode(buf, 4) Add the byte to the return value if it isn't part of an '=' character (indicated by 0xff) Size_t encoded_size = encoded_string.size() Make sure string length is a multiple of 4 Expand the return string size to a multiple of 4ī4 = ((b3 & 0x3f) Base64::decode(std::string encoded_string) Calculate how many bytes that needs to be added to get a multiple of 3 Std::string Base64::encode(const BYTE* buf, unsigned int bufLen) Return encode(&buf, (unsigned int)buf.size()) Return "" // Avoid dereferencing buf if it's empty Std::string Base64::encode(const std::vector& buf) Std::string base64_encode(BYTE const* buf, unsigned int bufLen) Std::vector base64_decode(std::string const&) And why have I modified it? Well, because it didn't seem appropriate to me that I should work with binary data stored within std::string object ) Here's my modification of the implementation that was originally written by René Nyffenegger.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |