]> Cypherpunks repositories - gostls13.git/commitdiff
encoding/base64, encoding/base32: add doc details to DecodeString and AppendDecode
authorDmytro Yeroshkin <yeroshkin@google.com>
Fri, 6 Dec 2024 15:49:52 +0000 (15:49 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 6 Dec 2024 20:49:45 +0000 (20:49 +0000)
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>
src/encoding/base32/base32.go
src/encoding/base64/base64.go

index 66f24e98a6604d12843f4c926a2176175219152a..8bda6c6799ef72ed7aecdd5b12742d5fc937bb87 100644 (file)
@@ -401,6 +401,7 @@ func (enc *Encoding) Decode(dst, src []byte) (n int, err error) {
 // AppendDecode appends the base32 decoded src to dst
 // and returns the extended buffer.
 // If the input is malformed, it returns the partially decoded src and an error.
+// New line characters (\r and \n) are ignored.
 func (enc *Encoding) AppendDecode(dst, src []byte) ([]byte, error) {
        // Compute the output size without padding to avoid over allocating.
        n := len(src)
@@ -415,6 +416,8 @@ func (enc *Encoding) AppendDecode(dst, src []byte) ([]byte, error) {
 }
 
 // DecodeString returns the bytes represented by the base32 string s.
+// If the input is malformed, it returns the partially decoded data and
+// [CorruptInputError]. New line characters (\r and \n) are ignored.
 func (enc *Encoding) DecodeString(s string) ([]byte, error) {
        buf := []byte(s)
        l := stripNewlines(buf, buf)
index 7f0fa2de78e6bf6075546590c9e35d90f72b4641..f94bea132cbde36a0bd9775ce4491bc146a806a1 100644 (file)
@@ -409,6 +409,7 @@ func (enc *Encoding) decodeQuantum(dst, src []byte, si int) (nsi, n int, err err
 // AppendDecode appends the base64 decoded src to dst
 // and returns the extended buffer.
 // If the input is malformed, it returns the partially decoded src and an error.
+// New line characters (\r and \n) are ignored.
 func (enc *Encoding) AppendDecode(dst, src []byte) ([]byte, error) {
        // Compute the output size without padding to avoid over allocating.
        n := len(src)
@@ -423,6 +424,8 @@ func (enc *Encoding) AppendDecode(dst, src []byte) ([]byte, error) {
 }
 
 // DecodeString returns the bytes represented by the base64 string s.
+// If the input is malformed, it returns the partially decoded data and
+// [CorruptInputError]. New line characters (\r and \n) are ignored.
 func (enc *Encoding) DecodeString(s string) ([]byte, error) {
        dbuf := make([]byte, enc.DecodedLen(len(s)))
        n, err := enc.Decode(dbuf, []byte(s))