diff options
author | Santiago Pastorino <santiago@wyeworks.com> | 2012-11-01 20:23:21 -0200 |
---|---|---|
committer | Santiago Pastorino <santiago@wyeworks.com> | 2012-11-03 14:57:54 -0200 |
commit | 851e8fe897633f095a0f39a91f8bc75eee7a76aa (patch) | |
tree | 22d5d2d4e4d35c2528790d756537b4e9fa590a4a /activesupport/lib | |
parent | 47da5744741f0af668d2f915e09003be35dcce66 (diff) | |
download | rails-851e8fe897633f095a0f39a91f8bc75eee7a76aa.tar.gz rails-851e8fe897633f095a0f39a91f8bc75eee7a76aa.tar.bz2 rails-851e8fe897633f095a0f39a91f8bc75eee7a76aa.zip |
Cache generated keys per KeyGenerator instance using salt + key_size
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/key_generator.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/key_generator.rb b/activesupport/lib/active_support/key_generator.rb index 8b49ad8414..a8a4c17fd6 100644 --- a/activesupport/lib/active_support/key_generator.rb +++ b/activesupport/lib/active_support/key_generator.rb @@ -1,3 +1,4 @@ +require 'mutex_m' require 'openssl' module ActiveSupport @@ -21,6 +22,19 @@ module ActiveSupport end end + class CachingKeyGenerator + def initialize(key_generator) + @key_generator = key_generator + @cache_keys = {}.extend(Mutex_m) + end + + def generate_key(salt, key_size=64) + @cache_keys.synchronize do + @cache_keys["#{salt}#{key_size}"] ||= @key_generator.generate_key(salt, key_size) + end + end + end + class DummyKeyGenerator def initialize(secret) @secret = secret |