Class: HealthCards::KeySet
- Inherits:
-
Object
- Object
- HealthCards::KeySet
- Extended by:
- Forwardable
- Defined in:
- lib/health_cards/key_set.rb
Overview
A set of keys used for signing or verifying HealthCards
Class Method Summary collapse
-
.from_jwks(jwks) ⇒ HealthCards::KeySet
Create a KeySet from a JWKS.
Instance Method Summary collapse
-
#add_keys(new_keys) ⇒ Object
Add keys to KeySet.
-
#find_key(kid) ⇒ Payload::Key
Retrieves a key from the keyset with a kid that matches the parameter.
-
#include?(key) ⇒ Boolean
Check if key is included in the KeySet.
-
#initialize(keys = nil) ⇒ KeySet
constructor
Create a new KeySet.
-
#keys ⇒ Array
The contained keys.
-
#remove_keys(removed_keys) ⇒ Object
Remove keys from KeySet.
-
#to_jwk ⇒ Object
Returns the keys as a JWK.
Constructor Details
#initialize(keys = nil) ⇒ KeySet
Create a new KeySet
25 26 27 28 |
# File 'lib/health_cards/key_set.rb', line 25 def initialize(keys = nil) @key_map = {} add_keys(keys) unless keys.nil? end |
Class Method Details
.from_jwks(jwks) ⇒ HealthCards::KeySet
Create a KeySet from a JWKS
16 17 18 19 20 |
# File 'lib/health_cards/key_set.rb', line 16 def self.from_jwks(jwks) jwks = JSON.parse(jwks) keys = jwks['keys'].map { |jwk| HealthCards::Key.from_jwk(jwk) } KeySet.new(keys) end |
Instance Method Details
#add_keys(new_keys) ⇒ Object
Add keys to KeySet
Keys are added based on the key kid
57 58 59 60 61 62 63 |
# File 'lib/health_cards/key_set.rb', line 57 def add_keys(new_keys) if new_keys.is_a? KeySet add_keys(new_keys.keys) else [*new_keys].each { |new_key| @key_map[new_key.kid] = new_key } end end |
#find_key(kid) ⇒ Payload::Key
Retrieves a key from the keyset with a kid that matches the parameter
48 49 50 |
# File 'lib/health_cards/key_set.rb', line 48 def find_key(kid) @key_map[kid] end |
#include?(key) ⇒ Boolean
Check if key is included in the KeySet
82 83 84 |
# File 'lib/health_cards/key_set.rb', line 82 def include?(key) !@key_map[key.kid].nil? end |
#keys ⇒ Array
The contained keys
33 34 35 |
# File 'lib/health_cards/key_set.rb', line 33 def keys @key_map.values end |
#remove_keys(removed_keys) ⇒ Object
Remove keys from KeySet
Keys are remove based on the key kid
70 71 72 73 74 75 76 |
# File 'lib/health_cards/key_set.rb', line 70 def remove_keys(removed_keys) if removed_keys.is_a? KeySet remove_keys(removed_keys.keys) else [*removed_keys].each { |removed_key| @key_map.delete(removed_key.kid) } end end |
#to_jwk ⇒ Object
Returns the keys as a JWK
40 41 42 |
# File 'lib/health_cards/key_set.rb', line 40 def to_jwk { keys: keys.map(&:to_jwk) }.to_json end |