
Hello! I've run into a strange problem with encoding/decoding base64. Let's have a look at the following code: ///////////////////////////////////////////////////////// #include "boost/archive/iterators/base64_from_binary.hpp" #include "boost/archive/iterators/binary_from_base64.hpp" #include "boost/archive/iterators/transform_width.hpp" #include <string> #include <iostream> using namespace std; using namespace boost::archive::iterators; typedef base64_from_binary< transform_width<string::const_iterator, 6, 8> > base64_t; typedef transform_width< binary_from_base64<string::const_iterator>, 8, 6 > binary_t; int main() { string str("Hello, world!"); cout << str << endl; // This works quite well. string enc(base64_t(str.begin()), base64_t(str.end())); cout << enc << endl; // The following call throws an exception about unacceptable // base64 character in the stream. Probably a bug? //string dec(binary_t(enc.begin()), binary_t(enc.end())); // Hackish workaround: string dec( binary_t(enc.begin()), binary_t(enc.begin() + enc.length() - 1) ); cout << dec << endl; return 0; } ////////////////////////////////////////////////////////////// Does those transforming iterators work as expected? Why the tailoring zero is included in the transformation process? Is there a better way to workaround the problem? Thanks in advance! -- Anatoli Sakhnik.