Opened 14 years ago
Closed 14 years ago
#2010 closed Tasks (fixed)
bas64 iterator improvement
| Reported by: | Robert Ramey | Owned by: | Robert Ramey |
|---|---|---|---|
| Milestone: | Boost 1.36.0 | Component: | None |
| Version: | Boost 1.35.0 | Severity: | Problem |
| Keywords: | serialization base64 | Cc: |
Description
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 = '=';
> }
Change History (2)
comment:1 by , 14 years ago
| Status: | new → assigned |
|---|
comment:2 by , 14 years ago
| Resolution: | → fixed |
|---|---|
| Status: | assigned → closed |
Note:
See TracTickets
for help on using tickets.

change checked into trunk