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
-
#cipher ⇒ Object
readonly
:nodoc:.
-
#codec ⇒ Object
readonly
:nodoc:.
-
#context ⇒ Object
readonly
:nodoc:.
-
#digest ⇒ Object
readonly
:nodoc:.
-
#keygen ⇒ 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.
177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 |
# File 'lib/epithet.rb', line 177 def initialize(opts = {}) opts = opts.dup @separator = -String(opts.delete(:separator) { '_' }) @context = -String(opts.delete(:context)) alphabet = String(opts.delete(:alphabet) { Block58::Alphabet }) @cipher = -(opts.delete(:cipher) || 'aes-256-ecb').downcase @digest = -(opts.delete(:digest) || 'sha256').downcase keygen, passphrase, scrypt = %i[keygen passphrase scrypt].map { opts.delete it } 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 raise ArgumentError, 'use keygen: or passphrase:, not both' if keygen && (passphrase || scrypt) raise ArgumentError, 'one of passphrase: or keygen: is required' unless keygen || passphrase raise ArgumentError, "unused option(s) #{opts.keys}" unless opts.empty? @codec = Block58.build(cipher.block_size, alphabet:) @keygen = keygen || Keygen.new(passphrase:, digest: @digest, scrypt:) freeze end |
Instance Attribute Details
#cipher ⇒ Object (readonly)
:nodoc:
175 176 177 |
# File 'lib/epithet.rb', line 175 def cipher @cipher end |
#codec ⇒ Object (readonly)
:nodoc:
175 176 177 |
# File 'lib/epithet.rb', line 175 def codec @codec end |
#context ⇒ Object (readonly)
:nodoc:
175 176 177 |
# File 'lib/epithet.rb', line 175 def context @context end |
#digest ⇒ Object (readonly)
:nodoc:
175 176 177 |
# File 'lib/epithet.rb', line 175 def digest @digest end |
#keygen ⇒ Object (readonly)
:nodoc:
175 176 177 |
# File 'lib/epithet.rb', line 175 def keygen @keygen end |
#separator ⇒ Object (readonly)
:nodoc:
175 176 177 |
# File 'lib/epithet.rb', line 175 def separator @separator end |