Sha256: 4fbdf7876a31024c6444d80868bc1642ad936185a53565ddc0af89de3ac0d5d7

Contents?: true

Size: 716 Bytes

Versions: 22

Compression:

Stored size: 716 Bytes

Contents

# frozen_string_literal: true

require 'openssl'

module Devise
  class TokenGenerator
    def initialize(key_generator, digest = "SHA256")
      @key_generator = key_generator
      @digest = digest
    end

    def digest(klass, column, value)
      value.present? && OpenSSL::HMAC.hexdigest(@digest, key_for(column), value.to_s)
    end

    def generate(klass, column)
      key = key_for(column)

      loop do
        raw = Devise.friendly_token
        enc = OpenSSL::HMAC.hexdigest(@digest, key, raw)
        break [raw, enc] unless klass.to_adapter.find_first({ column => enc })
      end
    end

    private

    def key_for(column)
      @key_generator.generate_key("Devise #{column}")
    end
  end
end

Version data entries

22 entries across 22 versions & 3 rubygems

Version Path
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/devise-4.9.4/lib/devise/token_generator.rb
devise-4.9.4 lib/devise/token_generator.rb
devise-4.9.3 lib/devise/token_generator.rb
devise-4.9.2 lib/devise/token_generator.rb
devise-4.9.1 lib/devise/token_generator.rb
devise-4.9.0 lib/devise/token_generator.rb
devise-4.8.1 lib/devise/token_generator.rb
date_n_time_picker_activeadmin-0.1.2 vendor/bundle/ruby/2.6.0/gems/devise-4.8.0/lib/devise/token_generator.rb
date_n_time_picker_activeadmin-0.1.1 vendor/bundle/ruby/2.6.0/gems/devise-4.8.0/lib/devise/token_generator.rb
devise-4.8.0 lib/devise/token_generator.rb
devise-4.7.3 lib/devise/token_generator.rb
devise-4.7.2 lib/devise/token_generator.rb
devise-4.7.1 lib/devise/token_generator.rb
devise-4.7.0 lib/devise/token_generator.rb
devise-4.6.2 lib/devise/token_generator.rb
devise-4.6.1 lib/devise/token_generator.rb
devise-4.6.0 lib/devise/token_generator.rb
devise-4.5.0 lib/devise/token_generator.rb
devise-4.4.3 lib/devise/token_generator.rb
devise-4.4.2 lib/devise/token_generator.rb