Documentation ¶
Index ¶
- Variables
- type DefaultPaddingService
- type DefaultPasswordGeneratorService
- type DefaultRNGService
- func (s *DefaultRNGService) Generate() (int, error)
- func (s *DefaultRNGService) GenerateDigit() (int, error)
- func (s *DefaultRNGService) GenerateSlice(length int) ([]int, error)
- func (s *DefaultRNGService) GenerateSliceWithMax(length int, max int) ([]int, error)
- func (s *DefaultRNGService) GenerateWithMax(max int) (int, error)
- type DefaultSeparatorService
- type DefaultTransformerService
- type DefaultWordListService
- type PaddingService
- type PasswordGeneratorService
- type RNGService
- type SeparatorService
- type TransformerService
- type WordListService
Constants ¶
This section is empty.
Variables ¶
var ( ErrRNGMaxLessThanOne = errors.New("rng max cannot be less than 1") ErrRNGSliceLengthLessThanZero = errors.New("rng slice length cannot be less than 0") )
Functions ¶
This section is empty.
Types ¶
type DefaultPaddingService ¶
type DefaultPaddingService struct {
// contains filtered or unexported fields
}
Implements the PaddingService interface. It provides methods to add padding to strings based on predefined configuration settings.
func NewPaddingService ¶
func NewPaddingService(cfg *config.Settings, rngSvc RNGService) (*DefaultPaddingService, error)
Creates a new instance of DefaultPaddingService with the provided configuration and RNGService. It returns an error if the provided configuration is invalid.
type DefaultPasswordGeneratorService ¶
type DefaultPasswordGeneratorService struct {
// contains filtered or unexported fields
}
DefaultPasswordGeneratorService implements the PasswordGeneratorService interface providing a concrete implementation for password generation. It combines various services like transformers, separators, padders, and word list services to generate passwords based on provided configuration.
func NewCustomPasswordGeneratorService ¶
func NewCustomPasswordGeneratorService( cfg *config.Settings, transformerSvc TransformerService, separatorSvc SeparatorService, paddingSvc PaddingService, wordListSvc WordListService, ) (*DefaultPasswordGeneratorService, error)
NewCustomPasswordGeneratorService constructs a new instance of DefaultPasswordGeneratorService with the provided services and configuration. It validates the configuration and returns an error if the configuration is invalid (e.g., number of passwords is less than 1).
func NewPasswordGeneratorService ¶
func NewPasswordGeneratorService( cfg *config.Settings, ) (*DefaultPasswordGeneratorService, error)
NewPasswordGeneratorService constructs a DefaultPasswordGeneratorService with default implementations for its dependent services (transformer, separator, padding, and word list services). It initializes each service with the provided configuration and random number generator service.
func (*DefaultPasswordGeneratorService) Generate ¶
func (s *DefaultPasswordGeneratorService) Generate() ([]string, error)
Generate creates a list of passwords using the services provided to the DefaultPasswordGeneratorService instance and returns the list of generated passwords or the first error if one or more is encountered.
type DefaultRNGService ¶
type DefaultRNGService struct{}
DefaultRNGService is a struct implementing the RNGService interface.
func NewRNGService ¶
func NewRNGService() *DefaultRNGService
Creates a new instance of DefaultRNGService.
func (*DefaultRNGService) Generate ¶
func (s *DefaultRNGService) Generate() (int, error)
Generates a random integer with the maximum possible value for int.
func (*DefaultRNGService) GenerateDigit ¶
func (s *DefaultRNGService) GenerateDigit() (int, error)
GenerateDigit generates a single digit (0-9).
func (*DefaultRNGService) GenerateSlice ¶
func (s *DefaultRNGService) GenerateSlice(length int) ([]int, error)
Generates a slice of random integers with the maximum possible value for int.
func (*DefaultRNGService) GenerateSliceWithMax ¶
func (s *DefaultRNGService) GenerateSliceWithMax(length int, max int) ([]int, error)
Generates a slice of random integers, each up to the specified maximum value.
func (*DefaultRNGService) GenerateWithMax ¶
func (s *DefaultRNGService) GenerateWithMax(max int) (int, error)
Generates a random integer up to the specified maximum value.
type DefaultSeparatorService ¶
type DefaultSeparatorService struct {
// contains filtered or unexported fields
}
Implements the SeparatorService, providing functionality to separate string slices.
func NewSeparatorService ¶
func NewSeparatorService(cfg *config.Settings, rngSvc RNGService) (*DefaultSeparatorService, error)
Creates a new instance of DefaultSeparatorService. It validates the provided configuration and returns an error if the configuration is invalid.
func (*DefaultSeparatorService) Separate ¶
func (s *DefaultSeparatorService) Separate(slice []string) ([]string, error)
Separate takes a slice of strings and inserts a separator character between each element of the slice. The separator character is determined based on the configuration. It returns the modified slice or an error if the separator character cannot be determined.
type DefaultTransformerService ¶
type DefaultTransformerService struct {
// contains filtered or unexported fields
}
Implements the TransformerService, providing functionality to transform string slices based on a predefined configuration.
func NewTransformerService ¶
func NewTransformerService(cfg *config.Settings, rngSvc RNGService) (*DefaultTransformerService, error)
Creates a new valid instance of DefaultTransformerService with the given configuration and RNG service
func (*DefaultTransformerService) Transform ¶
func (s *DefaultTransformerService) Transform(slice []string) ([]string, error)
Transform takes a slice of strings and transforms each element according to the configured transformation rule. Returns the transformed slice or an error if the transformation fails.
Transform Types:
- Alternate
- AlternateLettercase
- Capitalise
- CapitaliseInvert
- Invert
- Lower
- LowerVowelUpperConsonant
- Random
- Sentence
- Upper
type DefaultWordListService ¶
type DefaultWordListService struct {
// contains filtered or unexported fields
}
Implements the interface WordListService, providing functionality to extract words from a word list.
func NewWordListService ¶
func NewWordListService(cfg *config.Settings, rngSvc RNGService) (*DefaultWordListService, error)
Creates a new instance of DefaultWordListService. It requires configuration and a random number generation service. It returns an error if the configuration is invalid.
func (*DefaultWordListService) GetWords ¶
func (s *DefaultWordListService) GetWords() ([]string, error)
Creates a slice of words randomly extracted from a word list. It returns an error if the slice cannot be created.
type PaddingService ¶
type PaddingService interface { // Takes a slice of strings and applies extra characters or digits // and joins the slice, or returns an error Pad(slice []string) (string, error) }
Defines the interface for a service that provides functionality to pad a slice of strings.
type PasswordGeneratorService ¶
type PasswordGeneratorService interface { // Generate creates a list of passwords and returns the list or an error Generate() ([]string, error) }
PasswordGeneratorService defines the interface for a service that generates passwords. It requires an implementation of the Generate method that returns a slice of strings representing generated passwords and an error if the generation process fails.
type RNGService ¶
type RNGService interface { // Generates a random integer up to the specified maximum value. GenerateWithMax(max int) (int, error) // Generates a random integer Generate() (int, error) // Generates a single digit (0-9). GenerateDigit() (int, error) // Generates a slice of random integers GenerateSlice(length int) ([]int, error) // Generates a slice of random integers, each up to the specified maximum value. GenerateSliceWithMax(length int, max int) ([]int, error) }
RNGService defines an interface for random number generation. It provides methods for generating random integers and slices of integers.
type SeparatorService ¶
type SeparatorService interface { // Separate takes a slice of strings and inserts a separator character // between each element of the slice or returns an error if the slice // cannot be separated Separate(slice []string) ([]string, error) }
Defines the interface for a service that can separate elements of a string slice.
type TransformerService ¶
type TransformerService interface { // Transform takes a slice of strings and transforms each element or returns // an error if the transformation fails. Transform(slice []string) ([]string, error) }
Defines an interface for transforming a slice of strings
type WordListService ¶
type WordListService interface { // GetWords returns a slice of words extracted from a word list or an error // if the words cannot be extracted. GetWords() ([]string, error) }
Defines the interface for a service that extracts words from word lists