Class: SelfSDK::Operation
- Inherits:
-
Object
- Object
- SelfSDK::Operation
- Defined in:
- lib/signature_graph.rb
Instance Attribute Summary collapse
-
#actions ⇒ Object
readonly
Returns the value of attribute actions.
-
#jws ⇒ Object
readonly
Returns the value of attribute jws.
-
#previous ⇒ Object
readonly
Returns the value of attribute previous.
-
#sequence ⇒ Object
readonly
Returns the value of attribute sequence.
-
#signing_key ⇒ Object
readonly
Returns the value of attribute signing_key.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
-
#initialize(operation) ⇒ Operation
constructor
A new instance of Operation.
- #revokes(kid) ⇒ Object
- #validate! ⇒ Object
Constructor Details
permalink #initialize(operation) ⇒ Operation
Returns a new instance of Operation.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/signature_graph.rb', line 17 def initialize(operation) @jws = operation payload = Base64.urlsafe_decode64(@jws[:payload]) header = Base64.urlsafe_decode64(@jws[:protected]) op = JSON.parse(payload, symbolize_names: true) hdr = JSON.parse(header, symbolize_names: true) @sequence = op[:sequence] @previous = op[:previous] @timestamp = op[:timestamp] @version = op[:version] @actions = op[:actions] @signing_key = hdr[:kid] validate! end |
Instance Attribute Details
permalink #actions ⇒ Object (readonly)
Returns the value of attribute actions.
15 16 17 |
# File 'lib/signature_graph.rb', line 15 def actions @actions end |
permalink #jws ⇒ Object (readonly)
Returns the value of attribute jws.
15 16 17 |
# File 'lib/signature_graph.rb', line 15 def jws @jws end |
permalink #previous ⇒ Object (readonly)
Returns the value of attribute previous.
15 16 17 |
# File 'lib/signature_graph.rb', line 15 def previous @previous end |
permalink #sequence ⇒ Object (readonly)
Returns the value of attribute sequence.
15 16 17 |
# File 'lib/signature_graph.rb', line 15 def sequence @sequence end |
permalink #signing_key ⇒ Object (readonly)
Returns the value of attribute signing_key.
15 16 17 |
# File 'lib/signature_graph.rb', line 15 def signing_key @signing_key end |
permalink #timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
15 16 17 |
# File 'lib/signature_graph.rb', line 15 def @timestamp end |
Instance Method Details
permalink #revokes(kid) ⇒ Object
[View source]
46 47 48 49 50 51 52 53 |
# File 'lib/signature_graph.rb', line 46 def revokes(kid) @actions.each do |action| if action[:kid] == kid && action[:action] == ACTION_REVOKE return true end end return false end |
permalink #validate! ⇒ Object
[View source]
36 37 38 39 40 41 42 43 44 |
# File 'lib/signature_graph.rb', line 36 def validate! raise "unknown operation version" if @version != "1.0.0" raise "invalid operation sequence" if @sequence < 0 raise "operation does not specify a previous signature" if @previous.nil? raise "invalid operation timestamp" if @timestamp < 1 raise "operation does not specify any actions" if @actions.nil? raise "operation does not specify any actions" if @actions.length < 1 raise "operation does not specify an identifier for the signing key" if @signing_key.nil? end |