AnyEvent-GnuPG
view release on metacpan or search on metacpan
lib/AnyEvent/GnuPG.pm view on Meta::CPAN
use strict;
use warnings;
package AnyEvent::GnuPG;
# ABSTRACT: AnyEvent-based interface to the GNU Privacy Guard
use Exporter 'import';
use AnyEvent;
use AnyEvent::Proc 0.104;
use Email::Address;
use Async::Chain;
use Try::Tiny;
use Carp qw(confess);
use constant RSA_RSA => 1;
use constant DSA_ELGAMAL => 2;
use constant DSA => 3;
use constant RSA => 4;
use constant TRUST_UNDEFINED => -1;
use constant TRUST_NEVER => 0;
use constant TRUST_MARGINAL => 1;
use constant TRUST_FULLY => 2;
use constant TRUST_ULTIMATE => 3;
our $VERSION = '1.001'; # VERSION
our @EXPORT = qw();
our %EXPORT_TAGS = (
algo => [qw[ RSA_RSA DSA_ELGAMAL DSA RSA ]],
trust => [
qw[ TRUST_UNDEFINED TRUST_NEVER TRUST_MARGINAL TRUST_FULLY TRUST_ULTIMATE ]
],
);
Exporter::export_ok_tags(qw( algo trust ));
sub _options {
my $self = shift;
$self->{cmd_options} = shift if ( $_[0] );
$self->{cmd_options};
}
sub _command {
my $self = shift;
$self->{command} = shift if ( $_[0] );
$self->{command};
}
sub _args {
my $self = shift;
$self->{args} = shift if ( $_[0] );
$self->{args};
}
sub _cmdline {
my $self = shift;
my $args = [ $self->{gnupg_path} ];
# Default options
push @$args, "--no-tty", "--no-greeting", "--yes";
# Check for homedir and options file
push @$args, "--homedir", $self->{homedir} if $self->{homedir};
push @$args, "--options", $self->{options} if $self->{options};
# Command options
push @$args, @{ $self->_options };
# Command and arguments
push @$args, "--" . $self->_command;
lib/AnyEvent/GnuPG.pm view on Meta::CPAN
=item * fingerprint
The fingerprint of the signature.
=item * trust
The trust value of the public key of the signer. Those are values that can be imported in your namespace with the :trust tag. They are (TRUST_UNDEFINED, TRUST_NEVER, TRUST_MARGINAL, TRUST_FULLY, TRUST_ULTIMATE).
=back
Example:
my $sig = $gpg->verify(
signature => "file.txt.asc",
file => "file.txt"
);
=head2 verify_cb(%params[, cb => $callback|$condvar])
Asynchronous variant of L</verify>.
=head2 decrypt(%params)
This method decrypts an encrypted message. It croaks, if there is an error while decrypting the message. If the message was signed, this method also verifies the signature. If decryption is sucessful, the method either returns the valid signature par...
=over 4
=item * ciphertext
This optional parameter contains either the name of the file containing the ciphertext or a reference to a file handle containing the ciphertext.
=item * output
This optional parameter determines where the plaintext will be stored. It can be either a file name or anything else that L<AnyEvent::Proc/pipe> accepts.
=item * symmetric
This should be set to true, if the message is encrypted using symmetric cryptography.
=item * passphrase
The passphrase that should be used to decrypt the message (in the case of a message encrypted using a symmetric cipher) or the secret that will unlock the private key that should be used to decrypt the message.
=back
Example:
$gpg->decrypt(
ciphertext => "file.gpg",
output => "file.txt",
passphrase => $secret
);
=head2 decrypt_cb(%params[, cb => $callback|$condvar])
Asynchronous variant of L</decrypt>.
=head1 API OVERVIEW
The API is accessed through methods on a AnyEvent::GnuPG object which is a wrapper around the B<gpg> program. All methods takes their argument using named parameters, and errors are returned by throwing an exception (using croak). If you wan't to cat...
This modules uses L<AnyEvent::Proc>. For input data, all of L<AnyEvent::Proc/pull> and for output data, all of L<AnyEvent::Proc/pipe> possible handle types are allowed.
The code is based on L<GnuPG> with API compatibility except that L<GnuPG::Tie> is B<not> ported.
=head2 CALLBACKS AND CONDITION VARIABLES
Every method has a callback variant, suffixed with I<_cb>. These methods accept an optional parameter called I<cb>, which can be a CodeRef or an L<AnyEvent>::CondVar and returns a condvar.
$gpg->method_cb(%params, cb => sub {
my $result = shift->recv; # croaks on error
...
});
my $cv = $gpg->method_cb(%params);
my $result = $cv->recv; # croaks on error
...
The non-callback variants are all wrapper methods, looking something like this:
sub method {
shift->method_cb(@_)->recv
}
=head1 EXPORTS
Nothing by default. Available tags:
=over 4
=item * :algo
RSA_RSA DSA_ELGAMAL DSA RSA
=item * :trust
TRUST_UNDEFINED TRUST_NEVER TRUST_MARGINAL TRUST_FULLY TRUST_ULTIMATE
=back
=head1 BUGS AND LIMITATIONS
This module doesn't work (yet) with the v2 branch of GnuPG.
=head1 SEE ALSO
=over 4
=item * L<GnuPG>
=item * L<gpg(1)>
=back
=head1 BUGS
Please report any bugs or feature requests on the bugtracker website
https://github.com/zurborg/libanyevent-gnupg-perl/issues
When submitting a bug or request, please include a test-file or a
( run in 0.595 second using v1.01-cache-2.11-cpan-600a1bdf6e4 )