aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/lib/active_support/message_verifier.rb
diff options
context:
space:
mode:
authorRafael Mendonça França <rafaelmfranca@gmail.com>2014-12-02 13:10:18 -0200
committerRafael Mendonça França <rafaelmfranca@gmail.com>2014-12-02 13:10:18 -0200
commitbc8cc56a2ae0b73276782d66b7dceba1ecd294a2 (patch)
tree61372ff245fc96d89b3f94428556ba90f460840a /activesupport/lib/active_support/message_verifier.rb
parent9fd6011f40a0fb7792867ef1a48ac0dbbb2ffee0 (diff)
downloadrails-bc8cc56a2ae0b73276782d66b7dceba1ecd294a2.tar.gz
rails-bc8cc56a2ae0b73276782d66b7dceba1ecd294a2.tar.bz2
rails-bc8cc56a2ae0b73276782d66b7dceba1ecd294a2.zip
Prefer object/nil over `true`/`false`
This is the project guideline and the reasons are: * That follows standard Ruby semantics. * Allows the implementation to avoid artificial code like !! or something ? true : false * You do not need to rely on the exact type of 3rd party code. For example, if your method returns str.end_with?('foo') you do not need to make sure end_with? returns a singleton. Your predicate just propagates predicate semantics up regardless of what end_with? returns.
Diffstat (limited to 'activesupport/lib/active_support/message_verifier.rb')
-rw-r--r--activesupport/lib/active_support/message_verifier.rb10
1 files changed, 4 insertions, 6 deletions
diff --git a/activesupport/lib/active_support/message_verifier.rb b/activesupport/lib/active_support/message_verifier.rb
index 8e5d050540..97fb994cff 100644
--- a/activesupport/lib/active_support/message_verifier.rb
+++ b/activesupport/lib/active_support/message_verifier.rb
@@ -35,8 +35,8 @@ module ActiveSupport
end
def valid_message?(signed_message)
- return false if signed_message.blank?
-
+ return if signed_message.blank?
+
data, digest = signed_message.split("--")
data.present? && digest.present? && ActiveSupport::SecurityUtils.secure_compare(digest, generate_digest(data))
end
@@ -47,14 +47,12 @@ module ActiveSupport
data = signed_message.split("--")[0]
@serializer.load(decode(data))
rescue ArgumentError => argument_error
- return false if argument_error.message =~ %r{invalid base64}
+ return if argument_error.message =~ %r{invalid base64}
raise
end
- else
- false
end
end
-
+
def verify(signed_message)
verified(signed_message) || raise(InvalidSignature)
end