Class: Macaroons::Verifier
- Inherits:
-
Object
- Object
- Macaroons::Verifier
- Defined in:
- lib/macaroons/verifier.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#callbacks ⇒ Object
Returns the value of attribute callbacks.
-
#predicates ⇒ Object
Returns the value of attribute predicates.
Instance Method Summary collapse
-
#initialize ⇒ Verifier
constructor
A new instance of Verifier.
- #satisfy_exact(predicate) ⇒ Object
- #satisfy_general(callback = nil, &block) ⇒ Object
- #verify(macaroon: nil, key: nil, discharge_macaroons: nil) ⇒ Object
- #verify_discharge(root: nil, macaroon: nil, key: nil, discharge_macaroons: []) ⇒ Object
Constructor Details
#initialize ⇒ Verifier
Returns a new instance of Verifier.
10 11 12 13 14 |
# File 'lib/macaroons/verifier.rb', line 10 def initialize @predicates = [] @callbacks = [] @calculated_signature = nil end |
Instance Attribute Details
#callbacks ⇒ Object
Returns the value of attribute callbacks.
8 9 10 |
# File 'lib/macaroons/verifier.rb', line 8 def callbacks @callbacks end |
#predicates ⇒ Object
Returns the value of attribute predicates.
7 8 9 |
# File 'lib/macaroons/verifier.rb', line 7 def predicates @predicates end |
Instance Method Details
#satisfy_exact(predicate) ⇒ Object
16 17 18 19 |
# File 'lib/macaroons/verifier.rb', line 16 def satisfy_exact(predicate) raise ArgumentError, 'Must provide predicate' unless predicate @predicates << predicate end |
#satisfy_general(callback = nil, &block) ⇒ Object
21 22 23 24 25 |
# File 'lib/macaroons/verifier.rb', line 21 def satisfy_general(callback = nil, &block) raise ArgumentError, 'Must provide callback or block' unless callback || block_given? callback = block if block_given? @callbacks << callback end |
#verify(macaroon: nil, key: nil, discharge_macaroons: nil) ⇒ Object
27 28 29 30 31 |
# File 'lib/macaroons/verifier.rb', line 27 def verify(macaroon: nil, key: nil, discharge_macaroons: nil) raise ArgumentError, 'Macaroon and Key required' if macaroon.nil? || key.nil? key = Utils.generate_derived_key(key) verify_discharge(root: macaroon, macaroon: macaroon, key: key, discharge_macaroons:discharge_macaroons) end |
#verify_discharge(root: nil, macaroon: nil, key: nil, discharge_macaroons: []) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/macaroons/verifier.rb', line 33 def verify_discharge(root: nil, macaroon: nil, key: nil, discharge_macaroons: []) @calculated_signature = Utils.hmac(key, macaroon.identifier) verify_caveats(macaroon, discharge_macaroons) if root != macaroon raw = root.instance_variable_get(:@raw_macaroon) @calculated_signature = raw.bind_signature(Utils.hexlify(@calculated_signature).downcase) end raise SignatureMismatchError, 'Signatures do not match.' unless signatures_match(Utils.unhexlify(macaroon.signature), @calculated_signature) return true end |