1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Don't marshal dump twice when using encryptor.

This commit is contained in:
José Valim 2011-11-09 20:11:46 -02:00
parent 71e84a3b51
commit a625523e75
2 changed files with 13 additions and 3 deletions

View file

@ -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

View file

@ -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