aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xbin/cisa-sizes.rb20
1 files changed, 20 insertions, 0 deletions
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)