Class: ActiveElasticJob::MessageVerifier
- Inherits:
-
Object
- Object
- ActiveElasticJob::MessageVerifier
- Defined in:
- lib/active_elastic_job/message_verifier.rb
Overview
:nodoc:
Defined Under Namespace
Classes: InvalidDigest
Instance Method Summary collapse
- #generate_digest(message) ⇒ Object
-
#initialize(secret) ⇒ MessageVerifier
constructor
A new instance of MessageVerifier.
- #verify(message, digest) ⇒ Object
- #verify!(message, digest) ⇒ Object
Constructor Details
#initialize(secret) ⇒ MessageVerifier
Returns a new instance of MessageVerifier.
12 13 14 |
# File 'lib/active_elastic_job/message_verifier.rb', line 12 def initialize(secret) @secret = secret end |
Instance Method Details
#generate_digest(message) ⇒ Object
29 30 31 32 |
# File 'lib/active_elastic_job/message_verifier.rb', line 29 def generate_digest() require 'openssl' unless defined?(OpenSSL) OpenSSL::HMAC.hexdigest(OpenSSL::Digest::SHA1.new, @secret, ) end |
#verify(message, digest) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/active_elastic_job/message_verifier.rb', line 16 def verify(, digest) if .nil? || .blank? || digest.nil? || digest.blank? return false end return ActiveSupport::SecurityUtils.secure_compare( digest, generate_digest()) end |
#verify!(message, digest) ⇒ Object
25 26 27 |
# File 'lib/active_elastic_job/message_verifier.rb', line 25 def verify!(, digest) raise InvalidDigest unless verify(, digest) end |