From 679bf0f3c975ebe7f610e09854cdf820603be862 Mon Sep 17 00:00:00 2001 From: Henry Date: Tue, 3 Jun 2014 16:15:11 +0200 Subject: [PATCH] Fixes #22 - Padding issue in Go1.3 rc1 --- jwt.go | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/jwt.go b/jwt.go index d4f191a..b630593 100644 --- a/jwt.go +++ b/jwt.go @@ -217,12 +217,8 @@ func EncodeSegment(seg []byte) string { // Decode JWT specific base64url encoding with padding stripped func DecodeSegment(seg string) ([]byte, error) { - // len % 4 - switch len(seg) % 4 { - case 2: - seg = seg + "==" - case 3: - seg = seg + "===" + if l := len(seg) % 4; l > 0 { + seg += strings.Repeat("=", 4-l) } return base64.URLEncoding.DecodeString(seg)