Documentation
¶
Index ¶
- func CryptoRandomBytes(length int) ([]byte, error)
- func CryptoRandomString(length int) (string, error)
- func GetIPFromContext(ctx context.Context) string
- func HashToken(token, salt string) string
- func IsRedirectSafe(redirectURL, baseURL string) bool
- func SHA256Hex(s string) string
- func ScopeSet(scopes string) map[string]bool
- func SetIPContext(ctx context.Context, ip string) context.Context
- func TruncateString(s string, maxLen int) string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CryptoRandomBytes ¶
CryptoRandomBytes generates cryptographically secure random bytes
func CryptoRandomString ¶
CryptoRandomString generates a random hex string for salts
func GetIPFromContext ¶
GetIPFromContext extracts the client IP address from the context. Returns empty string if IP cannot be determined.
func HashToken ¶
HashToken returns PBKDF2 hash of token with salt Parameters match Gitea's implementation for security consistency
func IsRedirectSafe ¶ added in v0.14.0
IsRedirectSafe validates that a redirect URL is safe to use. It only allows: 1. Relative paths starting with "/" but not "//" 2. Absolute URLs that match the baseURL host
func SHA256Hex ¶ added in v0.15.0
SHA256Hex returns the SHA-256 hash of s as a lowercase hex string. Intended for use with high-entropy, unguessable values (e.g., randomly generated tokens); for such inputs, a salt is not required for security.
func ScopeSet ¶ added in v0.18.0
ScopeSet parses a space-separated scope string into a boolean lookup map.
func SetIPContext ¶ added in v0.14.0
SetIPContext embeds client IP into a standard context
func TruncateString ¶ added in v0.18.0
TruncateString truncates s to maxLen runes and appends "..." if truncated.
Types ¶
This section is empty.