aboutsummaryrefslogtreecommitdiffstats
path: root/modules/base
diff options
context:
space:
mode:
authorCodruț Constantin Gușoi <codrut.gusoi@gmail.com>2018-02-18 18:14:37 +0000
committerLauris BH <lauris@nix.lv>2018-02-18 20:14:37 +0200
commit96c268c0fcc22604103f67821d66fef39944e80b (patch)
treefb5a97ff8557ae18dd22b227e52fcd811320eac3 /modules/base
parente59fe7c8d9eb8e49858cb2d59e8732f6058756ff (diff)
downloadgitea-96c268c0fcc22604103f67821d66fef39944e80b.tar.gz
gitea-96c268c0fcc22604103f67821d66fef39944e80b.zip
Implements generator cli for secrets (#3531)
Signed-off-by: Codruț Constantin Gușoi <codrut.gusoi@gmail.com>
Diffstat (limited to 'modules/base')
-rw-r--r--modules/base/tool.go29
-rw-r--r--modules/base/tool_test.go6
2 files changed, 0 insertions, 35 deletions
diff --git a/modules/base/tool.go b/modules/base/tool.go
index 347241e6bb..16ac4dbff1 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -14,7 +14,6 @@ import (
"html/template"
"io"
"math"
- "math/big"
"net/http"
"net/url"
"path"
@@ -88,25 +87,6 @@ func BasicAuthEncode(username, password string) string {
return base64.StdEncoding.EncodeToString([]byte(username + ":" + password))
}
-// GetRandomString generate random string by specify chars.
-func GetRandomString(n int) (string, error) {
- const alphanum = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
-
- buffer := make([]byte, n)
- max := big.NewInt(int64(len(alphanum)))
-
- for i := 0; i < n; i++ {
- index, err := randomInt(max)
- if err != nil {
- return "", err
- }
-
- buffer[i] = alphanum[index]
- }
-
- return string(buffer), nil
-}
-
// GetRandomBytesAsBase64 generates a random base64 string from n bytes
func GetRandomBytesAsBase64(n int) string {
bytes := make([]byte, 32)
@@ -119,15 +99,6 @@ func GetRandomBytesAsBase64(n int) string {
return base64.RawURLEncoding.EncodeToString(bytes)
}
-func randomInt(max *big.Int) (int, error) {
- rand, err := rand.Int(rand.Reader, max)
- if err != nil {
- return 0, err
- }
-
- return int(rand.Int64()), nil
-}
-
// VerifyTimeLimitCode verify time limit code
func VerifyTimeLimitCode(data string, minutes int, code string) bool {
if len(code) <= 18 {
diff --git a/modules/base/tool_test.go b/modules/base/tool_test.go
index ffa17fae00..f99edd5fbf 100644
--- a/modules/base/tool_test.go
+++ b/modules/base/tool_test.go
@@ -107,12 +107,6 @@ func TestBasicAuthEncode(t *testing.T) {
assert.Equal(t, "Zm9vOmJhcg==", BasicAuthEncode("foo", "bar"))
}
-func TestGetRandomString(t *testing.T) {
- randomString, err := GetRandomString(4)
- assert.NoError(t, err)
- assert.Len(t, randomString, 4)
-}
-
// TODO: Test PBKDF2()
// TODO: Test VerifyTimeLimitCode()
// TODO: Test CreateTimeLimitCode()