diff options
author | Paul Duncan <pabs@pablotron.org> | 2022-03-16 07:40:38 -0400 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2022-03-16 07:40:38 -0400 |
commit | 86707e1eb95a0b2ba386c0b000274df23ba54970 (patch) | |
tree | 086e6dbc7607f77d391def8b912b921f88a96566 | |
parent | c00a99805c35817b63ec195a97e211464f8a1f04 (diff) | |
download | cvez-86707e1eb95a0b2ba386c0b000274df23ba54970.tar.bz2 cvez-86707e1eb95a0b2ba386c0b000274df23ba54970.zip |
bin/cisa-sizes.rb: get field min size
-rwxr-xr-x | bin/cisa-sizes.rb | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/bin/cisa-sizes.rb b/bin/cisa-sizes.rb index 88ec7d3..934ac23 100755 --- a/bin/cisa-sizes.rb +++ b/bin/cisa-sizes.rb @@ -1,8 +1,7 @@ #!/usr/bin/env ruby # -# cisa-sizes.rb: get maximum field lengths from compressed cisa -# kev catalog. +# cisa-sizes.rb: get min/max field lengths from cisa catalog. # require 'json' @@ -14,7 +13,10 @@ 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] } +# get/print json-encoded min/max field lengths +puts JSON(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) |