From 53739590571e66cbace8a6b388a79901cfb8fc3a Mon Sep 17 00:00:00 2001 From: Joe Tsai Date: Sat, 2 Sep 2023 20:38:49 -0700 Subject: encoding: show the alphabet for base32 and base64 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 Reviewed-by: Dmitri Shuralyov TryBot-Result: Gopher Robot Run-TryBot: Joseph Tsai Auto-Submit: Joseph Tsai --- src/encoding/base32/base32.go | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) (limited to 'src/encoding/base32') diff --git a/src/encoding/base32/base32.go b/src/encoding/base32/base32.go index e921887285..d26cb5c685 100644 --- a/src/encoding/base32/base32.go +++ b/src/encoding/base32/base32.go @@ -26,9 +26,12 @@ type Encoding struct { } const ( - StdPadding rune = '=' // Standard padding character - NoPadding rune = -1 // No padding - decodeMapInitialize = "" + + StdPadding rune = '=' // Standard padding character + NoPadding rune = -1 // No padding +) + +const ( + decodeMapInitialize = "" + "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" + "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" + "\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff" + @@ -48,9 +51,6 @@ const ( invalidIndex = '\xff' ) -const encodeStd = "ABCDEFGHIJKLMNOPQRSTUVWXYZ234567" -const encodeHex = "0123456789ABCDEFGHIJKLMNOPQRSTUV" - // NewEncoding returns a new padded Encoding defined by the given alphabet, // which must be a 32-byte string that contains unique byte values and // does not contain the padding character or CR / LF ('\r', '\n'). @@ -83,13 +83,12 @@ func NewEncoding(encoder string) *Encoding { return e } -// StdEncoding is the standard base32 encoding, as defined in -// RFC 4648. -var StdEncoding = NewEncoding(encodeStd) +// StdEncoding is the standard base32 encoding, as defined in RFC 4648. +var StdEncoding = NewEncoding("ABCDEFGHIJKLMNOPQRSTUVWXYZ234567") // HexEncoding is the “Extended Hex Alphabet” defined in RFC 4648. // It is typically used in DNS. -var HexEncoding = NewEncoding(encodeHex) +var HexEncoding = NewEncoding("0123456789ABCDEFGHIJKLMNOPQRSTUV") // WithPadding creates a new encoding identical to enc except // with a specified padding character, or NoPadding to disable padding. -- cgit v1.3-5-g9baa