| 1 | package CSAF::Schema; | ||
| 2 | |||
| 3 | use 5.010001; | ||
| 4 | use strict; | ||
| 5 | use warnings; | ||
| 6 | use utf8; | ||
| 7 | |||
| 8 | use CSAF::Util qw(schema_cache_path); | ||
| 9 | use JSON::Validator; | ||
| 10 | |||
| 11 | |||
| 12 | our %SCHEMAS = ( | ||
| 13 | 'csaf-2.0' => 'https://docs.oasis-open.org/csaf/csaf/v2.0/os/schemas/csaf_json_schema.json', | ||
| 14 | 'strict-csaf-2.0' => 'https://docs.oasis-open.org/csaf/csaf/v2.0/os/schemas/csaf_json_schema.json?strict', | ||
| 15 | 'csaf-2.0-provider' => 'https://docs.oasis-open.org/csaf/csaf/v2.0/os/schemas/provider_json_schema.json', | ||
| 16 | 'csaf-2.0-aggregator' => 'https://docs.oasis-open.org/csaf/csaf/v2.0/os/schemas/aggregator_json_schema.json', | ||
| 17 | |||
| 18 | 'cvss-v3.1' => 'https://www.first.org/cvss/cvss-v3.1.json', | ||
| 19 | 'cvss-v3.0' => 'https://www.first.org/cvss/cvss-v3.0.json', | ||
| 20 | 'cvss-v2.0' => 'https://www.first.org/cvss/cvss-v2.0.json', | ||
| 21 | |||
| 22 | 'cvss-v3.x' => { | ||
| 23 | oneOf => [ | ||
| 24 | {'$ref' => 'https://www.first.org/cvss/cvss-v3.0.json'}, | ||
| 25 | {'$ref' => 'https://www.first.org/cvss/cvss-v3.1.json'} | ||
| 26 | ] | ||
| 27 | } | ||
| 28 | ); | ||
| 29 | |||
| 30 | sub validator { | ||
| 31 | |||
| 32 | my ($class, $schema) = @_; | ||
| 33 | |||
| 34 | my $jv = JSON::Validator->new; | ||
| 35 | |||
| 36 | $jv->cache_paths([schema_cache_path]); | ||
| 37 | $jv->schema($SCHEMAS{$schema} || $schema); | ||
| 38 | |||
| 39 | return $jv; | ||
| 40 | |||
| 41 | } | ||
| 42 | |||
| 43 | 1; | ||
| 44 | |||
| 45 | __END__ |