Class: Dcc::Signature::Result
- Inherits:
-
Object
- Object
- Dcc::Signature::Result
- 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
-
#certificate_pem ⇒ Object
readonly
Returns the value of attribute certificate_pem.
-
#signed_xml ⇒ Object
readonly
Returns the value of attribute signed_xml.
-
#valid ⇒ Object
readonly
Returns the value of attribute valid.
Instance Method Summary collapse
-
#initialize(valid:, certificate_pem: nil, signed_xml: nil) ⇒ Result
constructor
A new instance of Result.
- #to_json(*_args) ⇒ Object
- #to_s ⇒ Object
- #to_yaml(*_args) ⇒ Object
- #valid? ⇒ Boolean
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_pem ⇒ Object (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_xml ⇒ Object (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 |
#valid ⇒ Object (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_s ⇒ Object
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
16 17 18 |
# File 'lib/dcc/signature/result.rb', line 16 def valid? !!@valid end |