You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@santuario.apache.org by Milan Tomic <mi...@setcce.org> on 2004/01/26 17:00:40 UTC

Base64

	Is this OK:

CString cEncodedFile;
XSCryptCryptoBase64 b64;
b64.encodeInit();
CFile f;
f.Open(cXMLFile.GetBuffer(999), CFile::modeRead);
int outLen = 10 * 1024 * 4/3 + 4;
BYTE *input = new BYTE[10 * 1024];
BYTE *output = new BYTE[outLen];
int inputSz = f.Read(input, 10 * 1024); int outputSz = 0;

while (inputSz > 0) {
	outputSz = b64.encode(input, inputSz, output, outLen );
	CString tmp = CString((char*) output, outputSz);
	cEncodedFile += tmp;
	inputSz = f.Read(input, 10 * 1024);
}

outputSz = b64.encodeFinish(output, outLen - outputSz);
//write_to_wherever(output, outputSz);
CString tmp = CString((char*) output, outputSz);
cEncodedFile += tmp;

I'm missing 1K at the end. :(

Re: Base64

Posted by Berin Lautenbach <be...@wingsofhermes.org>.
Which smells to be like a bug in the code.  If we are dropping bytes 
without either

a) throwing an exception; or
b) storing them in a buffer to be retrieved on the next call to ::encode()

then I think something is wrong.

I will have a look at this.

Thanks!

Cheers,
	Berin


Milan Tomic wrote:
> 	I've found solution. This:
> 
> int outLen = 10 * 1024 * 4/3 + 4;
> 
> 	should be:
> 
> int outLen = 10 * 1024 * 2;
> 
> 	there was no enough space in output baffer.
> 
> Thank you,
> Milan
> 
> 
> 
> 


RE: Base64

Posted by Milan Tomic <mi...@setcce.org>.
	I've found solution. This:

int outLen = 10 * 1024 * 4/3 + 4;

	should be:

int outLen = 10 * 1024 * 2;

	there was no enough space in output baffer.

Thank you,
Milan



Re: Base64

Posted by Berin Lautenbach <be...@wingsofhermes.org>.
Milan,

1K seems a lot to be missing.

I'm not sure about the line :

    outputSz = b64.encodeFinish(output, outLen - outputSz);

My reading is that outputSz could still be set from the last run through
the loop, and if the last piece of input was big enough, this would leave
no space in the output buffer for the final piece of output.
However that shoulnd't leave you with such a large amount missing.

How big is the file, and when you say you are missing 1K, are you sure it
is at the end (just to rule out the base64 encoder dropping bytes at the
end of buffers during each round).
Cheers,
     Berin

>
> 	Is this OK:
>
> CString cEncodedFile;
> XSCryptCryptoBase64 b64;
> b64.encodeInit();
> CFile f;
> f.Open(cXMLFile.GetBuffer(999), CFile::modeRead);
> int outLen = 10 * 1024 * 4/3 + 4;
> BYTE *input = new BYTE[10 * 1024];
> BYTE *output = new BYTE[outLen];
> int inputSz = f.Read(input, 10 * 1024); int outputSz = 0;
>
> while (inputSz > 0) {
> 	outputSz = b64.encode(input, inputSz, output, outLen );
> 	CString tmp = CString((char*) output, outputSz);
> 	cEncodedFile += tmp;
> 	inputSz = f.Read(input, 10 * 1024);
> }
>
> outputSz = b64.encodeFinish(output, outLen - outputSz);
> //write_to_wherever(output, outputSz);
> CString tmp = CString((char*) output, outputSz);
> cEncodedFile += tmp;
>
> I'm missing 1K at the end. :(