Class: CVESchema::CVE::Impact

Inherits:
Object
  • Object
show all
Defined in:
lib/cve_schema/cve/impact.rb,
lib/cve_schema/cve/impact/cvss_v2.rb,
lib/cve_schema/cve/impact/cvss_v3.rb

Defined Under Namespace

Classes: CVSSv2, CVSSv3

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cvssv2: nil, cvssv3: nil) ⇒ Impact

Initializes the impact object.

Parameters:

  • cvssv2 (CVSSv2, nil) (defaults to: nil)

    The CVSSv2 object.

  • cvssv3 (CVSSv3, nil) (defaults to: nil)

    The CVSSv3 object.



27
28
29
30
# File 'lib/cve_schema/cve/impact.rb', line 27

def initialize(cvssv2: nil, cvssv3: nil)
  @cvssv2 = cvssv2
  @cvssv3 = cvssv3
end

Instance Attribute Details

#cvssv2CVSSv2? (readonly) Also known as: cvss_v2

Returns:



9
10
11
# File 'lib/cve_schema/cve/impact.rb', line 9

def cvssv2
  @cvssv2
end

#cvssv3CVSSv3? (readonly) Also known as: cvss_v3

Returns:



14
15
16
# File 'lib/cve_schema/cve/impact.rb', line 14

def cvssv3
  @cvssv3
end

Class Method Details

.from_json(json) ⇒ Hash{Symbol => Object}

Maps the parsed JSON to a Symbol Hash for #initialize.

Parameters:

  • json (Hash{String => Object})

    The parsed JSON.

Returns:

  • (Hash{Symbol => Object})

    The mapped Symbol Hash.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/cve_schema/cve/impact.rb', line 43

def self.from_json(json)
  # HACK: the "impact" value is often an Array containing a single Hash
  hash = case json
         when Hash  then json
         when Array then json[0]
         else
           raise(InvalidJSON,'"impact" is neither a Hash or Array')
         end

  {
    cvssv2: hash['cvssv2'] && CVSSv2.load(hash['cvssv2']),
    cvssv3: hash['cvssv3'] && CVSSv3.load(hash['cvssv3'])
  }
end

.load(json) ⇒ Impact

Loads the impact object from the parsed JSON.

Parameters:

  • json (Hash{String => Object})

    The parsed JSON.

Returns:

  • (Impact)

    The loaded impact object.



69
70
71
# File 'lib/cve_schema/cve/impact.rb', line 69

def self.load(json)
  new(**from_json(json))
end