ExkPasswd.Config.Presets (ExkPasswd v0.1.1)

View Source

Preset registry with compile-time and runtime preset support.

Built-in presets are pre-validated at compile time for zero runtime overhead. Custom presets can be registered at runtime for application-specific configurations.

Built-in Presets

  • :default - Balanced security and memorability (~59 bits entropy)
  • :web32 - For websites allowing up to 32 characters (~65 bits)
  • :web16 - For websites with 16 character limit (~42 bits - ⚠️ low security)
  • :wifi - 63 character WPA2 keys (~85 bits)
  • :apple_id - Meets Apple ID requirements (~55 bits)
  • :security - For security questions (~77 bits)
  • :xkcd - Similar to the famous XKCD comic (~65 bits)

Examples

# Get a built-in preset
config = Presets.get(:xkcd)

# Register a custom preset
Presets.register(:corporate,
  Config.new!(num_words: 4, separator: "-")
)

# Compose from existing preset
Presets.register(:strong_wifi,
  Presets.get(:wifi),
  num_words: 8
)

# List all presets
Presets.list()
#=> [:default, :web32, :web16, :wifi, :apple_id, :security, :xkcd, :corporate, :strong_wifi]

Summary

Functions

Get all built-in presets as a list.

Returns a specification to start this module under a supervisor.

Get a preset by name.

List all available preset names (built-in and runtime).

Register a runtime preset.

Register a preset by composing from a base with overrides.

Start the preset registry Agent.

Functions

all()

@spec all() :: [ExkPasswd.Config.t()]

Get all built-in presets as a list.

Returns

List of Config structs.

Examples

all = Presets.all()
length(all)
#=> 7

child_spec(arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

get(name)

@spec get(atom() | String.t()) :: ExkPasswd.Config.t() | nil

Get a preset by name.

Checks built-in presets first (compile-time, zero overhead), then runtime registry.

Parameters

  • name - Preset name as atom or string

Returns

A Config struct or nil if not found.

Examples

config = Presets.get(:xkcd)
config = Presets.get("wifi")
config = Presets.get(:nonexistent)
#=> nil

list()

@spec list() :: [atom()]

List all available preset names (built-in and runtime).

Returns

List of preset names as atoms.

Examples

Presets.list()
#=> [:default, :web32, :web16, :wifi, :apple_id, :security, :xkcd]

register(name, config)

@spec register(atom(), ExkPasswd.Config.t()) :: :ok

Register a runtime preset.

Parameters

  • name - Preset name (atom)
  • config - A validated Config struct

Returns

:ok

Examples

Presets.register(:corporate,
  Config.new!(num_words: 4, separator: "-")
)

register(name, base, overrides)

@spec register(atom(), atom() | ExkPasswd.Config.t(), keyword()) :: :ok

Register a preset by composing from a base with overrides.

Parameters

  • name - New preset name (atom)
  • base - Base preset name (atom) or Config struct
  • overrides - Keyword list of overrides

Returns

:ok

Examples

# Extend built-in preset
Presets.register(:strong_wifi, :wifi, num_words: 8, digits: {6, 6})

# Extend custom preset
base = Config.new!(num_words: 3)
Presets.register(:custom, base, separator: "_")

start_link(_)

@spec start_link(term()) :: {:ok, pid()} | {:error, term()}

Start the preset registry Agent.

This is typically called by the application supervisor.