diff options
author | Sean Griffin <sean@seantheprogrammer.com> | 2014-12-02 07:11:15 -0700 |
---|---|---|
committer | Sean Griffin <sean@seantheprogrammer.com> | 2014-12-02 07:11:15 -0700 |
commit | 47af13cfb562a8048c68ffe59687eacb9d5a9ad9 (patch) | |
tree | d7d83c39e3b60f13bc07ada3aa9832a22b36f134 /activesupport/lib/active_support/message_verifier.rb | |
parent | fc32d02b08f09270bd9fe5a7d17cf0665786c787 (diff) | |
parent | 7ad541f955dfa396f4a6b29700bed2e188cd9187 (diff) | |
download | rails-47af13cfb562a8048c68ffe59687eacb9d5a9ad9.tar.gz rails-47af13cfb562a8048c68ffe59687eacb9d5a9ad9.tar.bz2 rails-47af13cfb562a8048c68ffe59687eacb9d5a9ad9.zip |
Merge pull request #17727 from lleger/lleger-add-methods-to-message-verifier
Add new methods to MessageVerifier
Diffstat (limited to 'activesupport/lib/active_support/message_verifier.rb')
-rw-r--r-- | activesupport/lib/active_support/message_verifier.rb | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/message_verifier.rb b/activesupport/lib/active_support/message_verifier.rb index a8a8de5672..8e5d050540 100644 --- a/activesupport/lib/active_support/message_verifier.rb +++ b/activesupport/lib/active_support/message_verifier.rb @@ -34,21 +34,30 @@ module ActiveSupport @serializer = options[:serializer] || Marshal end - def verify(signed_message) - raise InvalidSignature if signed_message.blank? - + def valid_message?(signed_message) + return false if signed_message.blank? + data, digest = signed_message.split("--") - if data.present? && digest.present? && ActiveSupport::SecurityUtils.secure_compare(digest, generate_digest(data)) + data.present? && digest.present? && ActiveSupport::SecurityUtils.secure_compare(digest, generate_digest(data)) + end + + def verified(signed_message) + if valid_message?(signed_message) begin + data = signed_message.split("--")[0] @serializer.load(decode(data)) rescue ArgumentError => argument_error - raise InvalidSignature if argument_error.message =~ %r{invalid base64} + return false if argument_error.message =~ %r{invalid base64} raise end else - raise InvalidSignature + false end end + + def verify(signed_message) + verified(signed_message) || raise(InvalidSignature) + end def generate(value) data = encode(@serializer.dump(value)) |