提交 bc8cc56a 编写于 作者: R Rafael Mendonça França

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.
上级 9fd6011f
......@@ -35,8 +35,8 @@ def initialize(secret, options = {})
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 @@ def verified(signed_message)
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
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册