aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support
diff options
context:
space:
mode:
authorSantiago Pastorino <santiago@wyeworks.com>2012-11-15 23:06:44 -0200
committerSantiago Pastorino <santiago@wyeworks.com>2012-11-15 23:06:44 -0200
commite6e3317c5409b069782e7b701a11bcd5283794ae (patch)
tree396cb6360bf969d3050bdb91107f28e94183d80d /activesupport/lib/active_support
parentd348c43c1cd6db153410514026a58e2bb2b07095 (diff)
downloadrails-e6e3317c5409b069782e7b701a11bcd5283794ae.tar.gz
rails-e6e3317c5409b069782e7b701a11bcd5283794ae.tar.bz2
rails-e6e3317c5409b069782e7b701a11bcd5283794ae.zip
Add docs for CachingKeyGenerator
Diffstat (limited to 'activesupport/lib/active_support')
-rw-r--r--activesupport/lib/active_support/key_generator.rb6
1 files changed, 6 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/key_generator.rb b/activesupport/lib/active_support/key_generator.rb
index a79bab816a..6beb2b6afa 100644
--- a/activesupport/lib/active_support/key_generator.rb
+++ b/activesupport/lib/active_support/key_generator.rb
@@ -22,12 +22,18 @@ module ActiveSupport
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)