aboutsummaryrefslogtreecommitdiff
path: root/bin/cisa-sizes.rb
blob: 5670ac5e0b5f4bd3918d207f3bfe44fcb515f690 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env ruby

#
# cisa-sizes.rb: get min/max field lengths from cisa catalog.
#

require 'json'
require 'zlib'
require 'csv'

# path to vulnerabilities
PATH = File.join(__dir__, '../cisa/testdata/cisa-kevc-20220313.json.gz')

# read vulns
ROWS = JSON(Zlib::GzipReader.new(File.open(PATH)).read)['vulnerabilities']

# get limits
sizes = ROWS.each.with_object(Hash.new { |h, k| h[k] = {} }) do |row, r|
  row.each do |k, v|
    r[k][:min] = v.size if !r[k][:min] || v.size < r[k][:min]
    r[k][:max] = v.size if !r[k][:max] || v.size > r[k][:max]
  end
end

# print limits
CSV(STDOUT) do |csv|
  csv << %w{name min max}
  sizes.keys.sort.each do |k|
    csv << [k, sizes[k][:min], sizes[k][:max]]
  end
end