Class: Epithet::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/epithet.rb

Overview

Class for passing around preset configs. See Epithet::configure for options.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(opts = {}) ⇒ Config

Returns a new instance of Config.

Raises:

  • (ArgumentError)


167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/epithet.rb', line 167

def initialize(opts = {})
  opts = opts.dup
  @separator = -String(opts.delete(:separator) { '_' })
  @salt = -String(opts.delete(:salt))
  @alphabet = -String(opts.delete(:alphabet) { Block58::Alphabet })
  @cipher = -(opts.delete(:cipher) || 'aes-256-ecb')
  @digest = -(opts.delete(:digest) || 'sha256')

  cipher = OpenSSL::Cipher.new(@cipher)
  raise ArgumentError, 'separator intersects alphabet' if @separator.bytes.intersect?(@alphabet.bytes)
  raise ArgumentError, "#{@cipher} not a 128-bit block cipher" if cipher.block_size != 16
  raise ArgumentError, "#{@cipher} requires an IV/nonce" if cipher.iv_len != 0
  raise ArgumentError, "#{@digest} produces < 64-bit digest" if OpenSSL::Digest.new(@digest).digest_length < 8

  @keygen = opts.delete(:keygen) || Keygen.new(
    passphrase: opts.delete(:passphrase),
    digest: @digest,
    scrypt: opts.delete(:scrypt) || {})
  raise ArgumentError, "unused option(s) #{opts.keys}" unless opts.empty?
  freeze
end

Instance Attribute Details

#alphabetObject (readonly)

:nodoc:



165
166
167
# File 'lib/epithet.rb', line 165

def alphabet
  @alphabet
end

#cipherObject (readonly)

:nodoc:



165
166
167
# File 'lib/epithet.rb', line 165

def cipher
  @cipher
end

#digestObject (readonly)

:nodoc:



165
166
167
# File 'lib/epithet.rb', line 165

def digest
  @digest
end

#keygenObject (readonly)

:nodoc:



165
166
167
# File 'lib/epithet.rb', line 165

def keygen
  @keygen
end

#saltObject (readonly)

:nodoc:



165
166
167
# File 'lib/epithet.rb', line 165

def salt
  @salt
end

#separatorObject (readonly)

:nodoc:



165
166
167
# File 'lib/epithet.rb', line 165

def separator
  @separator
end