Fixes #22 - Padding issue in Go1.3 rc1

This commit is contained in:
Henry 2014-06-03 16:15:11 +02:00
parent fecd9ab279
commit 679bf0f3c9
1 changed files with 2 additions and 6 deletions

8
jwt.go
View File

@ -217,12 +217,8 @@ func EncodeSegment(seg []byte) string {
// Decode JWT specific base64url encoding with padding stripped // Decode JWT specific base64url encoding with padding stripped
func DecodeSegment(seg string) ([]byte, error) { func DecodeSegment(seg string) ([]byte, error) {
// len % 4 if l := len(seg) % 4; l > 0 {
switch len(seg) % 4 { seg += strings.Repeat("=", 4-l)
case 2:
seg = seg + "=="
case 3:
seg = seg + "==="
} }
return base64.URLEncoding.DecodeString(seg) return base64.URLEncoding.DecodeString(seg)