Module: Sia::Configurable

Included in:
Sia, Safe
Defined in:
lib/sia/configurable.rb

Overview

Sia-wide and Safe-specific configuration

Any Sia-wide custom configuration is passed along to new safes.

Sia.options
# => {:root_dir=>"~/.sia_safes", :index_name=>".sia_index", ...}
Sia.config(root_dir: '/custom/dir')
# => {:root_dir=>"/custom/dir", :index_name=>".sia_index", ...}
Sia::Safe.new(name: 'test', password: 'secret').options
# => {:root_dir=>"/custom/dir", :index_name=>".sia_index", ...}

Safes can only be configured at creation. There is intentionally no API for configuring safes that already exist.

safe = Sia::Safe.new(name: 'test', password: 'secret', index_name: 'hi')
safe.options
# => {:root_dir=>"/custom/dir", :index_name=>"hi", ...}

Hmm... the :root_dir option is still set to our custom directory before, but we don't want to use that anymore. We could manually reset it back to its default, or we can just use set_default_options!.

Sia.set_default_options!(:root_dir)
safe = Sia::Safe.new(name: 'test', password: 'secret', index_name: 'hi')
safe.options
# => {:root_dir=>"~/.sia_safes", :index_name=>"hi", ...}

Constant Summary collapse

DEFAULTS =

Configuration defaults for Sia as a whole and for individual safes

:root_dir - The directory holding all the safes. Within this directory, each safe will have its own directory

:index_name - The name of the encrypted index file within the safe directory. It hold information like which files are in the safe and when they were last opened/closed.

:salt_name - The name of the file within the safe directory that holds the salt string.

:digest_iterations - Changes how long computing the symmetric key from the password will take. The longer the computation takes, the harder for someone to break into the safe.

:buffer_bytes - The buffer size to use when reading/writing files.

:in_place - If true, closed files will be encrypted where they are with a Sia file extension attached to the name. If false, closed files will be moved to the safe dir and renamed to a url-safe hash.

:extension - In-place safes will attach this extension to closed files. Ignored unless :in_place is truthy. Can include the period or not (so '.thing' and 'thing' will both work the same).

:portable - If true, all clear files must be children of the safe dir. Useful if the safe will be shared.

{
  root_dir: Pathname(Dir.home) / '.sia_safes',
  index_name: '.sia_index',
  salt_name: '.sia_salt',
  digest_iterations: 200_000,
  buffer_bytes: 512,
  in_place: false,
  extension: '.sia_closed',
  portable: false,
}.freeze

Instance Method Summary collapse

Instance Method Details

#optionsHash

The configuration options

Returns:

  • (Hash)


74
75
76
# File 'lib/sia/configurable.rb', line 74

def options
  (@options ||= defaults).transform_values(&:dup)
end