Skip to content

Commit a8263b5

Browse files
committed
xsrftoken: create no padding base64 string by RawURLEncoding.
Getting the no padding base64 string with base64.RawURLEncoding to reduce the costs.
1 parent 032e4e4 commit a8263b5

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

xsrftoken/xsrf.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,9 @@ func generateTokenAtTime(key, userID, actionID string, now time.Time) string {
4545
h := hmac.New(sha1.New, []byte(key))
4646
fmt.Fprintf(h, "%s:%s:%d", clean(userID), clean(actionID), milliTime)
4747

48-
// Get the padded base64 string then removing the padding.
48+
// Get the no padding base64 string.
4949
tok := string(h.Sum(nil))
50-
tok = base64.URLEncoding.EncodeToString([]byte(tok))
51-
tok = strings.TrimRight(tok, "=")
50+
tok = base64.RawURLEncoding.EncodeToString([]byte(tok))
5251

5352
return fmt.Sprintf("%s:%d", tok, milliTime)
5453
}

0 commit comments

Comments
 (0)