#!/usr/bin/perl -Tw
# Written by Jonathan McDowell <noodles@earth.li>
# Dedicated to linguists called Simon everywhere.
#
# An attempt at parsing the output of gpg -v --with-colons --list-keys
# Not completed yet. Will replace gpgpre and allow info on keysize/type.

use strict;

my ($curline, $rsa, $dsa, $elg, $elgeo);

$rsa=$dsa=$elg=$elgeo=0;

while ($curline = <>) {
	chomp $curline;

	if ($curline =~ /^pub:.*:\d*:(\d*):([0-9a-fA-F]*):.*:.*:.*:.*:(.*):/) {
		if ($1 == 1) {
			$rsa++;
		} elsif ($1 == 16) {
			$elgeo++;
		} elsif ($1 == 17) {
			$dsa++;
		} elsif ($1 == 20) {
			$elg++;
		}
#		print "P$2\n";
#		print "N$3\n";
	} elsif ($curline =~ /^sig:.*:\d*:(\d*):([0-9a-fA-F]*):.*:.*:.*:.*:.*/) {
#		print "S$2\n";
	} elsif ($curline =~ /^uid:/) {
		# Extra uid. Ignore.
	} elsif ($curline =~ /^sub:/) {
		# Subkey. Ignore.
	} elsif ($curline =~ /^rev:/) {
		# Unsure. Ignore.
	} else {
		print "$curline\n";
	}
}

print "RSA keys: $rsa, DSA keys: $dsa, ELG encrypt-only: $elgeo, ELG: $elg\n";
