summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Palfrader <peter@palfrader.org>2004-04-24 12:25:10 +0000
committerPeter Palfrader <peter@palfrader.org>2004-04-24 12:25:10 +0000
commit75da8751b1e5a5a39f8743b44971224b0ab34c31 (patch)
tree3e194bcac050e2876c1821fd40f00b91dff63a91
parent82c0bb931633d67a7e60bddb756264edcd4620b6 (diff)
Move duplicated IO::Handle preperations for GnuPG::Interface to Echolot::Tools::make_gpg_fds.
-rw-r--r--Echolot/Conf.pm15
-rw-r--r--Echolot/Pinger/CPunk.pm27
-rw-r--r--Echolot/Stats.pm26
-rw-r--r--Echolot/Tools.pm25
-rw-r--r--NEWS2
5 files changed, 18 insertions, 77 deletions
diff --git a/Echolot/Conf.pm b/Echolot/Conf.pm
index 53340eb..19ea43f 100644
--- a/Echolot/Conf.pm
+++ b/Echolot/Conf.pm
@@ -25,7 +25,6 @@ account (This is the one with the latest self signature I think).
use strict;
use Echolot::Log;
use GnuPG::Interface;
-use IO::Handle;
sub is_not_a_remailer($) {
@@ -361,19 +360,7 @@ sub parse_cpunk_key($$$) {
(?:[a-zA-Z0-9+\/=]*\r?\n)+
-----END \s PGP \s PUBLIC \s KEY \s BLOCK-----$/xmg );
for my $key (@pgp_keys) {
- my ( $stdin_fh, $stdout_fh, $stderr_fh, $status_fh )
- = ( IO::Handle->new(),
- IO::Handle->new(),
- IO::Handle->new(),
- IO::Handle->new(),
- );
- my $handles = GnuPG::Handles->new (
- stdin => $stdin_fh,
- stdout => $stdout_fh,
- stderr => $stderr_fh,
- status => $status_fh
- );
-
+ my ( $stdin_fh, $stdout_fh, $stderr_fh, $status_fh, $handles ) = Echolot::Tools::make_gpg_fds();
my $pid = $GnuPG->wrap_call(
commands => [qw{--with-colons}],
command_args => [qw{--no-options --no-secmem-warning --no-default-keyring --fast-list-mode}],
diff --git a/Echolot/Pinger/CPunk.pm b/Echolot/Pinger/CPunk.pm
index 08bed0c..1aa8f07 100644
--- a/Echolot/Pinger/CPunk.pm
+++ b/Echolot/Pinger/CPunk.pm
@@ -19,7 +19,6 @@ This package provides functions for sending cypherpunk (type I) pings.
use strict;
use English;
use GnuPG::Interface;
-use IO::Handle;
use Echolot::Log;
sub encrypt_to($$$$) {
@@ -40,18 +39,7 @@ sub encrypt_to($$$$) {
homedir => Echolot::Config::get()->{'gnupghome'} );
$GnuPG->options->meta_interactive( 0 );
- my ( $stdin_fh, $stdout_fh, $stderr_fh, $status_fh )
- = ( IO::Handle->new(),
- IO::Handle->new(),
- IO::Handle->new(),
- IO::Handle->new(),
- );
- my $handles = GnuPG::Handles->new (
- stdin => $stdin_fh,
- stdout => $stdout_fh,
- stderr => $stderr_fh,
- status => $status_fh
- );
+ my ( $stdin_fh, $stdout_fh, $stderr_fh, $status_fh, $handles ) = Echolot::Tools::make_gpg_fds();
my $pid = $GnuPG->wrap_call(
commands => [ '--import' ],
command_args => [qw{--no-options --no-secmem-warning --no-default-keyring --fast-list-mode --keyring}, $keyring, '--', '-' ],
@@ -87,18 +75,7 @@ sub encrypt_to($$$$) {
$GnuPG->options->hash_init(
armor => 1 );
- ( $stdin_fh, $stdout_fh, $stderr_fh, $status_fh )
- = ( IO::Handle->new(),
- IO::Handle->new(),
- IO::Handle->new(),
- IO::Handle->new(),
- );
- $handles = GnuPG::Handles->new (
- stdin => $stdin_fh,
- stdout => $stdout_fh,
- stderr => $stderr_fh,
- status => $status_fh
- );
+ ( $stdin_fh, $stdout_fh, $stderr_fh, $status_fh, $handles ) = Echolot::Tools::make_gpg_fds();
my $command_args = [qw{--no-options --no-secmem-warning --always-trust --no-default-keyring --textmode --cipher-algo 3DES --keyring}, $keyring, '--recipient', $recipient];
my $plaintextfile;
diff --git a/Echolot/Stats.pm b/Echolot/Stats.pm
index cdb2372..31eb2b6 100644
--- a/Echolot/Stats.pm
+++ b/Echolot/Stats.pm
@@ -856,18 +856,7 @@ sub build_pgpring_type($$$$) {
# only if we have a conf
if ( defined Echolot::Globals::get()->{'storage'}->get_nick($addr) ) {
- my ( $stdin_fh, $stdout_fh, $stderr_fh, $status_fh )
- = ( IO::Handle->new(),
- IO::Handle->new(),
- IO::Handle->new(),
- IO::Handle->new(),
- );
- my $handles = GnuPG::Handles->new (
- stdin => $stdin_fh,
- stdout => $stdout_fh,
- stderr => $stderr_fh,
- status => $status_fh
- );
+ my ( $stdin_fh, $stdout_fh, $stderr_fh, $status_fh, $handles ) = Echolot::Tools::make_gpg_fds();
my $pid = $GnuPG->wrap_call(
commands => [ '--import' ],
command_args => [qw{--no-options --no-secmem-warning --no-default-keyring --fast-list-mode --keyring}, $keyring, '--', '-' ],
@@ -901,18 +890,7 @@ sub build_pgpring_type($$$$) {
sub build_pgpring_export($$$$) {
my ($GnuPG, $keyring, $file, $keyids) = @_;
- my ( $stdin_fh, $stdout_fh, $stderr_fh, $status_fh )
- = ( IO::Handle->new(),
- IO::Handle->new(),
- IO::Handle->new(),
- IO::Handle->new(),
- );
- my $handles = GnuPG::Handles->new (
- stdin => $stdin_fh,
- stdout => $stdout_fh,
- stderr => $stderr_fh,
- status => $status_fh
- );
+ my ( $stdin_fh, $stdout_fh, $stderr_fh, $status_fh, $handles ) = Echolot::Tools::make_gpg_fds();
my $pid = $GnuPG->wrap_call(
commands => [ '--export' ],
command_args => [qw{--no-options --no-secmem-warning --no-default-keyring --keyring}, $keyring, @$keyids ],
diff --git a/Echolot/Tools.pm b/Echolot/Tools.pm
index fd202f5..9dea6a3 100644
--- a/Echolot/Tools.pm
+++ b/Echolot/Tools.pm
@@ -18,6 +18,7 @@ Echolot::Tools - Tools for echolot
use strict;
use HTML::Template;
use Digest::MD5 qw{};
+use IO::Handle;
use GnuPG::Interface;
use Echolot::Log;
@@ -263,8 +264,15 @@ sub write_HTML_file($$;$%) {
return 1;
};
-
-
+sub make_gpg_fds() {
+ my %fds = (
+ stdin => IO::Handle->new(),
+ stdout => IO::Handle->new(),
+ stderr => IO::Handle->new(),
+ status => IO::Handle->new() );
+ my $handles = GnuPG::Handles->new( %fds );
+ return ($fds{'stdin'}, $fds{'stdout'}, $fds{'stderr'}, $fds{'status'}, $handles);
+};
sub crypt_symmetrically($$) {
my ($msg, $direction) = @_;
@@ -281,18 +289,7 @@ sub crypt_symmetrically($$) {
$GnuPG->options->meta_interactive( 0 );
$GnuPG->passphrase( Echolot::Globals::get()->{'storage'}->get_secret() );
- my ( $stdin_fh, $stdout_fh, $stderr_fh, $status_fh )
- = ( IO::Handle->new(),
- IO::Handle->new(),
- IO::Handle->new(),
- IO::Handle->new(),
- );
- my $handles = GnuPG::Handles->new (
- stdin => $stdin_fh,
- stdout => $stdout_fh,
- stderr => $stderr_fh,
- status => $status_fh
- );
+ my ( $stdin_fh, $stdout_fh, $stderr_fh, $status_fh, $handles ) = make_gpg_fds();
my $pid =
$direction eq 'encrypt' ?
$GnuPG->encrypt_symmetrically( handles => $handles ) :
diff --git a/NEWS b/NEWS
index 3f61d9c..0e9d45b 100644
--- a/NEWS
+++ b/NEWS
@@ -8,6 +8,8 @@ Changes in version - 2004
manually.
* Remove get_remailers since get_addresses does almost the same.
* Make sure we do not create empty key hashes in metadata.
+ * gpg interaction cleanup, move a lot of duplicated code to
+ Echolot::Tools.
Changes in version 2.1.3 - 2004-04-20
* Improvements to pingd.conf(5) by Colin.