|
Boost Users : |
From: Anatoli Sakhnik (sakhnik_at_[hidden])
Date: 2007-04-11 06:09:01
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.
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net