Class: Ibex::VerificationReport::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/verification_report/validator.rb

Overview

Validates a report and its cross-artifact manifest/table bindings. rubocop:disable Metrics/ClassLength -- closed report and cross-artifact invariants form one validator contract.

Constant Summary collapse

ROOT_KEYS =

@rbs! type json_value = String | Integer | Float | bool | nil | Array | Hash[String, json_value]

%w[
  ibex_report schema_version checker profile bounds input ir table outcome excluded_trust evidence_digest
].freeze
CHECKER_KEYS =

: Array

%w[name version].freeze
BOUNDS_KEYS =

: Array

%w[max_states max_items].freeze
INPUT_KEYS =

: Array

%w[digest files].freeze
INPUT_FILE_KEYS =

: Array

%w[logical_path sha256 bytesize].freeze
IR_KEYS =

: Array

%w[identity_scope grammar automaton].freeze
GRAMMAR_KEYS =

: Array

%w[schema_version digest].freeze
AUTOMATON_KEYS =

: Array

%w[schema_version algorithm digest].freeze
TABLE_KEYS =

: Array

%w[
  logical_path artifact_type schema_version representation artifact_digest payload_digest
].freeze
OUTCOME_KEYS =

: Array

%w[status requested_checks executed_checks violations exhaustion].freeze
VIOLATION_KEYS =

: Array

%w[id location message].freeze
EXHAUSTION_KEYS =

: Array

%w[kind message].freeze
DIGEST =

: Array

/\Asha256:[0-9a-f]{64}\z/
ALGORITHMS =

: Array

%w[slr lalr1 ielr1 lr1].freeze

Instance Method Summary collapse

Instance Method Details

#validate(source) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/ibex/verification_report/validator.rb', line 34

def validate(source)
  document = JSON.parse(source) #: json_value
  validate_document(document)
  document #: Hash[String, json_value]
rescue JSON::ParserError, KeyError, TypeError, ArgumentError => e
  raise ValidationError, "(verification-report):1:1: invalid report: #{e.message}"
end

#validate_bundle(manifest_source:, report_source:, table_source:) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/ibex/verification_report/validator.rb', line 43

def validate_bundle(manifest_source:, report_source:, table_source:)
  manifest = GenerationManifest.validate(manifest_source, verify_artifacts: false) #: Hash[String, json_value]
  report = validate(report_source)
  table = TableArtifact.load(table_source)
  report_entry = unique_artifact(manifest, "verification_report")
  table_entry = unique_artifact(manifest, "parser_table")
  unique_artifact(manifest, "parser")

  validate_manifest_bytes!(report_entry, report_source, "verification report")
  validate_manifest_bytes!(table_entry, table_source, "parser table")
  validate_inputs!(manifest, report)
  validate_table_binding!(report, table, table_entry)
  report
rescue Ibex::Error => e
  raise e if e.is_a?(ValidationError)

  raise ValidationError, "(verification-bundle):1:1: #{e.message}"
rescue KeyError, TypeError, ArgumentError => e
  raise ValidationError, "(verification-bundle):1:1: invalid bundle: #{e.message}"
end

#validate_bundle_file(manifest_path) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/ibex/verification_report/validator.rb', line 65

def validate_bundle_file(manifest_path)
  manifest_source = File.binread(manifest_path)
  manifest = GenerationManifest.validate(manifest_source, verify_artifacts: false) #: Hash[String, json_value]
  report_entry = unique_artifact(manifest, "verification_report")
  table_entry = unique_artifact(manifest, "parser_table")
  report_path = report_entry.fetch("path") #: String
  table_path = table_entry.fetch("path") #: String
  report_source = File.binread(report_path)
  table_source = File.binread(table_path)
  result = validate_bundle(
    manifest_source: manifest_source, report_source: report_source, table_source: table_source
  )
  GenerationManifest.validate(manifest_source)
  result
rescue SystemCallError => e
  raise ValidationError, "#{manifest_path}:1:1: cannot read verification bundle: #{e.message}"
end