Class: HttpSignatures::KeyStore

Inherits:
Object
  • Object
show all
Defined in:
lib/http_signatures/key_store.rb

Instance Method Summary collapse

Constructor Details

#initialize(key_hash) ⇒ KeyStore

Returns a new instance of KeyStore.



4
5
6
7
# File 'lib/http_signatures/key_store.rb', line 4

def initialize(key_hash)
  @keys = {}
  key_hash.each { |id, secret| self[id] = secret }
end

Instance Method Details

#fetch(id) ⇒ Object



9
10
11
# File 'lib/http_signatures/key_store.rb', line 9

def fetch(id)
  @keys.fetch(id)
end

#only_keyObject



13
14
15
16
17
18
19
# File 'lib/http_signatures/key_store.rb', line 13

def only_key
  if @keys.one?
    @keys.values.first
  else
    raise KeyError, "Expected 1 key, found #{@keys.size}"
  end
end