utils

package
v0.0.0-...-8f4f983 Latest Latest
Warning

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

Go to latest
Published: May 8, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

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

Username validation constants

Variables

This section is empty.

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 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 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 percentage-based block alignment with randomized jitter.

Block size = 2% of file size (minimum 64KB). The file is rounded up to the nearest block boundary, then random jitter (0 to 10% of block size) is added. This gives a consistent worst-case padding overhead of ~2.2% for files above 3.2MB, with the 64KB minimum floor providing size obfuscation for smaller files at negligible absolute cost.

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