Class: Epithet::Config
- Inherits:
-
Object
- Object
- Epithet::Config
- Defined in:
- lib/epithet.rb
Overview
Class for passing around preset configs. See Epithet::configure for options.
Instance Attribute Summary collapse
-
#alphabet ⇒ Object
readonly
:nodoc:.
-
#cipher ⇒ Object
readonly
:nodoc:.
-
#digest ⇒ Object
readonly
:nodoc:.
-
#keygen ⇒ Object
readonly
:nodoc:.
-
#salt ⇒ Object
readonly
:nodoc:.
-
#separator ⇒ Object
readonly
:nodoc:.
Instance Method Summary collapse
-
#initialize(opts = {}) ⇒ Config
constructor
A new instance of Config.
Constructor Details
#initialize(opts = {}) ⇒ Config
Returns a new instance of Config.
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
#alphabet ⇒ Object (readonly)
:nodoc:
165 166 167 |
# File 'lib/epithet.rb', line 165 def alphabet @alphabet end |
#cipher ⇒ Object (readonly)
:nodoc:
165 166 167 |
# File 'lib/epithet.rb', line 165 def cipher @cipher end |
#digest ⇒ Object (readonly)
:nodoc:
165 166 167 |
# File 'lib/epithet.rb', line 165 def digest @digest end |
#keygen ⇒ Object (readonly)
:nodoc:
165 166 167 |
# File 'lib/epithet.rb', line 165 def keygen @keygen end |
#salt ⇒ Object (readonly)
:nodoc:
165 166 167 |
# File 'lib/epithet.rb', line 165 def salt @salt end |
#separator ⇒ Object (readonly)
:nodoc:
165 166 167 |
# File 'lib/epithet.rb', line 165 def separator @separator end |