Boost logo

Boost :

From: Robert Ramey (ramey_at_[hidden])
Date: 2008-06-09 12:40:44


Hmmm - I wasn't aware that base64 had a "principle" that output
length is a multiple of 4 bytes.

You could be on ot something here, I'll take another look at it.
Vyacheslav E. Andrejev wrote:
> Hello,
>
> Code that pads base64 output with '=' looks in
> basic_text_oprimitive.ipp like following:
>
> std::size_t padding = 2 - count % 3;
> if(padding > 1)
> *oi = '=';
> if(padding > 2)
> *oi = '=';
>
> It will give the following transformations of a few simple strings:
>
> "012" -> "MDEy="
> "0123" -> "MDEyMw"
> "01234" -> "MDEyMzQ"
> "012345" -> "MDEyMzQ1="
>
> Which violates the principle of the base 64 that the encoded output
> length is multiple of 4 bytes. Right output for the samples above
> should be:

>
> "012" -> "MDEy"
> "0123" -> "MDEyMw=="
> "01234" -> "MDEyMzQ="
> "012345" -> "MDEyMzQ1"
>
>
> The problem with the code above is that the condition (padding > 2)
> is never satisfied. I think that the proper code should look like
>
> std::size_t padding = 2 - count % 3;
> if (padding < 2) {
> *oi = '=';
> if (padding > 0)
> *oi = '=';
> }


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk