Skip to content

Commit

Permalink
xsrftoken: create no padding base64 string by RawURLEncoding.
Browse files Browse the repository at this point in the history
Getting the no padding base64 string with base64.RawURLEncoding to
reduce the costs.
  • Loading branch information
ghosind committed Jul 20, 2024
1 parent 032e4e4 commit a8263b5
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions xsrftoken/xsrf.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,9 @@ func generateTokenAtTime(key, userID, actionID string, now time.Time) string {
h := hmac.New(sha1.New, []byte(key))
fmt.Fprintf(h, "%s:%s:%d", clean(userID), clean(actionID), milliTime)

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

return fmt.Sprintf("%s:%d", tok, milliTime)
}
Expand Down

0 comments on commit a8263b5

Please sign in to comment.