Hello. I was testing the base64stream and I realized it doesn't work correctly with binary data. The unit test used in cxxtools source is applied only with small ascii strings.
I'm sending an example which reproduces the error. first I calculated the expected base64 string of an image (attached) with the command line $ base64 -w0 < test_image.jpg # I also tested with the mono (c#) base64 package having the same correct results I tested it in two intel machines with ubuntu and compiled with gcc. One is 32-bit and another is 64-bit. The problem happens in both. The expected string os the example is: /9j/4AAQSkZJRgABAQEASABIAAD//gANTGF2YzUzLjQyLjT/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh7/wAARCAASABcDASIAAhEBAxEB/8QAGAABAQEBAQAAAAAAAAAAAAAAAAIEAwf/xAAhEAABBAEDBQAAAAAAAAAAAAAAAQIDEiEEESITMTJCQ//EABcBAQEBAQAAAAAAAAAAAAAAAAACAQT/xAAVEQEBAAAAAAAAAAAAAAAAAAAAEf/aAAwDAQACEQMRAD8A9F6teW2fUyvlzmpE7stQmt12edMFSamNqefIEyxRurgGDTMiHH7MAKB/YAEj/9k= But the result, via Base64Stream is: /tf/4AAQSkZJRgABAQEASABIAA///gANTGF2YzUzLjQyLjP/2wBDAAUDBAQEAwUEBAQFBQUGBwwIBwcHBw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx3/2wBDAQUFBQcGBw4ICA4eFBEUHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh3/wAARCAASABcDASIAAhEBAxEB/sQAGAABAQEBAQAAAAAAAAAAAAAAAAIEAwb/xAAhEAABBAEDBQAAAAAAAAAAAAAAAQIDEiEEESITMTJCQv7EABcBAQEBAQAAAAAAAAAAAAAAAAACAQP/xAAVEQEBAAAAAAAAAAAAAAAAAAAAEP7aAAwDAQACEQMRAD8A9F2teWyfUyrlzmpE7ctQmd12eNMFSKiNqObIEyxRubgGDTMiHH3MA6B/YAEj/tk= The two strings are very close (they also have same lenght), but there are some different characters. I'm also sending a simple program in c# (i tested with mono on linux) which does the correct encoding. It receives the binary file as parameter and prints the base64 string on sceren. $ cli-csc Main.cs $ mono Main.exe test_image.jpg Thanks in advance -- ----- Sent from my Atari
<<attachment: test_image.jpg>>
#include <cxxtools/base64stream.h>
#include <string>
#include <sstream>
using namespace cxxtools;
using namespace std;
#define IMAGESIZE 362
// The image content
const char imageData[IMAGESIZE] = {
-1, -40, -1, -32, 0, 16, 74, 70, 73, 70,
0, 1, 1, 1, 0, 72, 0, 72, 0, 0,
-1, -2, 0, 13, 76, 97, 118, 99, 53, 51,
46, 52, 50, 46, 52, -1, -37, 0, 67, 0,
5, 3, 4, 4, 4, 3, 5, 4, 4, 4,
5, 5, 5, 6, 7, 12, 8, 7, 7, 7,
7, 15, 11, 11, 9, 12, 17, 15, 18, 18,
17, 15, 17, 17, 19, 22, 28, 23, 19, 20,
26, 21, 17, 17, 24, 33, 24, 26, 29, 29,
31, 31, 31, 19, 23, 34, 36, 34, 30, 36,
28, 30, 31, 30, -1, -37, 0, 67, 1, 5,
5, 5, 7, 6, 7, 14, 8, 8, 14, 30,
20, 17, 20, 30, 30, 30, 30, 30, 30, 30,
30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
30, 30, 30, 30, 30, 30, 30, 30, 30, 30,
30, 30, 30, -1, -64, 0, 17, 8, 0, 18,
0, 23, 3, 1, 34, 0, 2, 17, 1, 3,
17, 1, -1, -60, 0, 24, 0, 1, 1, 1,
1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 2, 4, 3, 7, -1, -60,
0, 33, 16, 0, 1, 4, 1, 3, 5, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
1, 2, 3, 18, 33, 4, 17, 34, 19, 49,
50, 66, 67, -1, -60, 0, 23, 1, 1, 1,
1, 1, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 2, 1, 4, -1, -60,
0, 21, 17, 1, 1, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
17, -1, -38, 0, 12, 3, 1, 0, 2, 17,
3, 17, 0, 63, 0, -12, 94, -83, 121, 109,
-97, 83, 43, -27, -50, 106, 68, -18, -53, 80,
-102, -35, 118, 121, -45, 5, 73, -87, -115, -87,
-25, -56, 19, 44, 81, -70, -72, 6, 13, 51,
34, 28, 126, -52, 0, -96, 127, 96, 1, 35,
-1, -39
};
// the expected base64 value
string expectedBase64 =
"/9j/4AAQSkZJRgABAQEASABIAAD//gANTGF2YzUzLjQyLjT/2wBDAAUDBAQEAwUEBAQFBQUGBwwI"
"BwcHBw8LCwkMEQ8SEhEPERETFhwXExQaFRERGCEYGh0dHx8fExciJCIeJBweHx7/2wBDAQUFBQcG"
"Bw4ICA4eFBEUHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4eHh4e"
"Hh7/wAARCAASABcDASIAAhEBAxEB/8QAGAABAQEBAQAAAAAAAAAAAAAAAAIEAwf/xAAhEAABBAED"
"BQAAAAAAAAAAAAAAAQIDEiEEESITMTJCQ//EABcBAQEBAQAAAAAAAAAAAAAAAAACAQT/xAAVEQEB"
"AAAAAAAAAAAAAAAAAAAAEf/aAAwDAQACEQMRAD8A9F6teW2fUyvlzmpE7stQmt12edMFSamNqefI"
"EyxRurgGDTMiHH7MAKB/YAEj/9k=";
void testEncoding()
{
// the data in stl string
string strData(imageData,IMAGESIZE);
ostringstream ss;
Base64ostream os(ss);
os << strData;
os.terminate();
cout << "Expected base64: " << endl << expectedBase64 << endl << endl;
cout << "Calculated base64: " << endl << ss.str() << endl;
cout << endl;
cout << "Encoding: " << (expectedBase64 == ss.str() ? "OK" : "FAIL") << endl;
}
void testDecoding()
{
// the data in stl string
string strData(imageData,IMAGESIZE);
stringstream ss;
ss << expectedBase64;
Base64istream is(ss);
string data;
is >> data;
cout << "Decoding: " << (strData == data ? "OK" : "FAIL") << endl;
}
int main(int argc, char **argv)
{
testEncoding();
testDecoding();
}
Main.cs
Description: Binary data
------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________ Tntnet-general mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/tntnet-general
