Class: PBKDF2
- Inherits:
-
Object
- Object
- PBKDF2
- Defined in:
- lib/puppet_x/icinga2/pbkdf2.rb
Overview
PBKDF2
Constant Summary collapse
- VERSION =
'0.2.2'.freeze
Instance Attribute Summary collapse
-
#hash_function ⇒ Object
Returns the value of attribute hash_function.
-
#iterations ⇒ Object
Returns the value of attribute iterations.
-
#key_length ⇒ Object
Returns the value of attribute key_length.
-
#password ⇒ Object
Returns the value of attribute password.
-
#salt ⇒ Object
Returns the value of attribute salt.
Instance Method Summary collapse
-
#benchmark(iters = 400_000) ⇒ Object
return number of milliseconds it takes to complete one iteration.
- #hex_string ⇒ Object
-
#initialize(opts = {}) {|_self| ... } ⇒ PBKDF2
constructor
A new instance of PBKDF2.
- #value ⇒ Object (also: #bin_string)
Constructor Details
#initialize(opts = {}) {|_self| ... } ⇒ PBKDF2
Returns a new instance of PBKDF2.
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/puppet_x/icinga2/pbkdf2.rb', line 31 def initialize(opts = {}) @hash_function = OpenSSL::Digest.new('sha256') # override with options opts.each_key do |k| if self.respond_to?("#{k}=") self.send("#{k}=", opts[k]) else raise ArgumentError, "Argument '#{k}' is not allowed" end end yield self if block_given? # set this to the default if nothing was given @key_length ||= @hash_function.size # make sure the relevant things got set raise ArgumentError, 'password not set' if @password.nil? raise ArgumentError, 'salt not set' if @salt.nil? raise ArgumentError, 'iterations not set' if @iterations.nil? end |
Instance Attribute Details
#hash_function ⇒ Object
Returns the value of attribute hash_function.
53 54 55 |
# File 'lib/puppet_x/icinga2/pbkdf2.rb', line 53 def hash_function @hash_function end |
#iterations ⇒ Object
Returns the value of attribute iterations.
53 54 55 |
# File 'lib/puppet_x/icinga2/pbkdf2.rb', line 53 def iterations @iterations end |
#key_length ⇒ Object
Returns the value of attribute key_length.
53 54 55 |
# File 'lib/puppet_x/icinga2/pbkdf2.rb', line 53 def key_length @key_length end |
#password ⇒ Object
Returns the value of attribute password.
53 54 55 |
# File 'lib/puppet_x/icinga2/pbkdf2.rb', line 53 def password @password end |
#salt ⇒ Object
Returns the value of attribute salt.
53 54 55 |
# File 'lib/puppet_x/icinga2/pbkdf2.rb', line 53 def salt @salt end |
Instance Method Details
#benchmark(iters = 400_000) ⇒ Object
return number of milliseconds it takes to complete one iteration
95 96 97 98 99 100 101 102 103 |
# File 'lib/puppet_x/icinga2/pbkdf2.rb', line 95 def benchmark(iters = 400_000) iter_orig = @iterations @iterations = iters start = Time.now calculate! time = Time.now - start @iterations = iter_orig time / iters end |
#hex_string ⇒ Object
90 91 92 |
# File 'lib/puppet_x/icinga2/pbkdf2.rb', line 90 def hex_string bin_string.unpack('H*').first end |
#value ⇒ Object Also known as: bin_string
83 84 85 86 |
# File 'lib/puppet_x/icinga2/pbkdf2.rb', line 83 def value calculate! if @value.nil? @value end |