Class: Devise::CachingKeyGenerator
- Inherits:
-
Object
- Object
- Devise::CachingKeyGenerator
- Defined in:
- lib/devise/token_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
Instance Method Summary collapse
-
#generate_key(salt, key_size = 64) ⇒ Object
Returns a derived key suitable for use.
-
#initialize(key_generator) ⇒ CachingKeyGenerator
constructor
A new instance of CachingKeyGenerator.
Constructor Details
#initialize(key_generator) ⇒ CachingKeyGenerator
Returns a new instance of CachingKeyGenerator.
58 59 60 61 |
# File 'lib/devise/token_generator.rb', line 58 def initialize(key_generator) @key_generator = key_generator @cache_keys = ThreadSafe::Cache.new end |
Instance Method Details
#generate_key(salt, key_size = 64) ⇒ Object
Returns a derived key suitable for use. The default key_size is chosen to be compatible with the default settings of ActiveSupport::MessageVerifier. i.e. OpenSSL::Digest::SHA1#block_length
66 67 68 |
# File 'lib/devise/token_generator.rb', line 66 def generate_key(salt, key_size=64) @cache_keys["#{salt}#{key_size}"] ||= @key_generator.generate_key(salt, key_size) end |