<commit_before>require 'openssl'

module Tender
  class MultiPass
    class << self
      attr_accessor :site_key
      attr_accessor :support_domain
      attr_accessor :cookie_domain
    end

    attr_reader :user

    def initialize(user)
      @user = user
    end

    # Sets tender cookie values on the given cookie jar.
    def create(cookies, options = {}, name_field = nil)
      return nil if self.class.site_key.nil?
      expires = (options.delete(:expires) || 1.week.from_now).to_i # we want unix time
      cookies[:tender_email]   = cookie_value(@user.email)
      cookies[:tender_expires] = cookie_value(expires)

      options.each do |key, value|
        cookies[:"tender_#{key}"] = cookie_value(value)
      end

      if name_field
        name_field = cookies[:tender_name]  = cookie_value(@user.send(name_field))
      end

      cookies[:tender_hash]    = cookie_value(expiring_token(expires, name_field))
      cookies
    end

    def expiring_token(expires, name_field=nil)
      generate_hmac([self.class.support_domain, @user.email, expires, name_field].compact.join("/"))
    end

    def expire(cookies)
      [:tender_email, :tender_expires, :tender_hash].each do |key|<commit_msg>Delete tender name as well.<commit_after>require 'openssl'

module Tender
  class MultiPass
    class << self
      attr_accessor :site_key
      attr_accessor :support_domain
      attr_accessor :cookie_domain
    end

    attr_reader :user

    def initialize(user)
      @user = user
    end

    # Sets tender cookie values on the given cookie jar.
    def create(cookies, options = {}, name_field = nil)
      return nil if self.class.site_key.nil?
      expires = (options.delete(:expires) || 1.week.from_now).to_i # we want unix time
      cookies[:tender_email]   = cookie_value(@user.email)
      cookies[:tender_expires] = cookie_value(expires)

      options.each do |key, value|
        cookies[:"tender_#{key}"] = cookie_value(value)
      end

      if name_field
        name_field = cookies[:tender_name]  = cookie_value(@user.send(name_field))
      end

      cookies[:tender_hash]    = cookie_value(expiring_token(expires, name_field))
      cookies
    end

    def expiring_token(expires, name_field=nil)
      generate_hmac([self.class.support_domain, @user.email, expires, name_field].compact.join("/"))
    end

    def expire(cookies)
      [:tender_email, :tender_expires, :tender_hash, :tender_name].each do |key|
{'fraction_non_alphanumeric': 0.10318107667210441, 'fraction_numerical': 0.0008156606851549756, 'mean_word_length': 3.1931623931623934, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1171746', 'n_tokens_mistral': 805, 'n_tokens_neox': 787, 'n_words': 172}