use ExtUtils::testlib;
use Catacomb;

package Report;

sub new { bless [], $_[0]; }
sub report { my ($me, @info) = @_; push(@$me, \@info); }
sub done {
  my ($me) = @_;
  if (@$me) {
    print STDERR "Errors reading key file:\n";
    foreach my $i (@$me) {
      printf STDERR "  %s:%d: %s\n", @$i;
    }
    exit(1);
  }
}

package main;

my $fn = shift || "keyring";
my $rep = Report->new();
$kf = Catacomb::Key::File->new($fn, KFILE_READ, $rep)
  or die("error opening keyring: $!");
$rep->done();
$hcn = shift || "rmd160";
$hc = Catacomb::HashClass->find($hcn) or die("no hash algorithm `$hcn'");
$filt = Catacomb::Key::Filter->new("-secret");
for (my $i = $kf->iterate(); my $k = $i->next(); ) {
  $h = $hc->init();
  $fp = $k->fingerprint($h, $filt);
  print unpack("H*", $h->done()), " ", $k->fulltag(), "\n";
}
