class Rack::U2f::RegistrationStore::RedisStore

Public Class Methods

new(redis_connection = nil) click to toggle source
# File lib/rack/u2f/registration_store/redis_store.rb, line 7
def initialize(redis_connection = nil)
  @redis = redis_connection || Redis.new
  @hash_key_prefix = 'rack-u2f'
end

Public Instance Methods

get_registration(key_handle:) click to toggle source
# File lib/rack/u2f/registration_store/redis_store.rb, line 24
def get_registration(key_handle:)
  data = @redis.hget(@hash_key_prefix, key_handle)
  data && JSON.parse(data)
end
key_handles() click to toggle source
# File lib/rack/u2f/registration_store/redis_store.rb, line 44
def key_handles
  @redis.hkeys(@hash_key_prefix) || []
end
store_registration(certificate:, key_handle:, public_key:, counter:) click to toggle source
# File lib/rack/u2f/registration_store/redis_store.rb, line 12
def store_registration(certificate:, key_handle:, public_key:, counter:)
  @redis.hset(
    @hash_key_prefix,
    key_handle,
    JSON.dump(
      certificate: certificate,
      public_key: public_key,
      counter: counter
    )
  )
end
update_registration(key_handle:, counter:) click to toggle source
# File lib/rack/u2f/registration_store/redis_store.rb, line 29
def update_registration(key_handle:, counter:)
  existing = get_registration(key_handle: key_handle)
  if existing
    @redis.hset(
      @hash_key_prefix,
      key_handle,
      JSON.dump(
        certificate: existing['certificate'],
        public_key: existing['public_key'],
        counter: counter
      )
    )
  end
end