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
#initialize(operation) ⇒ Operation
Returns a new instance of Operation.
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/signature_graph.rb', line 19 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
#actions ⇒ Object (readonly)
Returns the value of attribute actions.
17 18 19 |
# File 'lib/signature_graph.rb', line 17 def actions @actions end |
#jws ⇒ Object (readonly)
Returns the value of attribute jws.
17 18 19 |
# File 'lib/signature_graph.rb', line 17 def jws @jws end |
#previous ⇒ Object (readonly)
Returns the value of attribute previous.
17 18 19 |
# File 'lib/signature_graph.rb', line 17 def previous @previous end |
#sequence ⇒ Object (readonly)
Returns the value of attribute sequence.
17 18 19 |
# File 'lib/signature_graph.rb', line 17 def sequence @sequence end |
#signing_key ⇒ Object (readonly)
Returns the value of attribute signing_key.
17 18 19 |
# File 'lib/signature_graph.rb', line 17 def signing_key @signing_key end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
17 18 19 |
# File 'lib/signature_graph.rb', line 17 def @timestamp end |
Instance Method Details
#revokes(kid) ⇒ Object
48 49 50 51 52 53 54 55 |
# File 'lib/signature_graph.rb', line 48 def revokes(kid) @actions.each do |action| if action[:kid] == kid && action[:action] == ACTION_REVOKE return true end end return false end |
#validate! ⇒ Object
38 39 40 41 42 43 44 45 46 |
# File 'lib/signature_graph.rb', line 38 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 |