home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / perl5 / GnuPG / Options.pm < prev    next >
Encoding:
Perl POD Document  |  2010-05-08  |  8.3 KB  |  359 lines

  1. #  Options.pm
  2. #    - providing an object-oriented approach to GnuPG's options
  3. #
  4. #  Copyright (C) 2000 Frank J. Tobin <ftobin@cpan.org>
  5. #
  6. #  This module is free software; you can redistribute it and/or modify it
  7. #  under the same terms as Perl itself.
  8. #
  9. #  This program is distributed in the hope that it will be useful,
  10. #  but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  12. #
  13. #  $Id: Options.pm,v 1.14 2001/08/21 13:31:50 ftobin Exp $
  14. #
  15.  
  16. package GnuPG::Options;
  17. use Any::Moose;
  18. with qw(GnuPG::HashInit);
  19.  
  20. use constant BOOLEANS => qw(
  21.     armor
  22.     no_greeting
  23.     verbose
  24.     no_verbose
  25.     quiet
  26.     batch
  27.     always_trust
  28.     rfc1991
  29.     openpgp
  30.     force_v3_sigs
  31.     no_options
  32.     textmode
  33.     meta_pgp_5_compatible
  34.     meta_pgp_2_compatible
  35.     meta_interactive
  36. );
  37.  
  38. use constant SCALARS => qw(
  39.     homedir
  40.     default_key
  41.     comment
  42.     status_fd
  43.     logger_fd
  44.     passphrase_fd
  45.     command_fd
  46.     compress_algo
  47.     options
  48.     meta_signing_key
  49.     meta_signing_key_id
  50. );
  51.  
  52. use constant LISTS => qw(
  53.     encrypt_to
  54.     recipients
  55.     meta_recipients_keys
  56.     meta_recipients_key_ids
  57.     extra_args
  58. );
  59.  
  60. has $_ => (
  61.     isa     => 'Bool',
  62.     is      => 'rw',
  63.     clearer => 'clear_' . $_,
  64. ) for BOOLEANS;
  65.  
  66. has $_ => (
  67.     isa     => 'Any',
  68.     is      => 'rw',
  69.     clearer => 'clear_' . $_,
  70. ) for SCALARS;
  71.  
  72. for my $list (LISTS) {
  73.     has $list => (
  74.         isa        => 'ArrayRef',
  75.         is         => 'rw',
  76.         lazy       => 1,
  77.         clearer    => "clear_$list",
  78.         default    => sub { [] },
  79.         auto_deref => 1,
  80.     );
  81.     __PACKAGE__->meta->add_method("push_$list" => sub {
  82.         my $self = shift;
  83.         push @{ $self->$list }, @_;
  84.     });
  85. }
  86.  
  87. sub BUILD {
  88.     my ( $self, $args ) = @_;
  89.     $self->hash_init( meta_interactive => 1 );
  90.     $self->hash_init(%$args);
  91. }
  92.  
  93. sub copy {
  94.     my ($self) = @_;
  95.  
  96.     my $new = ( ref $self )->new();
  97.  
  98.     foreach my $field ( BOOLEANS, SCALARS, LISTS ) {
  99.         my $value = $self->$field();
  100.         next unless defined $value;
  101.         $new->$field($value);
  102.     }
  103.  
  104.     return $new;
  105. }
  106.  
  107. sub get_args {
  108.     my ($self) = @_;
  109.  
  110.     return (
  111.         $self->get_meta_args(),
  112.         $self->get_option_args(),
  113.         $self->extra_args(),
  114.     );
  115. }
  116.  
  117. sub get_option_args {
  118.     my ($self) = @_;
  119.  
  120.     my @args = ();
  121.  
  122.     push @args, '--homedir', $self->homedir() if $self->homedir();
  123.     push @args, '--options', $self->options() if $self->options();
  124.     push @args, '--no-options' if $self->no_options();
  125.     push @args, '--armor'      if $self->armor();
  126.     push @args, '--textmode'   if $self->textmode();
  127.     push @args, '--default-key', $self->default_key() if $self->default_key();
  128.     push @args, '--no-greeting'  if $self->no_greeting();
  129.     push @args, '--verbose'      if $self->verbose();
  130.     push @args, '--no-verbose'   if $self->no_verbose();
  131.     push @args, '--quiet'        if $self->quiet();
  132.     push @args, '--batch'        if $self->batch();
  133.     push @args, '--always-trust' if $self->always_trust();
  134.     push @args, '--comment', $self->comment() if defined $self->comment();
  135.     push @args, '--force-v3-sigs' if $self->force_v3_sigs();
  136.     push @args, '--rfc1991'       if $self->rfc1991;
  137.     push @args, '--openpgp'       if $self->openpgp();
  138.     push @args, '--compress-algo', $self->compress_algo()
  139.         if defined $self->compress_algo();
  140.  
  141.     push @args, '--status-fd', $self->status_fd()
  142.         if defined $self->status_fd();
  143.     push @args, '--logger-fd', $self->logger_fd()
  144.         if defined $self->logger_fd();
  145.     push @args, '--passphrase-fd', $self->passphrase_fd()
  146.         if defined $self->passphrase_fd();
  147.     push @args, '--command-fd', $self->command_fd()
  148.         if defined $self->command_fd();
  149.  
  150.     push @args, map { ( '--recipient',  $_ ) } $self->recipients();
  151.     push @args, map { ( '--encrypt-to', $_ ) } $self->encrypt_to();
  152.  
  153.     return @args;
  154. }
  155.  
  156. sub get_meta_args {
  157.     my ($self) = @_;
  158.  
  159.     my @args = ();
  160.  
  161.     push @args, '--compress-algo', 1, '--force-v3-sigs'
  162.         if $self->meta_pgp_5_compatible();
  163.     push @args, '--rfc1991' if $self->meta_pgp_2_compatible();
  164.     push @args, '--batch', '--no-tty' if not $self->meta_interactive();
  165.  
  166.     # To eliminate confusion, we'll move to having any options
  167.     # that deal with keys end in _id(s) if they only take
  168.     # an id; otherwise we assume that a GnuPG::Key
  169.     push @args, '--default-key', $self->meta_signing_key_id()
  170.         if $self->meta_signing_key_id();
  171.     push @args, '--default-key', $self->meta_signing_key()->hex_id()
  172.         if $self->meta_signing_key();
  173.  
  174.     push @args,
  175.         map { ( '--recipient', $_ ) } $self->meta_recipients_key_ids();
  176.     push @args,
  177.         map { ( '--recipient', $_->hex_id() ) } $self->meta_recipients_keys();
  178.  
  179.     return @args;
  180. }
  181.  
  182. __PACKAGE__->meta->make_immutable;
  183.  
  184. 1;
  185.  
  186. __END__
  187.  
  188. =head1 NAME
  189.  
  190. GnuPG::Options - GnuPG options embodiment
  191.  
  192. =head1 SYNOPSIS
  193.  
  194.   # assuming $gnupg is a GnuPG::Interface object
  195.   $gnupg->options->armor( 1 );
  196.   $gnupg->options->push_recipients( 'ftobin', '0xABCD1234' );
  197.  
  198. =head1 DESCRIPTION
  199.  
  200. GnuPG::Options objects are generally not instantiated on their
  201. own, but rather as part of a GnuPG::Interface object.
  202.  
  203. =head1 OBJECT METHODS
  204.  
  205. =over 4
  206.  
  207. =item new( I<%initialization_args> )
  208.  
  209. This methods creates a new object.  The optional arguments are
  210. initialization of data members.
  211.  
  212. =item hash_init( I<%args> ).
  213.  
  214.  
  215. =item copy
  216.  
  217. Returns a copy of this object.  Useful for 'saving' options.
  218.  
  219. =item get_args
  220.  
  221. Returns a list of arguments to be passed to GnuPG based
  222. on data members which are 'meta_' options, regular options,
  223. and then I<extra_args>, in that order.
  224.  
  225. =back
  226.  
  227. =head1 OBJECT DATA MEMBERS
  228.  
  229. =over 4
  230.  
  231. =item homedir
  232.  
  233. =item armor
  234.  
  235. =item textmode
  236.  
  237. =item default_key
  238.  
  239. =item no_greeting
  240.  
  241. =item verbose
  242.  
  243. =item no_verbose
  244.  
  245. =item quiet
  246.  
  247. =item batch
  248.  
  249. =item always_trust
  250.  
  251. =item comment
  252.  
  253. =item status_fd
  254.  
  255. =item logger_fd
  256.  
  257. =item passphrase_fd
  258.  
  259. =item compress_algo
  260.  
  261. =item force_v3_sigs
  262.  
  263. =item rfc1991
  264.  
  265. =item openpgp
  266.  
  267. =item options
  268.  
  269. =item no_options
  270.  
  271. =item encrypt_to
  272.  
  273. =item recipients
  274.  
  275. =back
  276.  
  277. These options correlate directly to many GnuPG options.  For those that
  278. are boolean to GnuPG, simply that argument is passed.  For those
  279. that are associated with a scalar, that scalar is passed passed
  280. as an argument appropriate.  For those that can be specified more
  281. than once, such as B<recipients>, those are considered lists
  282. and passed accordingly.  Each are undefined or false to begin.
  283.  
  284. =head2 Meta Options
  285.  
  286. Meta options are those which do not correlate directly to any
  287. option in GnuPG, but rather are generally a bundle of options
  288. used to accomplish a specific goal, such as obtaining
  289. compatibility with PGP 5.  The actual arguments each of these
  290. reflects may change with time.  Each defaults to false unless
  291. otherwise specified.
  292.  
  293. These options are being designed and to provide a non-GnuPG-specific
  294. abstraction, to help create compatibility with a possible
  295. PGP::Interface module.
  296.  
  297. To help avoid confusion, methods with take a form of a key as
  298. an object shall be prepended with I<_id(s)> if they only
  299. take an id; otherwise assume an object of type GnuPG::Key
  300. is required.
  301.  
  302. =over 4
  303.  
  304. =item meta_pgp_5_compatible
  305.  
  306. If true, arguments are generated to try to be compatible with PGP 5.x.
  307.  
  308. =item meta_pgp_2_compatible
  309.  
  310. If true, arguments are generated to try to be compatible with PGP 2.x.
  311.  
  312. =item meta_interactive
  313.  
  314. If false, arguments are generated to try to help the using program
  315. use GnuPG in a non-interactive environment, such as CGI scripts.
  316. Default is true.
  317.  
  318. =item meta_signing_key_id
  319.  
  320. This scalar reflects the key used to sign messages.
  321. Currently this is synonymous with I<default-key>.
  322.  
  323. =item meta_signing_key
  324.  
  325. This GnuPG::Key object reflects the key used to sign messages.
  326.  
  327. =item meta_recipients_key_ids
  328.  
  329. This list of scalar key ids are used to generate the
  330. appropriate arguments having these keys as recipients.
  331.  
  332. =item meta_recipients_keys
  333.  
  334. This list of keys of the type GnuPG::Key are used to generate the
  335. appropriate arguments having these keys as recipients.
  336. You probably want to have this list be of the inherited class
  337. GnuPG::SubKey, as in most instances, OpenPGP keypairs have
  338. the encyrption key as the subkey of the primary key, which is
  339. used for signing.
  340.  
  341. =back
  342.  
  343. =head2 Other Data Members
  344.  
  345. =over 4
  346.  
  347. =item extra_args
  348.  
  349. This is a list of any other arguments used to pass to GnuPG.
  350. Useful to pass an argument not yet covered in this package.
  351.  
  352. =back
  353.  
  354. =head1 SEE ALSO
  355.  
  356. L<GnuPG::Interface>,
  357.  
  358. =cut
  359.