demarches-normaliennes/app/services/signature_service.rb

23 lines
490 B
Ruby
Raw Normal View History

2018-04-03 16:26:24 +02:00
class SignatureService
class << self
def verify(signature, message)
begin
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)
verifier.generate(message)
2018-04-03 16:26:24 +02:00
end
private
def verifier
@@verifier ||= ActiveSupport::MessageVerifier.new(Rails.application.secrets.signing_key)
2018-04-03 16:26:24 +02:00
end
end
end