aboutsummaryrefslogtreecommitdiff
path: root/src/encoding/base64/base64.go
AgeCommit message (Collapse)Author
2026-03-26encoding/{base32,base64}: speed up EncodeJulien Cretel
This CL clarifies (*Encoding).Encode and speeds it up by reducing the number of bounds checks in its loop. Here are some benchmark results (no change to allocations): goos: darwin goarch: arm64 pkg: encoding/base32 cpu: Apple M4 │ old │ new │ │ sec/op │ sec/op vs base │ EncodeToString-10 7.310µ ± 0% 5.308µ ± 0% -27.39% (n=180) Encode-10 5.651µ ± 0% 3.603µ ± 0% -36.25% (n=180) geomean 6.427µ 4.373µ -31.96% │ old │ new │ │ B/s │ B/s vs base │ EncodeToString-10 1.044Gi ± 0% 1.437Gi ± 0% +37.71% (p=0.000 n=180) Encode-10 1.350Gi ± 0% 2.118Gi ± 0% +56.88% (p=0.000 n=180) geomean 1.187Gi 1.745Gi +46.98% pkg: encoding/base64 │ old │ new │ │ sec/op │ sec/op vs base │ EncodeToString-10 7.058µ ± 0% 6.034µ ± 0% -14.51% (n=180) │ old │ new │ │ B/s │ B/s vs base │ EncodeToString-10 1.081Gi ± 0% 1.264Gi ± 0% +16.97% (p=0.000 n=180) Updates #20206 Change-Id: I7d46891ddb4371df004bfd612a8efc6638715b94 GitHub-Last-Rev: 1caac3d65532fefacbbed57f11a4a49273f173e2 GitHub-Pull-Request: golang/go#78344 Reviewed-on: https://go-review.googlesource.com/c/go/+/759100 Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@golang.org> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Reviewed-by: Keith Randall <khr@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
2025-02-06encoding/base64: use internal/byteorderIan Lance Taylor
This permits us to remove the dependency on reflect. Change-Id: I60b1e9fd713f340bfd5eec2edfa58fc724a8e2d8 Reviewed-on: https://go-review.googlesource.com/c/go/+/641936 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Robert Griesemer <gri@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Bypass: Ian Lance Taylor <iant@golang.org> Auto-Submit: Ian Lance Taylor <iant@golang.org>
2024-12-06encoding/base64, encoding/base32: add doc details to DecodeString and ↵Dmytro Yeroshkin
AppendDecode Currently only Encoding.Decode has the information that `\r` and `\n` are ignored. However, this also applies to the other decoding methods. Since this is not intuitive behavior, we should add this information to the other impacted methods. Change-Id: I6f71fe1f4280fe75f2694a3cc1b759652eb8b8c1 Reviewed-on: https://go-review.googlesource.com/c/go/+/634215 Reviewed-by: Ian Lance Taylor <iant@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Chris Ingram <chrisingram@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Truc Le <trucleduc@google.com>
2024-08-30encoding/base32, encoding/base64: document Decode to short bufferIan Lance Taylor
Document that if one of the Decode methods in these packages is given a short buffer, it panics. Fixes #69024 Change-Id: I1c0e4c74274965c1cfa0422cc8f86af4fefb1d00 Reviewed-on: https://go-review.googlesource.com/c/go/+/607499 Auto-Submit: Ian Lance Taylor <iant@golang.org> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Damien Neil <dneil@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2023-09-08encoding: modernize Go documentationJoe Tsai
Across all encoding packages, linkify declarations if possible. In some cases, we convert a code block into a bulleted list, which then further allows for more linkification. Change-Id: I68fedf362615b34228bab5d4859b7d87d831c570 Reviewed-on: https://go-review.googlesource.com/c/go/+/524977 LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Daniel Martí <mvdan@mvdan.cc> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: qiulaidongfeng <2645477756@qq.com> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2023-09-03encoding: show the alphabet for base32 and base64Joe Tsai
There is not a great reason to hide the alphabet used for StdEncoding, HexEncoding, and URLEncoding. Although this is specified in RFC 4748, showing it in GoDoc saves an extra click from going to the RFC itself to see the alphabet being used. Also, split exported and unexported constants apart so that GoDoc renders more cleanly. Fixes #55126 Change-Id: I03bfa607fb6c3df7f757e33fc0f4ec2b233de1a1 Reviewed-on: https://go-review.googlesource.com/c/go/+/525296 Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
2023-08-19encoding: optimize growth behavior in Encoding.AppendDecodeJoe Tsai
The Encoding.DecodedLen API only returns the maximum length of the expected decoded output, since it does not know about padding. Since we have the input, we can do better by computing the input length without padding, and then perform the DecodedLen calculation as if there were no padding. This avoids over-growing the destination slice if possible. Over-growth is still possible since the input may contain ignore characters like newlines and carriage returns, but those a rarely encountered in practice. Change-Id: I38b8f91de1f4fbd3a7128c491a25098bd385cf74 Reviewed-on: https://go-review.googlesource.com/c/go/+/520267 Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Ian Lance Taylor <iant@google.com> Auto-Submit: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2023-08-18encoding: require unique alphabet for base32 and base64Joe Tsai
In order for decoding to faithfully reproduce the encoded input, the symbols must be unique (i.e., provide a bijective mapping). Thus, reject duplicate symbols in NewEncoding. As a minor optimization, modify WithPadding to use the decodeMap to quickly check whether the padding character is used in O(1) instead of O(32) or O(64). Change-Id: I5631f6ff9335c35d59d020dc0e307e3520786fbc Reviewed-on: https://go-review.googlesource.com/c/go/+/520335 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Auto-Submit: Joseph Tsai <joetsai@digital-static.net> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Joseph Tsai <joetsai@digital-static.net>
2023-08-17encoding: reject negative runes in Encoding.WithPaddingJoe Tsai
A negative rune (other than NoPadding) makes no semantic sense. Doing so relies on integer overflow of converting a rune to a byte and would thus be equivalent to passing the positive byte value of byte(padding). This may cause existing code to panic. An alternative is treat negative runes as equivalent to NoPadding. However, the code already panics to report erroneous padding values, so this is in line with the existing API. Change-Id: I02499705519581598adc0c8525d90e25278dc056 Reviewed-on: https://go-review.googlesource.com/c/go/+/505236 Auto-Submit: Joseph Tsai <joetsai@digital-static.net> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
2023-08-17encoding: add AppendEncode and AppendDecodeJoe Tsai
Implement append-like equivalent of Encode and Decode functions. Fixes #53693 Change-Id: I79d8d834e3c8f77fad32be2fd391e33d4d1527ea Reviewed-on: https://go-review.googlesource.com/c/go/+/504884 Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Auto-Submit: Joseph Tsai <joetsai@digital-static.net>
2023-07-21encoding/base64: reduce the overflow risk when computing encode/decode lengthchanxuehong
Change-Id: I0a55cdc38ae496e2070f0b9ef317a41f82352afd GitHub-Last-Rev: c19527a26b0778cbb4548f49e1e365102709f068 GitHub-Pull-Request: golang/go#61407 Reviewed-on: https://go-review.googlesource.com/c/go/+/510635 Reviewed-by: Ian Lance Taylor <iant@google.com> Run-TryBot: Ian Lance Taylor <iant@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> Reviewed-by: Heschi Kreinick <heschi@google.com>
2023-06-27encoding: document that base32 and base64 do not use UTF-8Joe Tsai
The invention of base32 and base64 predates the invention of UTF-8 and was never meant to output valid UTF-8. By default, the output is always valid ASCII (and thus valid UTF-8) except when the user specifies an alphabet or padding value that is larger than '\x7f'. If that is done, then the exact byte symbol is used rather than the UTF-8 encoding. Fixes #60689 Change-Id: I4ec88d974ec0658ad1a578bbd65a809e27c73ea7 Reviewed-on: https://go-review.googlesource.com/c/go/+/505237 Run-TryBot: Joseph Tsai <joetsai@digital-static.net> Reviewed-by: Ian Lance Taylor <iant@google.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
2022-08-17encoding/base64: optimize decodemap memory setErikPelli
The existing implementation has an execution time higher in the benchmark than this one. This is an optimized implementation using the copy() function and a constant 256 bytes string with the values to be copied. ``` name old time/op new time/op delta NewEncoding-4 329ns ± 1% 231ns ± 1% -29.72% (p=0.008 n=5+5) name old speed new speed delta NewEncoding-4 778MB/s ± 1% 1108MB/s ± 1% +42.29% (p=0.008 n=5+5) ``` Fixes #53211 Change-Id: I80fe62aa40623125ef81ae9164a8405eed30b71b GitHub-Last-Rev: 55dce6f636ad29a70daa935169710c22f44ab31f GitHub-Pull-Request: golang/go#53212 Reviewed-on: https://go-review.googlesource.com/c/go/+/410194 Reviewed-by: Keith Randall <khr@google.com> Run-TryBot: Keith Randall <khr@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Keith Randall <khr@golang.org> Auto-Submit: Keith Randall <khr@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
2021-11-02encoding: simplify some codeJosh Bleecher Snyder
Change-Id: I63aac663da4ce7bdd198d385f87929c74f6a5cf8 Reviewed-on: https://go-review.googlesource.com/c/go/+/360601 Trust: Josh Bleecher Snyder <josharian@gmail.com> Run-TryBot: Josh Bleecher Snyder <josharian@gmail.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2020-04-22encoding/base64: improve performance up to 20% totalKirill Korotaev
Improve base64 encoding/decoding performance by suppressing compiler boundary checks on decode. name old speed new speed delta EncodeToString-8 570MB/s ± 1% 573MB/s ± 1% ~ (p=0.421 n=5+5) DecodeString/2-8 88.6MB/s ± 3% 91.6MB/s ± 2% +3.37% (p=0.016 n=5+5) DecodeString/4-8 162MB/s ± 1% 168MB/s ± 0% +4.12% (p=0.008 n=5+5) DecodeString/8-8 203MB/s ± 0% 214MB/s ± 0% +5.18% (p=0.008 n=5+5) DecodeString/64-8 471MB/s ± 1% 520MB/s ± 1% +10.50% (p=0.008 n=5+5) DecodeString/8192-8 757MB/s ± 0% 895MB/s ± 1% +18.29% (p=0.008 n=5+5) Change-Id: I135243c11aa4c974a4a4e95c5c2abb0635d52c8c GitHub-Last-Rev: 2c87abcb287f4459888941ae2633edcd8eb5b79d GitHub-Pull-Request: golang/go#36910 Reviewed-on: https://go-review.googlesource.com/c/go/+/217117 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-11-20encoding/base64: document that Strict mode still ignores newlinesFilippo Valsorda
An application that wants to reject non-canonical encodings is likely to care about other sources of malleability. Change-Id: I1d3a5b281d2631ca78df3f89b957a02687a534d8 Reviewed-on: https://go-review.googlesource.com/c/go/+/188858 Reviewed-by: Katie Hockman <katie@golang.org>
2019-03-13encoding/base64: speed up the decoderDaniel Martí
Most of the decoding time is spent in the first Decode loop, since the rest of the function only deals with the few remaining bytes. Any unnecessary work done in that loop body matters tremendously. One such unnecessary bottleneck was the use of the enc.decodeMap table. Since enc is a pointer receiver, and the field is used within the non-inlineable function decode64, the decoder must perform a nil check at every iteration. To fix that, move the enc.decodeMap uses to the parent function, where we can lift the nil check outside the loop. That gives roughly a 15% speed-up. The function no longer performs decoding per se, so rename it. While at it, remove the now unnecessary receivers. An unfortunate side effect of this change is that the loop now contains eight bounds checks on src instead of just one. However, not having to slice src plus the nil check removal well outweigh the added cost. The other piece that made decode64 slow was that it wasn't inlined, and had multiple branches. Use a simple bitwise-or trick suggested by Roger Peppe, and collapse the rest of the bitwise logic into a single expression. Inlinability and the reduced branching give a further 10% speed-up. Finally, add these two functions to TestIntendedInlining, since we want them to stay inlinable. Apply the same refactor to decode32 for consistency, and to let 32-bit architectures see a similar performance gain for large inputs. name old time/op new time/op delta DecodeString/2-8 47.3ns ± 1% 45.8ns ± 0% -3.28% (p=0.002 n=6+6) DecodeString/4-8 55.8ns ± 2% 51.5ns ± 0% -7.71% (p=0.004 n=5+6) DecodeString/8-8 64.9ns ± 0% 61.7ns ± 0% -4.99% (p=0.004 n=5+6) DecodeString/64-8 238ns ± 0% 198ns ± 0% -16.54% (p=0.002 n=6+6) DecodeString/8192-8 19.5µs ± 0% 14.6µs ± 0% -24.96% (p=0.004 n=6+5) name old speed new speed delta DecodeString/2-8 84.6MB/s ± 1% 87.4MB/s ± 0% +3.38% (p=0.002 n=6+6) DecodeString/4-8 143MB/s ± 2% 155MB/s ± 0% +8.41% (p=0.004 n=5+6) DecodeString/8-8 185MB/s ± 0% 195MB/s ± 0% +5.29% (p=0.004 n=5+6) DecodeString/64-8 369MB/s ± 0% 442MB/s ± 0% +19.78% (p=0.002 n=6+6) DecodeString/8192-8 560MB/s ± 0% 746MB/s ± 0% +33.27% (p=0.004 n=6+5) Updates #19636. Change-Id: Ib839577b0e3f5a2bb201f5cae580c61365d92894 Reviewed-on: https://go-review.googlesource.com/c/go/+/151177 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Reviewed-by: roger peppe <rogpeppe@gmail.com>
2019-03-05encoding/base64: do not slice past output unnecessarilyRuss Cox
Base64-encoding 32 bytes results in a 44-byte string. While in general a 44-byte string might decode to 33 bytes, if you take a 44-byte string that actually only encodes 32 bytes, and you try to decode it into 32 bytes, that should succeed. Instead it fails trying to do a useless dst[33:] slice operation. Delete that slice operation. Noticed while preparing CL 156322. Change-Id: I8024bf28a65e2638675b980732b2ff91c66c62cf Reviewed-on: https://go-review.googlesource.com/c/go/+/164628 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2019-03-03encoding/base64: lift nil check out of encode loopDaniel Martí
Most of the encoding time is spent in the first Encode loop, since the rest of the function only deals with the few remaining bytes. Any unnecessary work done in that loop body matters tremendously. One such unnecessary bottleneck was the use of the enc.encode table. Since enc is a pointer receiver, and the field is first used within the loop, the encoder must perform a nil check at every iteration. Add a dummy use of the field before the start of the loop, to move the nil check there. After that line, the compiler now knows that enc can't be nil, and thus the hot loop is free of nil checks. name old time/op new time/op delta EncodeToString-4 14.7µs ± 0% 13.7µs ± 1% -6.53% (p=0.000 n=10+10) name old speed new speed delta EncodeToString-4 559MB/s ± 0% 598MB/s ± 1% +6.99% (p=0.000 n=10+10) Updates #20206. Change-Id: Icbb523a7bd9e470a8be0a448d1d78ade97ed4ff6 Reviewed-on: https://go-review.googlesource.com/c/151158 Run-TryBot: Daniel Martí <mvdan@mvdan.cc> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-10-12encoding/base64: fix typo in decodeQuantum docsMihai Todor
Change-Id: I643540bcea574d8a70b79237d97097dcc7368766 GitHub-Last-Rev: e2be58d1ab84f91dfbba1067aae7145f24fd650d GitHub-Pull-Request: golang/go#28125 Reviewed-on: https://go-review.googlesource.com/c/141119 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2018-08-22encoding/base64: slight decoding speed-upDaniel Martí
First, use a dummy slice access on decode64 and decode32 to ensure that there is a single bounds check for src. Second, move the PutUint64/PutUint32 calls out of these functions, meaning that they are simpler and smaller. This may also open the door to inlineability in the future, but for now, they both go past the budget. While at it, get rid of the ilen and olen variables, which have no impact whatsoever on performance. At least, not measurable by any of the benchmarks. name old time/op new time/op delta DecodeString/2-4 54.3ns ± 1% 55.2ns ± 2% +1.60% (p=0.017 n=5+6) DecodeString/4-4 66.6ns ± 1% 66.8ns ± 2% ~ (p=0.903 n=6+6) DecodeString/8-4 79.3ns ± 2% 79.6ns ± 1% ~ (p=0.448 n=6+6) DecodeString/64-4 300ns ± 1% 281ns ± 3% -6.54% (p=0.002 n=6+6) DecodeString/8192-4 27.4µs ± 1% 23.7µs ± 2% -13.47% (p=0.002 n=6+6) name old speed new speed delta DecodeString/2-4 73.7MB/s ± 1% 72.5MB/s ± 2% -1.55% (p=0.026 n=5+6) DecodeString/4-4 120MB/s ± 1% 120MB/s ± 2% ~ (p=0.851 n=6+6) DecodeString/8-4 151MB/s ± 2% 151MB/s ± 1% ~ (p=0.485 n=6+6) DecodeString/64-4 292MB/s ± 1% 313MB/s ± 3% +7.03% (p=0.002 n=6+6) DecodeString/8192-4 399MB/s ± 1% 461MB/s ± 2% +15.58% (p=0.002 n=6+6) For #19636. Change-Id: I0dfbdafa2a41dc4c582f63aef94b90b8e473731c Reviewed-on: https://go-review.googlesource.com/113776 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-10-09encoding/base64: optimize DecodeStringJosselin Costanzi
Optimize base64 decoding speed by adding 32-bits and 64-bits specialized methods that don't perform any error checking and fall back to the more complex decodeQuantum method when a non-base64 character is present. On a 64-bits cpu: name old time/op new time/op delta DecodeString/2-4 70.0ns ± 6% 69.2ns ± 0% ~ (p=0.169 n=5+8) DecodeString/4-4 91.3ns ± 2% 80.4ns ± 0% -11.89% (p=0.001 n=5+10) DecodeString/8-4 126ns ± 5% 106ns ± 0% -16.14% (p=0.000 n=5+7) DecodeString/64-4 652ns ±21% 361ns ± 0% -44.57% (p=0.000 n=5+7) DecodeString/8192-4 61.0µs ±13% 31.5µs ± 1% -48.38% (p=0.001 n=5+9) name old speed new speed delta DecodeString/2-4 57.2MB/s ± 6% 57.7MB/s ± 2% ~ (p=0.419 n=5+9) DecodeString/4-4 87.7MB/s ± 2% 99.5MB/s ± 0% +13.45% (p=0.001 n=5+10) DecodeString/8-4 94.8MB/s ± 5% 112.6MB/s ± 1% +18.82% (p=0.001 n=5+9) DecodeString/64-4 136MB/s ±19% 243MB/s ± 0% +78.17% (p=0.003 n=5+7) DecodeString/8192-4 180MB/s ±11% 347MB/s ± 1% +92.94% (p=0.001 n=5+9) Improves #19636 Change-Id: Ic10a454851093a7e1d46ca0c140deed73535d990 Reviewed-on: https://go-review.googlesource.com/38632 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Lance Taylor <iant@golang.org>
2017-04-24encoding/base64: Optimize DecodeStringJosselin Costanzi
Optimize DecodeString for the common case where most of the input isn't a newline or a padding character. Also add some testcases found when fuzzing this implementation against upstream. Change Decode benchmark to run with different input sizes. name old time/op new time/op delta DecodeString/2-4 71.5ns ± 4% 70.0ns ± 6% ~ (p=0.246 n=5+5) DecodeString/4-4 112ns ±25% 91ns ± 2% ~ (p=0.056 n=5+5) DecodeString/8-4 136ns ± 5% 126ns ± 5% -7.33% (p=0.016 n=5+5) DecodeString/64-4 872ns ±29% 652ns ±21% -25.23% (p=0.032 n=5+5) DecodeString/8192-4 90.9µs ±21% 61.0µs ±13% -32.87% (p=0.008 n=5+5) name old speed new speed delta DecodeString/2-4 56.0MB/s ± 4% 57.2MB/s ± 6% ~ (p=0.310 n=5+5) DecodeString/4-4 73.4MB/s ±23% 87.7MB/s ± 2% ~ (p=0.056 n=5+5) DecodeString/8-4 87.8MB/s ± 5% 94.8MB/s ± 5% +7.98% (p=0.016 n=5+5) DecodeString/64-4 103MB/s ±24% 136MB/s ±19% +32.63% (p=0.032 n=5+5) DecodeString/8192-4 122MB/s ±19% 180MB/s ±11% +47.75% (p=0.008 n=5+5) Improves #19636 Change-Id: I39667f4fb682a12b3137946d017ad999553c5780 Reviewed-on: https://go-review.googlesource.com/34950 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-03-07encoding/base64, html/template: fix grammar mistakesKevin Burke
Replace 'does not contains' with 'does not contain' where it appears in the source code. Change-Id: Ie7266347c429512c8a41a7e19142afca7ead3922 Reviewed-on: https://go-review.googlesource.com/37887 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2017-03-07encoding/base64: add alphabet and padding restrictionsJosselin Costanzi
Document and check that the alphabet cannot contain '\n' or '\r'. Document that the alphabet cannot contain the padding character. Document that the padding character must be equal or bellow '\xff'. Document that the padding character must not be '\n' or '\r'. Fixes #19343 Fixes #19318 Change-Id: I6de0034d347ffdf317d7ea55d6fe38b01c2c4c03 Reviewed-on: https://go-review.googlesource.com/37838 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2017-03-06encoding/base64: fix decode reports incorrect indexJosselin Costanzi
Fix Decode to return the correct illegal data index from a corrupted input that contains whitespaces. Fixes #19406 Change-Id: Ib2b2b6ed7e41f024d0da2bd035caec4317c2869c Reviewed-on: https://go-review.googlesource.com/37837 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-10-12encoding/base64: This change modifies Go to take strict option when decoding ↵Xuyang Kang
base64 If strict option is enabled, when decoding, instead of skip the padding bits, it will do strict check to enforce they are set to zero. Fixes #15656 Change-Id: I869fb725a39cc9dde44dbc4ff0046446e7abc642 Reviewed-on: https://go-review.googlesource.com/24964 Reviewed-by: Russ Cox <rsc@golang.org> Run-TryBot: Russ Cox <rsc@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-15encoding/base64: correct DecodedLen overestimate for unpadded encodingsCaleb Spare
While we're at it, add tests for EncodedLen and DecodedLen. Fixes #14803. Change-Id: I200c72cf11c51669b8d9f70c6e57ece359f7ae61 Reviewed-on: https://go-review.googlesource.com/20649 Reviewed-by: Ian Lance Taylor <iant@golang.org> Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-03-02all: single space after period.Brad Fitzpatrick
The tree's pretty inconsistent about single space vs double space after a period in documentation. Make it consistently a single space, per earlier decisions. This means contributors won't be confused by misleading precedence. This CL doesn't use go/doc to parse. It only addresses // comments. It was generated with: $ perl -i -npe 's,^(\s*// .+[a-z]\.) +([A-Z]),$1 $2,' $(git grep -l -E '^\s*//(.+\.) +([A-Z])') $ go test go/doc -update Change-Id: Iccdb99c37c797ef1f804a94b22ba5ee4b500c4f7 Reviewed-on: https://go-review.googlesource.com/20022 Reviewed-by: Rob Pike <r@golang.org> Reviewed-by: Dave Day <djd@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
2016-01-08encoding/base64: fix streaming decode of padding-free base64Russ Cox
Fixes #13384. Change-Id: Id9e827acddc8de139f93c5de0c6486bc4334c7d4 Reviewed-on: https://go-review.googlesource.com/18330 Reviewed-by: Ian Lance Taylor <iant@golang.org>
2015-08-21encoding/base64: fix copy-paste-o bug in RawURLEncoding docsBrad Fitzpatrick
Fixes #12244 Change-Id: Iee4e45d9bca0718c71fcc574bc51b2084c3dcb2a Reviewed-on: https://go-review.googlesource.com/13783 Reviewed-by: Josh Bleecher Snyder <josharian@gmail.com>
2015-04-24encoding/base64: Optimize EncodeToString and DecodeString.Egon Elbre
benchmark old ns/op new ns/op delta BenchmarkEncodeToString 31281 23821 -23.85% BenchmarkDecodeString 156508 82254 -47.44% benchmark old MB/s new MB/s speedup BenchmarkEncodeToString 261.88 343.89 1.31x BenchmarkDecodeString 69.80 132.81 1.90x Change-Id: I115e0b18c3a6d5ef6bfdcb3f637644f02f290907 Reviewed-on: https://go-review.googlesource.com/8808 Reviewed-by: Nigel Tao <nigeltao@golang.org>
2014-12-22encoding/base64: add unpadded encodings, and test all encodings.Bryan Ford
Some applications use unpadded base64 format, omitting the trailing '=' padding characters from the standard base64 format, either to minimize size or (more justifiably) to avoid use of the '=' character. Unpadded flavors are standard and documented in section 3.2 of RFC 4648. To support these unpadded flavors, this change adds two predefined encoding variables, RawStdEncoding and RawURLEncoding, for unpadded encodings using the standard and URL character set, respectively. The change also adds a function WithPadding() to customize the padding character or disable padding in a custom Encoding. Finally, I noticed that the existing base64 test-suite was only exercising the StdEncoding, and not referencing URLEncoding at all. This change adds test-suite functionality to exercise all four encodings (the two existing ones and the two new unpadded flavors), although it still doesn't run *every* test on all four encodings. Naming: I used the "Raw" prefix because it's more concise than "Unpadded" and seemed just as expressive, but I have no strong preferences here. Another short alternative prefix would be "Min" ("minimal" encoding). Change-Id: Ic0423e02589b39a6b2bb7d0763bd073fd244f469 Reviewed-on: https://go-review.googlesource.com/1511 Reviewed-by: Russ Cox <rsc@golang.org> Reviewed-by: Minux Ma <minux@golang.org> Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
2014-09-08build: move package sources from src/pkg to srcRuss Cox
Preparation was in CL 134570043. This CL contains only the effect of 'hg mv src/pkg/* src'. For more about the move, see golang.org/s/go14nopkg.