cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Curl_base64_decode not mod 3 issue (fwd)

From: matthew b <mb7oo_at_hotmail.com>
Date: Fri, 20 Dec 2002 02:20:45 +0000

The interface I was mentioning was from a discussion I noticed in early
October. I think the current API is good enough, but understand why you want
to clean it up before making it public.

It looks like this code is used only in one place today.

I didn't write any sort of formal test suite, just a few examples which I
reviewed in the debugger. Clearly you could change these to strcmp, or do a
decode/encode or encode/decode pair.

int len; char sz[30];
len = Curl_base64_decode("MQ==", sz); // 1
sz[len] = '\0'; // binary -> null terminated string
len = Curl_base64_decode("MTI=", sz); // 12
sz[len] = '\0';
len = Curl_base64_decode("MTIz", sz); // 123
sz[len] = '\0';
len = Curl_base64_decode("aGVsbG8uIHRoaXMgaXMgYSBiYXNlNjQgdGVzdCE=", sz); //
hello. this is a base64 test!
sz[len] = '\0';

--Matthew

>Date: Thu, 19 Dec 2002 16:57:42 +0100 (MET)
>From: Daniel Stenberg <daniel_at_haxx.se>
>
>On Thu, 19 Dec 2002, matthew b wrote:
>
> > Hi. I needed a base64 decoder, and since I was using curl anyway I
>thought
> > I'd try base64.c in anticipation of it being part of the exported
>library.
> > (I say passing in a pre-existing buffer is OK for a base64 encode and
> > decode interface since the size is deterministic, but don't have the
>feel
> > of the curl interface enough to say if it's consistent.)
>
>The interface has become like this more or less out of a coincidence, as it
>hasn't been that very much planning behind how it turned out.
>
> > Anyway, the version on my machine (base64.c,v 1.14 2002/09/03) doesn't
>seem
> > to propertly handle the case when the size of the enencoded message is
>not
> > a multiple of 3. I made two small tweaks to fix it, and it seems to work
> > now.
>
>Thanks for the patch! The decoder is really very rarely used and I guess
>that's the explanation for this long-lasting bug.
>
>Did you happen to test this with some inputs to prove it working? If so,
>could you please post the code and I'd be happy to add it to the test
>suite!
>

_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963

-------------------------------------------------------
This SF.NET email is sponsored by: Geek Gift Procrastinating?
Get the perfect geek gift now! Before the Holidays pass you by.
T H I N K G E E K . C O M http://www.thinkgeek.com/sf/
Received on 2002-12-20