Class: Dcc::Signature::Result

Inherits:
Object
  • Object
show all
Defined in:
lib/dcc/signature/result.rb

Overview

Outcome of a signature verification. Carries the verified certificate, validity flag, and the signed XML subtree (the only trustable part).

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(valid:, certificate_pem: nil, signed_xml: nil) ⇒ Result

Returns a new instance of Result.



10
11
12
13
14
# File 'lib/dcc/signature/result.rb', line 10

def initialize(valid:, certificate_pem: nil, signed_xml: nil)
  @valid = valid
  @certificate_pem = certificate_pem
  @signed_xml = signed_xml
end

Instance Attribute Details

#certificate_pemObject (readonly)

Returns the value of attribute certificate_pem.



8
9
10
# File 'lib/dcc/signature/result.rb', line 8

def certificate_pem
  @certificate_pem
end

#signed_xmlObject (readonly)

Returns the value of attribute signed_xml.



8
9
10
# File 'lib/dcc/signature/result.rb', line 8

def signed_xml
  @signed_xml
end

#validObject (readonly)

Returns the value of attribute valid.



8
9
10
# File 'lib/dcc/signature/result.rb', line 8

def valid
  @valid
end

Instance Method Details

#to_json(*_args) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/dcc/signature/result.rb', line 28

def to_json(*_args)
  require "json"
  ::JSON.pretty_generate(
    valid: valid?,
    certificate_pem: certificate_pem,
    signed_xml_length: signed_xml&.length,
  )
end

#to_sObject



20
21
22
23
24
25
26
# File 'lib/dcc/signature/result.rb', line 20

def to_s
  if valid?
    "Signature valid#{certificate_pem ? " (cert: #{certificate_pem.lines.first&.strip})" : ''}"
  else
    "Signature INVALID"
  end
end

#to_yaml(*_args) ⇒ Object



37
38
39
40
# File 'lib/dcc/signature/result.rb', line 37

def to_yaml(*_args)
  require "yaml"
  { valid: valid?, certificate_pem: certificate_pem }.to_yaml
end

#valid?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/dcc/signature/result.rb', line 16

def valid?
  !!@valid
end