AnyEvent-GnuPG
view release on metacpan or search on metacpan
lib/AnyEvent/GnuPG.pm view on Meta::CPAN
sub _eq($_) { shift eq pop } ## no critic
sub _parse_status {
my ( $self, $cv, %actions ) = @_;
my $commands;
$self->{status_fd}->readlines_cb(
sub {
my $line = shift;
unless ( defined $line ) {
AE::log debug => "end of status parsing";
$cv->send($commands);
}
if ( my ( $cmd, $arg ) =
$line =~ m{^\[gnupg:\]\s+(\w+)\s*(.+)?\s*$}i )
{
$arg ||= '';
my @args = $arg ? ( split /\s+/, $arg ) : ();
AE::log debug => "got command: $cmd ($arg)";
try {
for ( lc $cmd ) {
_eq('newsig') && do { last };
_eq('goodsig') && do { last };
_eq('expsig')
&& do { die "the signature is expired ($arg)" };
_eq('expkeysig') && do {
die
"the signature was made by an expired key ($arg)";
};
lib/AnyEvent/GnuPG.pm view on Meta::CPAN
arg => $arg,
args => \@args,
result => $result
};
}
catch {
s{\s+$}{};
$self->_abort_gnupg( $_, $cv );
}
finally {
AE::log debug => "arguments parsed as: ["
. ( join ', ', map { "'$_'" } @args ) . "]";
}
}
else {
return $self->_abort_gnupg(
"error communicating with gnupg: bad status line: $line",
$cv );
}
}
);
lib/AnyEvent/GnuPG.pm view on Meta::CPAN
}
sub _abort_gnupg {
my ( $self, $msg, $cb ) = @_;
my $cv = _condvar($cb);
AE::log error => $msg if $msg;
if ( $self->{gnupg_proc} ) {
$self->{gnupg_proc}->fire_and_kill(
10,
sub {
AE::log debug => "fired and killed";
$self->_end_gnupg(
sub {
AE::log debug => "gnupg aborted";
$cv->croak($msg);
}
);
}
);
}
$cv;
}
sub _end_gnupg {
lib/AnyEvent/GnuPG.pm view on Meta::CPAN
close $self->{output};
}
for (
qw(protocol proc command options args status_fd command_fd input output next_status )
)
{
delete $self->{$_};
}
AE::log debug => "gnupg exited";
$cv->send;
}
);
}
else {
$cv->send;
}
$cv;
}
lib/AnyEvent/GnuPG.pm view on Meta::CPAN
my $gpg = shift @$cmdline;
my $status = AnyEvent::Proc::reader();
my $command = AnyEvent::Proc::writer();
unshift @$cmdline, '--status-fd' => $status;
unshift @$cmdline, '--command-fd' => $command;
my $err;
AE::log debug => "running $gpg " . join( ' ' => @$cmdline );
my $proc = AnyEvent::Proc->new(
bin => $gpg,
args => $cmdline,
extras => [ $status, $command ],
ttl => 600,
on_ttl_exceed => sub { $self->_abort_gnupg( 'ttl exceeded', $cv ) },
errstr => \$err,
);
if ( defined $self->{input} ) {
lib/AnyEvent/GnuPG.pm view on Meta::CPAN
}
if ( defined $self->{output} ) {
$proc->pipe( out => $self->{output} );
}
$self->{command_fd} = $command;
$self->{status_fd} = $status;
$self->{gnupg_proc} = $proc;
AE::log debug => "gnupg ready";
$proc;
}
sub _send_command {
shift->{command_fd}->writeln(pop);
}
sub DESTROY {
my $self = shift;
( run in 0.306 second using v1.01-cache-2.11-cpan-3cd7ad12f66 )