Class: ActiveSupport::CachingKeyGenerator
Relationships & Source Files | |
Inherits: | Object |
Defined in: | activesupport/lib/active_support/key_generator.rb |
Overview
CachingKeyGenerator
is a wrapper around KeyGenerator which allows users to avoid re-executing the key generation process when it's called using the same salt and key_size
Class Method Summary
- .new(key_generator) ⇒ CachingKeyGenerator constructor
Instance Method Summary
-
#generate_key(salt, key_size = 64)
Returns a derived key suitable for use.
Constructor Details
.new(key_generator) ⇒ CachingKeyGenerator
# File 'activesupport/lib/active_support/key_generator.rb', line 29
def initialize(key_generator) @key_generator = key_generator @cache_keys = ThreadSafe::Cache.new end
Instance Method Details
#generate_key(salt, key_size = 64)
Returns a derived key suitable for use. The default key_size is chosen to be compatible with the default settings of MessageVerifier. i.e. OpenSSL::Digest::SHA1#block_length
# File 'activesupport/lib/active_support/key_generator.rb', line 37
def generate_key(salt, key_size=64) @cache_keys["#{salt}#{key_size}"] ||= @key_generator.generate_key(salt, key_size) end