Method: ActiveSupport::MessageVerifier#valid_message?

Defined in:
lib/active_support/message_verifier.rb

#valid_message?(message) ⇒ Boolean

Checks if a signed message could have been generated by signing an object with the MessageVerifier‘s secret.

verifier = ActiveSupport::MessageVerifier.new("secret")
signed_message = verifier.generate("signed message")
verifier.valid_message?(signed_message) # => true

tampered_message = signed_message.chop # editing the message invalidates the signature
verifier.valid_message?(tampered_message) # => false

Returns:

  • (Boolean)


169
170
171
# File 'lib/active_support/message_verifier.rb', line 169

def valid_message?(message)
  !!catch_and_ignore(:invalid_message_format) { extract_encoded(message) }
end