Switch GenerateRandomBytes() method to public
This commit is contained in:
parent
b2a83e3022
commit
4d82e29793
|
@ -10,20 +10,23 @@ import (
|
||||||
// CreateCookieSessionStore creates and returns a new cookie session store
|
// CreateCookieSessionStore creates and returns a new cookie session store
|
||||||
// with random authentication and encryption keys
|
// with random authentication and encryption keys
|
||||||
func CreateCookieSessionStore(authKeySize, encryptKeySize int, defaultOptions *sessions.Options) (sessions.Store, error) {
|
func CreateCookieSessionStore(authKeySize, encryptKeySize int, defaultOptions *sessions.Options) (sessions.Store, error) {
|
||||||
authenticationKey, err := generateRandomBytes(authKeySize)
|
authenticationKey, err := GenerateRandomBytes(authKeySize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "error while generating cookie authentication key")
|
return nil, errors.Wrap(err, "error while generating cookie authentication key")
|
||||||
}
|
}
|
||||||
encryptionKey, err := generateRandomBytes(encryptKeySize)
|
|
||||||
|
encryptionKey, err := GenerateRandomBytes(encryptKeySize)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "error while generating cookie encryption key")
|
return nil, errors.Wrap(err, "error while generating cookie encryption key")
|
||||||
}
|
}
|
||||||
|
|
||||||
store := sessions.NewCookieStore(authenticationKey, encryptionKey)
|
store := sessions.NewCookieStore(authenticationKey, encryptionKey)
|
||||||
store.Options = defaultOptions
|
store.Options = defaultOptions
|
||||||
|
|
||||||
return store, nil
|
return store, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func generateRandomBytes(n int) ([]byte, error) {
|
func GenerateRandomBytes(n int) ([]byte, error) {
|
||||||
b := make([]byte, n)
|
b := make([]byte, n)
|
||||||
_, err := rand.Read(b)
|
_, err := rand.Read(b)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
Loading…
Reference in New Issue