Class: SelfSDK::Operation

Inherits:
Object
  • Object
show all
Defined in:
lib/signature_graph.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#actionsObject (readonly)

Returns the value of attribute actions.



17
18
19
# File 'lib/signature_graph.rb', line 17

def actions
  @actions
end

#jwsObject (readonly)

Returns the value of attribute jws.



17
18
19
# File 'lib/signature_graph.rb', line 17

def jws
  @jws
end

#previousObject (readonly)

Returns the value of attribute previous.



17
18
19
# File 'lib/signature_graph.rb', line 17

def previous
  @previous
end

#sequenceObject (readonly)

Returns the value of attribute sequence.



17
18
19
# File 'lib/signature_graph.rb', line 17

def sequence
  @sequence
end

#signing_keyObject (readonly)

Returns the value of attribute signing_key.



17
18
19
# File 'lib/signature_graph.rb', line 17

def signing_key
  @signing_key
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



17
18
19
# File 'lib/signature_graph.rb', line 17

def timestamp
  @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