aboutsummaryrefslogtreecommitdiff
path: root/bin/cisa-sizes.rb
diff options
context:
space:
mode:
Diffstat (limited to 'bin/cisa-sizes.rb')
-rwxr-xr-xbin/cisa-sizes.rb12
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)