2018-04-03 16:26:24 +02:00
|
|
|
class SignatureService
|
|
|
|
class << self
|
|
|
|
def verify(signature, message)
|
|
|
|
begin
|
2019-01-03 17:14:26 +01:00
|
|
|
decoded_message = verifier.verify(signature)
|
|
|
|
return message == decoded_message
|
|
|
|
rescue ActiveSupport::MessageVerifier::InvalidSignature
|
2018-04-03 16:26:24 +02:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def sign(message)
|
2019-01-03 17:14:26 +01:00
|
|
|
verifier.generate(message)
|
2018-04-03 16:26:24 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
2019-01-03 17:14:26 +01:00
|
|
|
def verifier
|
|
|
|
@@verifier ||= ActiveSupport::MessageVerifier.new(Rails.application.secrets.signing_key)
|
2018-04-03 16:26:24 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|