diff options
author | Dmitry Polushkin <dmitry.polushkin@gmail.com> | 2011-10-01 20:49:14 +0100 |
---|---|---|
committer | Dmitry Polushkin <dmitry.polushkin@gmail.com> | 2011-10-01 20:49:14 +0100 |
commit | 19965402b2f868c79d78269ca17cb6282f271382 (patch) | |
tree | 8635415f386595650c27469d6b6d04335121d070 /activesupport/lib/active_support/message_encryptor.rb | |
parent | 9d54f8994d09db5435d6c234430ae13333928fb9 (diff) | |
parent | ec53b802dab9b676dcc9b53e542bcd840983b7a2 (diff) | |
download | rails-19965402b2f868c79d78269ca17cb6282f271382.tar.gz rails-19965402b2f868c79d78269ca17cb6282f271382.tar.bz2 rails-19965402b2f868c79d78269ca17cb6282f271382.zip |
Merge branch 'master' of git://github.com/rails/rails
Diffstat (limited to 'activesupport/lib/active_support/message_encryptor.rb')
-rw-r--r-- | activesupport/lib/active_support/message_encryptor.rb | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/message_encryptor.rb b/activesupport/lib/active_support/message_encryptor.rb index 4f7cd12d48..e14386a85d 100644 --- a/activesupport/lib/active_support/message_encryptor.rb +++ b/activesupport/lib/active_support/message_encryptor.rb @@ -13,9 +13,15 @@ module ActiveSupport class InvalidMessage < StandardError; end OpenSSLCipherError = OpenSSL::Cipher.const_defined?(:CipherError) ? OpenSSL::Cipher::CipherError : OpenSSL::CipherError - def initialize(secret, cipher = 'aes-256-cbc') + def initialize(secret, options = {}) + unless options.is_a?(Hash) + ActiveSupport::Deprecation.warn "The second parameter should be an options hash. Use :cipher => 'algorithm' to specify the cipher algorithm." + options = { :cipher => options } + end + @secret = secret - @cipher = cipher + @cipher = options[:cipher] || 'aes-256-cbc' + @serializer = options[:serializer] || Marshal end def encrypt(value) @@ -27,7 +33,7 @@ module ActiveSupport cipher.key = @secret cipher.iv = iv - encrypted_data = cipher.update(Marshal.dump(value)) + encrypted_data = cipher.update(@serializer.dump(value)) encrypted_data << cipher.final [encrypted_data, iv].map {|v| ActiveSupport::Base64.encode64s(v)}.join("--") @@ -44,7 +50,7 @@ module ActiveSupport decrypted_data = cipher.update(encrypted_data) decrypted_data << cipher.final - Marshal.load(decrypted_data) + @serializer.load(decrypted_data) rescue OpenSSLCipherError, TypeError raise InvalidMessage end |