aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/message_verifier.rb
diff options
context:
space:
mode:
Diffstat (limited to 'activesupport/lib/active_support/message_verifier.rb')
-rw-r--r--activesupport/lib/active_support/message_verifier.rb17
1 files changed, 10 insertions, 7 deletions
diff --git a/activesupport/lib/active_support/message_verifier.rb b/activesupport/lib/active_support/message_verifier.rb
index 0181070479..57317028fc 100644
--- a/activesupport/lib/active_support/message_verifier.rb
+++ b/activesupport/lib/active_support/message_verifier.rb
@@ -26,12 +26,15 @@ module ActiveSupport
class MessageVerifier
class InvalidSignature < StandardError; end
- attr_accessor :serializer
-
- def initialize(secret, digest = 'SHA1', serializer = Marshal)
+ def initialize(secret, options = {})
+ unless options.is_a?(Hash)
+ ActiveSupport::Deprecation.warn "The second parameter should be an options hash. Use :digest => 'algorithm' to sepcify the digest algorithm."
+ options = { :digest => options }
+ end
+
@secret = secret
- @digest = digest
- @serializer = serializer
+ @digest = options[:digest] || 'SHA1'
+ @serializer = options[:serializer] || Marshal
end
def verify(signed_message)
@@ -39,14 +42,14 @@ module ActiveSupport
data, digest = signed_message.split("--")
if data.present? && digest.present? && secure_compare(digest, generate_digest(data))
- serializer.load(ActiveSupport::Base64.decode64(data))
+ @serializer.load(ActiveSupport::Base64.decode64(data))
else
raise InvalidSignature
end
end
def generate(value)
- data = ActiveSupport::Base64.encode64s(serializer.dump(value))
+ data = ActiveSupport::Base64.encode64s(@serializer.dump(value))
"#{data}--#{generate_digest(data)}"
end