summaryrefslogtreecommitdiffstats
path: root/modules/generate
diff options
context:
space:
mode:
authorGusted <postmaster@gusted.xyz>2024-01-24 16:25:06 +0100
committerEarl Warren <contact@earl-warren.org>2024-02-05 16:54:44 +0100
commit464ae81a36a7933c7b9cd9e38b25cb118b4926d6 (patch)
tree086694610af7bb84ef11d0e78b681b4568b4e3ff /modules/generate
parent[GITEA] Fix typo in formatting error (diff)
downloadforgejo-464ae81a36a7933c7b9cd9e38b25cb118b4926d6.tar.xz
forgejo-464ae81a36a7933c7b9cd9e38b25cb118b4926d6.zip
[GITEA] Refactor generation of JWT secret
- Remove non base64-ed version of JWT secret generation. Because all occurences need the Base64 version. (cherry picked from commit 6a6b5a31a8e38cb953fcca1c8847ea219234f10c) (cherry picked from commit 066b8ca6b40a7342352983de35f1ca6683927426)
Diffstat (limited to 'modules/generate')
-rw-r--r--modules/generate/generate.go16
1 files changed, 4 insertions, 12 deletions
diff --git a/modules/generate/generate.go b/modules/generate/generate.go
index ee3c76059b..df3e2474f9 100644
--- a/modules/generate/generate.go
+++ b/modules/generate/generate.go
@@ -38,22 +38,14 @@ func NewInternalToken() (string, error) {
return internalToken, nil
}
-// NewJwtSecret generates a new value intended to be used for JWT secrets.
-func NewJwtSecret() ([]byte, error) {
+// NewJwtSecret generates a new base64 encoded value intended to be used for JWT secrets.
+func NewJwtSecret() ([]byte, string, error) {
bytes := make([]byte, 32)
- _, err := io.ReadFull(rand.Reader, bytes)
- if err != nil {
- return nil, err
- }
- return bytes, nil
-}
-
-// NewJwtSecretBase64 generates a new base64 encoded value intended to be used for JWT secrets.
-func NewJwtSecretBase64() ([]byte, string, error) {
- bytes, err := NewJwtSecret()
+ _, err := rand.Read(bytes)
if err != nil {
return nil, "", err
}
+
return bytes, base64.RawURLEncoding.EncodeToString(bytes), nil
}