#!/usr/local/bin/perl
$h1="+++++++++++++++++++++++BEGIN L3 SIGNED MESSAGE+++++++++++++++++++++++";
$h2="++++++++++++++++++++++++++BEGIN L3 SIGNATURE+++++++++++++++++++++++++";
$h4="+++++++++++++++++++++++++++END L3 SIGNATURE++++++++++++++++++++++++++";
print STDERR "$ARGV[0]", "\n";
$state = 0;
$bindir="/usr/local/bin/";
print $h1, "\n";
die "usage: tsign prvfile\n" if (!$ARGV[0]);
open(SPIPE, "| ".$bindir."sign $ARGV[0] | ${bindir}prencode -e >/tmp/.$$.sig");
while(<STDIN>) {
	chop;
#	trailing spaces
	s/[ \t]*$//;
	print SPIPE $_, "\n";
	print $_, "\n";
}
print $h2, "\n";
close(SPIPE);
open(SIGF,"/tmp/.$$.sig") || die "cannot open /tmp/.$$.sig";
print $ARGV[0], "\n";
while(<SIGF>) {
	print " ", $_;
}
close SIGF;
print $h4, "\n";
unlink("/tmp/.$$.sig");
