class CVESchema::CVE

Represents a `“cve”` JSON object.

Constants

DATA_FORMAT
DATA_TYPES
DATA_VERSIONS
NA

The `n/a` constant.

Attributes

affects[R]

@return [Affects, nil]

configuration[R]

@return [Array<Configuration>]

configurations[R]

@return [Array<Configuration>]

credit[R]

@return [Array<Credit>]

credits[R]

@return [Array<Credit>]

data_format[R]

@return [:MITRE]

data_meta[R]

@return [DataMeta]

data_type[R]

@return [:CVE, :CNA, :CVEMENTOR]

data_version[R]

@return [:“4.0”]

description[R]

@return [Array<Description>]

descriptions[R]

@return [Array<Description>]

exploit[R]

@return [Array<Exploit>]

exploits[R]

@return [Array<Exploit>]

impact[R]

@return [Impact, nil]

metadata[R]

@return [DataMeta]

problem_type[R]

@return [ProblemType]

problem_types[R]

@return [ProblemType]

problemtype[R]

@return [ProblemType]

references[R]

@return [Array<Reference>]

solution[R]

@return [Array<Solution>]

solutions[R]

@return [Array<Solution>]

source[R]

@return [Source, nil]

timeline[R]

@return [Array<Timeline>]

work_around[R]

@return [Array<WorkAround>]

work_arounds[R]

@return [Array<WorkAround>]

Public Class Methods

from_json(json) click to toggle source

Maps the JSON Hash into a Symbols Hash for {#initialize}.

@param [Hash{String => Object}] json

The parsed JSON.

@return [Hash{Symbol => Object}]

The maped Symbol Hash.

@raise [MissingJSONKey]

The `"data_type"`, `"data_format"`, `"data_version"`, or
`"CVE_data_key"` JSON keys were missing.

@api semipublic

# File lib/cve_schema/cve.rb, line 188
def self.from_json(json)
  {
    data_type:    if (data_type = json['data_type'])
                    DATA_TYPES.fetch(data_type) do
                      raise UnknownJSONValue.new('data_type',data_type)
                    end
                  else
                    raise MissingJSONKey.new('data_type')
                  end,

    data_format:  if (data_format = json['data_format'])
                    DATA_FORMAT.fetch(data_format) do
                      raise UnknownJSONValue.new('data_format',data_format)
                    end
                  else
                    raise MissingJSONKey.new('data_format')
                  end,

    data_version: if (data_version = json['data_version'])
                    DATA_VERSIONS.fetch(data_version) do
                      raise UnknownJSONValue.new('data_version',data_version)
                    end
                  else
                    raise MissingJSONKey.new('data_version')
                  end,

    data_meta: if (cve_data_meta = json['CVE_data_meta'])
                 DataMeta.load(cve_data_meta)
               else
                 raise MissingJSONKey.new('CVE_data_meta')
               end,

    affects:   json['affects'] && Affects.load(json['affects']),
    configuration: Array(json['configuration']).map(&Configuration.method(:load)),
    problemtype: Array(json['problemtype'] && json['problemtype']['problemtype_data']).map(&ProblemType.method(:load)),

    references: Array(json['references'] && json['references']['reference_data']).map(&Reference.method(:load)),

    description: Array(json['description'] && json['description']['description_data']).map(&Description.method(:load)),

    exploit: Array(json['exploit']).map(&Exploit.method(:load)),
    credit: Array(json['credit']).map(&Credit.method(:load)),
    impact: json['impact'] && Impact.load(json['impact']),
    solution: Array(json['solution']).map(&Solution.method(:load)),
    source: json['source'] && Source.load(json['source']),
    work_around: Array(json['work_around']).map(&WorkAround.method(:load)),
    timeline: Array(json['timeline']).map(&Timeline.method(:load))
  }
end
load(json) click to toggle source

Loads the CVE data from parsed JSON.

@param [Hash{String => Object}] json

The parsed JSON.

@return [self]

@raise [MissingJSONKey]

The `"data_type"`, `"data_format"`, `"data_version"`, or
`"CVE_data_key"` JSON keys were missing.

@api public

# File lib/cve_schema/cve.rb, line 252
def self.load(json)
  new(**from_json(json))
end
new(data_type: , data_format: , data_version: , data_meta: , affects: nil, configuration: [], problemtype: [], references: [], description: [], exploit: [], credit: [], impact: nil, solution: [], source: nil, work_around: [], timeline: [] ) click to toggle source

Initializes the CVE.

@param [:CVE, :CNA, :CVEMENTOR] data_type

@param [:MITRE] data_format

@param [:“4.0”] data_version

@param [DataMeta] data_meta

@param [Affects, nil] affects

@param [Array<Configuration>] configuration

@param [ArrayProblemType>] problemtype

@param [Array<Reference>] references

@param [Array<Description>] description

@param [Array<Exploit>] exploit

@param [Array<Credit>] credit

@param [Array<Impact>] impact

@param [Array<Solution>] solution

@param [Source, nil] source

@param [Array<WorkAround>] work_around

@param [Array<Timeline>] timeline

@api semipublic

# File lib/cve_schema/cve.rb, line 140
def initialize(data_type: , data_format: , data_version: , data_meta: ,
               affects: nil,
               configuration: [],
               problemtype: [],
               references: [],
               description: [],
               exploit: [],
               credit: [],
               impact: nil,
               solution: [],
               source: nil,
               work_around: [],
               timeline: []
              )
  @data_type    = data_type
  @data_format  = data_format
  @data_version = data_version

  @data_meta = data_meta
  @affects   = affects
  @configuration = configuration
  @problemtype = problemtype
  @references = references
  @description = description
  @exploit = exploit
  @credit = credit
  @impact = impact
  @solution = solution
  @source = source
  @work_around = work_around
  @timeline = timeline
end