Class: HealthCards::Verifier

Inherits:
Object
  • Object
show all
Extended by:
Verification
Includes:
Verification
Defined in:
lib/health_cards/verifier.rb

Overview

Verifiers can validate HealthCards using public keys

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Verification

resolve_key, verify_using_key_set

Constructor Details

#initialize(keys: nil, resolve_keys: true) ⇒ Verifier

Create a new Verifier

Parameters:

  • keys (HealthCards::KeySet, HealthCards::Key, nil) (defaults to: nil)

    keys to use when verifying Health Cards

  • resolve_keys (Boolean) (defaults to: true)

    Enables or disables key resolution



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/health_cards/verifier.rb', line 29

def initialize(keys: nil, resolve_keys: true)
  @keys = case keys
          when KeySet
            keys
          when Key
            KeySet.new(keys)
          else
            KeySet.new
          end

  self.resolve_keys = resolve_keys
end

Instance Attribute Details

#keysObject (readonly)

Returns the value of attribute keys.



9
10
11
# File 'lib/health_cards/verifier.rb', line 9

def keys
  @keys
end

#resolve_keysObject

Returns the value of attribute resolve_keys.



10
11
12
# File 'lib/health_cards/verifier.rb', line 10

def resolve_keys
  @resolve_keys
end

Class Method Details

.verify(verifiable) ⇒ Boolean

Verify a Payload

This method always uses key resolution and does not depend on any cached keys

Parameters:

Returns:

  • (Boolean)


21
22
23
# File 'lib/health_cards/verifier.rb', line 21

def self.verify(verifiable)
  verify_using_key_set(verifiable)
end

Instance Method Details

#add_keys(key) ⇒ Object

Add a key to use when verifying

Parameters:



45
46
47
# File 'lib/health_cards/verifier.rb', line 45

def add_keys(key)
  @keys.add_keys(key)
end

#remove_keys(key) ⇒ Object

Remove a key to use when verifying

Parameters:



52
53
54
# File 'lib/health_cards/verifier.rb', line 52

def remove_keys(key)
  @keys.remove_keys(key)
end

#resolve_keys?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/health_cards/verifier.rb', line 64

def resolve_keys?
  resolve_keys
end

#verify(verifiable) ⇒ Boolean

Verify a Payload

Parameters:

Returns:

  • (Boolean)


60
61
62
# File 'lib/health_cards/verifier.rb', line 60

def verify(verifiable)
  verify_using_key_set(verifiable, keys, resolve_keys: resolve_keys?)
end