Skip to content

Commit

Permalink
refactor: use base32 encoder with no padding (#240)
Browse files Browse the repository at this point in the history
  • Loading branch information
leungyauming committed Jul 31, 2021
1 parent 9cb0b0a commit 0a84f35
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions store.go
Expand Up @@ -10,7 +10,6 @@ import (
"net/http"
"os"
"path/filepath"
"strings"
"sync"

"github.com/gorilla/securecookie"
Expand Down Expand Up @@ -201,6 +200,8 @@ func (s *FilesystemStore) New(r *http.Request, name string) (*Session, error) {
return session, err
}

var base32RawStdEncoding = base32.StdEncoding.WithPadding(base32.NoPadding)

// Save adds a single session to the response.
//
// If the Options.MaxAge of the session is <= 0 then the session file will be
Expand All @@ -221,9 +222,8 @@ func (s *FilesystemStore) Save(r *http.Request, w http.ResponseWriter,
if session.ID == "" {
// Because the ID is used in the filename, encode it to
// use alphanumeric characters only.
session.ID = strings.TrimRight(
base32.StdEncoding.EncodeToString(
securecookie.GenerateRandomKey(32)), "=")
session.ID = base32RawStdEncoding.EncodeToString(
securecookie.GenerateRandomKey(32))
}
if err := s.save(session); err != nil {
return err
Expand Down

0 comments on commit 0a84f35

Please sign in to comment.