From c00a99805c35817b63ec195a97e211464f8a1f04 Mon Sep 17 00:00:00 2001 From: Paul Duncan Date: Wed, 16 Mar 2022 07:33:33 -0400 Subject: bin/cisa-sizes.rb: add utility script --- bin/cisa-sizes.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100755 bin/cisa-sizes.rb (limited to 'bin') diff --git a/bin/cisa-sizes.rb b/bin/cisa-sizes.rb new file mode 100755 index 0000000..88ec7d3 --- /dev/null +++ b/bin/cisa-sizes.rb @@ -0,0 +1,20 @@ +#!/usr/bin/env ruby + +# +# cisa-sizes.rb: get maximum field lengths from compressed cisa +# kev catalog. +# + +require 'json' +require 'zlib' + +# 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/print json-encoded maximum field lengths +puts JSON(ROWS.each.with_object(Hash.new { |h, k| h[k] = 0 }) do |row, r| + row.each { |k, v| r[k] = v.size if v.size > r[k] } +end) -- cgit v1.2.3