diff options
author | Ryan Mohr <ryan.mohr@gmail.com> | 2014-11-12 12:48:44 -1000 |
---|---|---|
committer | Ryan Mohr <ryan.mohr@gmail.com> | 2014-11-12 12:48:44 -1000 |
commit | 8573de4d10188372ebab9509238210ed1c6a30f8 (patch) | |
tree | aa28ce61735ae45327f91c103c196c0baacee82a | |
parent | 6ff78469cd70ce821dd1455f3607780863f5a9d7 (diff) | |
download | rails-8573de4d10188372ebab9509238210ed1c6a30f8.tar.gz rails-8573de4d10188372ebab9509238210ed1c6a30f8.tar.bz2 rails-8573de4d10188372ebab9509238210ed1c6a30f8.zip |
Abstract encoding strategy for ActiveSupport::MessageVerifier
-rw-r--r-- | activesupport/lib/active_support/message_verifier.rb | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/activesupport/lib/active_support/message_verifier.rb b/activesupport/lib/active_support/message_verifier.rb index 4e0796f4f8..a8a8de5672 100644 --- a/activesupport/lib/active_support/message_verifier.rb +++ b/activesupport/lib/active_support/message_verifier.rb @@ -40,7 +40,7 @@ module ActiveSupport data, digest = signed_message.split("--") if data.present? && digest.present? && ActiveSupport::SecurityUtils.secure_compare(digest, generate_digest(data)) begin - @serializer.load(::Base64.strict_decode64(data)) + @serializer.load(decode(data)) rescue ArgumentError => argument_error raise InvalidSignature if argument_error.message =~ %r{invalid base64} raise @@ -51,11 +51,19 @@ module ActiveSupport end def generate(value) - data = ::Base64.strict_encode64(@serializer.dump(value)) + data = encode(@serializer.dump(value)) "#{data}--#{generate_digest(data)}" end private + def encode(data) + ::Base64.strict_encode64(data) + end + + def decode(data) + ::Base64.strict_decode64(data) + end + def generate_digest(data) require 'openssl' unless defined?(OpenSSL) OpenSSL::HMAC.hexdigest(OpenSSL::Digest.const_get(@digest).new, @secret, data) |