eBooru/app/logical/email_link_validator.rb
Earlopain fc7d84affd
[RuboCop] Enable Style/FrozenStringLiteralComment
This reduces allocations on the posts page by about 5%, from basic testing
2024-02-25 18:15:55 +01:00

25 lines
550 B
Ruby

# frozen_string_literal: true
class EmailLinkValidator
def self.generate(message, purpose, expires = nil)
validator.generate(message, purpose: purpose, expires_in: expires)
end
def self.validate(hash, purpose)
begin
message = validator.verify(hash, purpose: purpose)
return false if message.nil?
return message
rescue
return false
end
end
private
def self.validator
@validator ||= ActiveSupport::MessageVerifier.new(Danbooru.config.email_key, serializer: JSON, digest: "SHA256")
end
end