Class: Rack::U2f::RegistrationStore::RedisStore

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/u2f/registration_store/redis_store.rb

Instance Method Summary collapse

Constructor Details

#initialize(redis_connection = nil) ⇒ RedisStore

Returns a new instance of RedisStore.



7
8
9
10
# 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

Instance Method Details

#get_registration(key_handle:) ⇒ Object



24
25
26
27
# 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_handlesObject



44
45
46
# 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:) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# 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:) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# 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