Re: [PATCH 1/4] Add base64 encoder and decoder
- From
- Hitoshi Mitake <mitake@dcl.info.waseda.ac.jp>
- Date
- Feb 11, 2010, 14:37 UTC
- Message-ID
- <4B741631.40203@dcl.info.waseda.ac.jp>
- In-Reply-To
- <40aa078e1002090645s63449057hf88c89a232933680@mail.gmail.com>
(2010年02月09日 23:45), Erik Faye-Lund wrote:
Show 44 quoted lines
> On Tue, Feb 9, 2010 at 1:09 PM, Hitoshi Mitake
> <mitake@dcl.info.waseda.ac.jp> wrote:
>> +void base64_encode(char *out, const char *in, int inlen)
>> +{
>> + const char *inp = in;
>> + char *outp = out;
>
> ...Why? It's copying the pointers to pointers of identical type with
> different names, and never using the originals again... Looks like a
> sloppy extraction from another code-base to me.
>
>> +
>> + while (inlen>= 3) {
>> + *outp++ = base64char[(inp[0]>> 2)& 0x3f];
>> + *outp++ = base64char[((inp[0]& 0x03)<< 4) |
>> + ((inp[1]>> 4)& 0x0f)];
>> + *outp++ = base64char[((inp[1]& 0x0f)<< 2) |
>> + ((inp[2]>> 6)& 0x03)];
>> + *outp++ = base64char[inp[2]& 0x3f];
>> +
>> + inp += 3;
>> + inlen -= 3;
>> + }
>> +
>> + if (inlen> 0) {
>> + *outp++ = base64char[(inp[0]>> 2)& 0x3f];
>> + if (inlen == 1) {
>> + *outp++ = base64char[(inp[0]& 0x03)<< 4];
>> + *outp++ = '=';
>> + } else {
>> + *outp++ = base64char[((inp[0]& 0x03)<< 4) |
>> + ((inp[1]>> 4)& 0x0f)];
>> + *outp++ = base64char[((inp[1]& 0x0f)<< 2)];
>> + }
>> + *outp++ = '=';
>> + }
>> +
>> + *outp = '\0';
>> +}
>
> If inlen is 0, a single '=' should be emitted (plus the obvious zero
> termination). It could be that the code deals with that by making sure
> that inlen never is zero, though.
>Thanks for your review, I was careless...
I decided to use base64 and md5 stuffs OpenSSL provides. I'll remove 1 and 2 of my patch series.
Thanks,