utils

package
v0.0.0-...-f883f01 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 21, 2025 License: AGPL-3.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MinUsernameLength = 10
	MaxUsernameLength = 50
	UsernamePattern   = `^[a-zA-Z0-9_\-.,]{10,50}$`
)

Username validation constants

Variables

View Source
var (
	ErrPasswordTooShort       = errors.New("password must be at least 14 characters long")
	ErrPasswordMissingUpper   = errors.New("password must contain at least one uppercase letter")
	ErrPasswordMissingLower   = errors.New("password must contain at least one lowercase letter")
	ErrPasswordMissingDigit   = errors.New("password must contain at least one digit")
	ErrPasswordMissingSpecial = errors.New("password must contain at least one special character: `~!@#$%^&*()-_=+[]{}|;:,.<>?")
)

Password validation errors

Functions

func GetEnvironmentName

func GetEnvironmentName() string

GetEnvironmentName returns the current environment name

func GetJWTTokenLifetime

func GetJWTTokenLifetime() time.Duration

GetJWTTokenLifetime returns the JWT token lifetime from environment variables Defaults to 30 minutes if not set or invalid

func GetUsernameValidationRules

func GetUsernameValidationRules() string

GetUsernameValidationRules returns a human-readable description of username rules

func IsDevAdminAccount

func IsDevAdminAccount(username string) bool

IsDevAdminAccount checks if a username is a development admin account

func IsHexString

func IsHexString(s string) bool

IsHexString checks if a string contains only hexadecimal characters

func IsProductionEnvironment

func IsProductionEnvironment() bool

IsProductionEnvironment checks if the application is running in production

func IsValidUsername

func IsValidUsername(username string) bool

IsValidUsername returns true if the username is valid, false otherwise

func SanitizeUsername

func SanitizeUsername(username string) string

SanitizeUsername performs basic sanitization on a username Note: This is for display purposes only, not for bypassing validation

func ValidatePasswordComplexity

func ValidatePasswordComplexity(password string) error

ValidatePasswordComplexity checks if a password meets complexity requirements. Requirements: 14+ chars, 1+ upper, 1+ lower, 1+ digit, 1+ special.

func ValidateUsername

func ValidateUsername(username string) error

ValidateUsername validates that a username meets all requirements

Types

type PaddingCalculator

type PaddingCalculator struct{}

PaddingCalculator handles file padding calculations for privacy

func NewPaddingCalculator

func NewPaddingCalculator() *PaddingCalculator

NewPaddingCalculator creates a new padding calculator instance

func (*PaddingCalculator) CalculatePaddedSize

func (p *PaddingCalculator) CalculatePaddedSize(originalSize int64) (int64, error)

CalculatePaddedSize returns the padded size for a given file size using tiered padding with randomization

func (*PaddingCalculator) GeneratePaddingBytes

func (p *PaddingCalculator) GeneratePaddingBytes(size int64) ([]byte, error)

GeneratePaddingBytes generates cryptographically secure random padding bytes

func (*PaddingCalculator) GetPaddingSize

func (p *PaddingCalculator) GetPaddingSize(originalSize, targetSize int64) int64

GetPaddingSize calculates how much padding is needed given original and target sizes

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL