aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJosé Valim <jose.valim@gmail.com>2011-11-09 20:11:46 -0200
committerJosé Valim <jose.valim@gmail.com>2011-11-09 20:21:52 -0200
commita625523e755421b0f96fe5b0a885462ef51582b1 (patch)
tree4d565b0e42f8ed8be5e08fc2c60fbc577e68fb47
parent71e84a3b514b6a2630dfd7f658f4e7597424d6e3 (diff)
downloadrails-a625523e755421b0f96fe5b0a885462ef51582b1.tar.gz
rails-a625523e755421b0f96fe5b0a885462ef51582b1.tar.bz2
rails-a625523e755421b0f96fe5b0a885462ef51582b1.zip
Don't marshal dump twice when using encryptor.
-rw-r--r--activesupport/lib/active_support/message_encryptor.rb13
-rw-r--r--activesupport/test/message_encryptor_test.rb3
2 files changed, 13 insertions, 3 deletions
diff --git a/activesupport/lib/active_support/message_encryptor.rb b/activesupport/lib/active_support/message_encryptor.rb
index 5ab0cc83a7..9ef2b29580 100644
--- a/activesupport/lib/active_support/message_encryptor.rb
+++ b/activesupport/lib/active_support/message_encryptor.rb
@@ -10,6 +10,16 @@ module ActiveSupport
# This can be used in situations similar to the <tt>MessageVerifier</tt>, but where you don't
# want users to be able to determine the value of the payload.
class MessageEncryptor
+ module NullSerializer #:nodoc:
+ def self.load(value)
+ value
+ end
+
+ def self.dump(value)
+ value
+ end
+ end
+
class InvalidMessage < StandardError; end
OpenSSLCipherError = OpenSSL::Cipher.const_defined?(:CipherError) ? OpenSSL::Cipher::CipherError : OpenSSL::CipherError
@@ -21,6 +31,7 @@ module ActiveSupport
@secret = secret
@cipher = options[:cipher] || 'aes-256-cbc'
+ @verifier = MessageVerifier.new(@secret, :serializer => NullSerializer)
@serializer = options[:serializer] || Marshal
end
@@ -86,7 +97,7 @@ module ActiveSupport
end
def verifier
- MessageVerifier.new(@secret)
+ @verifier
end
end
end
diff --git a/activesupport/test/message_encryptor_test.rb b/activesupport/test/message_encryptor_test.rb
index 55c4d42500..3e6a5c6602 100644
--- a/activesupport/test/message_encryptor_test.rb
+++ b/activesupport/test/message_encryptor_test.rb
@@ -11,7 +11,6 @@ require 'active_support/time'
require 'active_support/json'
class MessageEncryptorTest < ActiveSupport::TestCase
-
class JSONSerializer
def dump(value)
ActiveSupport::JSON.encode(value)
@@ -24,7 +23,7 @@ class MessageEncryptorTest < ActiveSupport::TestCase
def setup
@secret = SecureRandom.hex(64)
- @verifier = ActiveSupport::MessageVerifier.new(@secret)
+ @verifier = ActiveSupport::MessageVerifier.new(@secret, :serializer => ActiveSupport::MessageEncryptor::NullSerializer)
@encryptor = ActiveSupport::MessageEncryptor.new(@secret)
@data = { :some => "data", :now => Time.local(2010) }
end