demarches-normaliennes/app/services/signature_service.rb
2019-01-03 17:48:53 +01:00

22 lines
490 B
Ruby

class SignatureService
class << self
def verify(signature, message)
begin
decoded_message = verifier.verify(signature)
return message == decoded_message
rescue ActiveSupport::MessageVerifier::InvalidSignature
return false
end
end
def sign(message)
verifier.generate(message)
end
private
def verifier
@@verifier ||= ActiveSupport::MessageVerifier.new(Rails.application.secrets.signing_key)
end
end
end