Permalink
Browse files

Add docs for CachingKeyGenerator

  • Loading branch information...
1 parent d348c43 commit e6e3317c5409b069782e7b701a11bcd5283794ae @spastorino spastorino committed Nov 16, 2012
Showing with 6 additions and 0 deletions.
  1. +6 −0 activesupport/lib/active_support/key_generator.rb
@@ -22,12 +22,18 @@ def generate_key(salt, key_size=64)
end
end
+ # 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 CachingKeyGenerator
def initialize(key_generator)
@key_generator = key_generator
@cache_keys = {}.extend(Mutex_m)
end
+ # 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
def generate_key(salt, key_size=64)
@cache_keys.synchronize do
@cache_keys["#{salt}#{key_size}"] ||= @key_generator.generate_key(salt, key_size)

0 comments on commit e6e3317

Please sign in to comment.