summaryrefslogtreecommitdiff
path: root/internal/commands/util.go
diff options
context:
space:
mode:
authorJames Elliott <james-d-elliott@users.noreply.github.com>2023-01-07 11:19:41 +1100
committerGitHub <noreply@github.com>2023-01-07 11:19:41 +1100
commitfc5ea5b4857452bacd39f3b12c8a87ec69b4e76a (patch)
treec67cb9ee005d4929fa5a58a05f28291451985d4e /internal/commands/util.go
parentf223975e7973077ce7d9e37240fd0ef80308ecd6 (diff)
refactor(random): add random provider (#4712)
This adds a random provider which makes usage of random operations mockable, and may allow us in the future to swap out the Cryptographical CPU random generator with dedicated hardware random generators.
Diffstat (limited to 'internal/commands/util.go')
-rw-r--r--internal/commands/util.go30
1 files changed, 16 insertions, 14 deletions
diff --git a/internal/commands/util.go b/internal/commands/util.go
index 3142088e7..4950c271b 100644
--- a/internal/commands/util.go
+++ b/internal/commands/util.go
@@ -14,7 +14,7 @@ import (
"golang.org/x/term"
"github.com/authelia/authelia/v4/internal/configuration"
- "github.com/authelia/authelia/v4/internal/utils"
+ "github.com/authelia/authelia/v4/internal/random"
)
func recoverErr(i any) error {
@@ -77,29 +77,29 @@ func flagsGetRandomCharacters(flags *pflag.FlagSet, flagNameLength, flagNameChar
switch c {
case "ascii":
- charset = utils.CharSetASCII
+ charset = random.CharSetASCII
case "alphanumeric":
- charset = utils.CharSetAlphaNumeric
+ charset = random.CharSetAlphaNumeric
case "alphanumeric-lower":
- charset = utils.CharSetAlphabeticLower + utils.CharSetNumeric
+ charset = random.CharSetAlphabeticLower + random.CharSetNumeric
case "alphanumeric-upper":
- charset = utils.CharSetAlphabeticUpper + utils.CharSetNumeric
+ charset = random.CharSetAlphabeticUpper + random.CharSetNumeric
case "alphabetic":
- charset = utils.CharSetAlphabetic
+ charset = random.CharSetAlphabetic
case "alphabetic-lower":
- charset = utils.CharSetAlphabeticLower
+ charset = random.CharSetAlphabeticLower
case "alphabetic-upper":
- charset = utils.CharSetAlphabeticUpper
+ charset = random.CharSetAlphabeticUpper
case "numeric-hex":
- charset = utils.CharSetNumericHex
+ charset = random.CharSetNumericHex
case "numeric":
- charset = utils.CharSetNumeric
+ charset = random.CharSetNumeric
case "rfc3986":
- charset = utils.CharSetRFC3986Unreserved
+ charset = random.CharSetRFC3986Unreserved
case "rfc3986-lower":
- charset = utils.CharSetAlphabeticLower + utils.CharSetNumeric + utils.CharSetSymbolicRFC3986Unreserved
+ charset = random.CharSetAlphabeticLower + random.CharSetNumeric + random.CharSetSymbolicRFC3986Unreserved
case "rfc3986-upper":
- charset = utils.CharSetAlphabeticUpper + utils.CharSetNumeric + utils.CharSetSymbolicRFC3986Unreserved
+ charset = random.CharSetAlphabeticUpper + random.CharSetNumeric + random.CharSetSymbolicRFC3986Unreserved
default:
return "", fmt.Errorf("flag '--%s' with value '%s' is invalid, must be one of 'ascii', 'alphanumeric', 'alphabetic', 'numeric', 'numeric-hex', or 'rfc3986'", flagNameCharSet, c)
}
@@ -109,7 +109,9 @@ func flagsGetRandomCharacters(flags *pflag.FlagSet, flagNameLength, flagNameChar
}
}
- return utils.RandomString(n, charset), nil
+ rand := &random.Cryptographical{}
+
+ return rand.StringCustom(n, charset), nil
}
func termReadConfirmation(flags *pflag.FlagSet, name, prompt, confirmation string) (confirmed bool, err error) {