~ubuntu-branches/ubuntu/precise/libcrypt-gpg-perl/precise

« back to all changes in this revision

Viewing changes to t/04-encdec.t

  • Committer: Bazaar Package Importer
  • Author(s): Roberto Jimeno
  • Date: 2006-11-17 06:54:08 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061117065408-df0cjy0kwa04guha
Tags: 1.52-1
* New maintainer 
* New upstream version (Closes: #329521).
* sign() method generates wrong gpg call and hangs no more, fixed by New
  upstream version (Closes: #264166)
* Changes from CPAN bug tracker to make it work
  http://rt.cpan.org/Public/Bug/Display.html?id=13563
* Upload by Amaya Rodrigo <amaya@debian.org>:
  - (100% MIA highjack) 
  - Updated Standards-Version
  - debian/compat in now 5
  - updated the watch file to version 3
  - made lintian happy: 
    - build-depends-indep-should-be-build-depends debhelper
    - duplicate-relation depends: perl (>= 5.8.0), perl (>= 5.6.0-16) 

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*-cperl-*-
 
2
#
 
3
# enc-dec.t - Crypt::GPG encryption / decryption tests.
 
4
# Copyright (c) 2005 Ashish Gulhati <crypt-gpg at neomailbox.com>
 
5
#
 
6
# All rights reserved. This code is free software; you can
 
7
# redistribute it and/or modify it under the same terms as Perl
 
8
# itself.
 
9
#
 
10
# $Id: 04-encdec.t,v 1.5 2005/02/23 09:12:56 cvs Exp $
 
11
 
 
12
use strict;
 
13
use Test;
 
14
use Crypt::GPG;
 
15
 
 
16
BEGIN { plan tests => 15 }
 
17
 
 
18
my $debug = 0;
 
19
my $dir = $0 =~ /^\// ? $0 : $ENV{PWD} . '/' . $0; $dir =~ s/\/[^\/]*$//;
 
20
$ENV{HOME} = $dir;
 
21
 
 
22
# Create new Crypt::GPG object
 
23
 
 
24
my @x;
 
25
my $gpg = new Crypt::GPG;
 
26
$ENV{GPGBIN} and $gpg->gpgbin($ENV{GPGBIN});
 
27
$gpg->gpgopts('--compress-algo 1 --cipher-algo cast5 --force-v3-sigs --no-comment');
 
28
$gpg->debug($debug);
 
29
 
 
30
# Start test loop with different key sizes/types
 
31
################################################
 
32
for my $bits qw(1024 2048) {
 
33
  for my $type ('ELG-E') {
 
34
 
 
35
    my ($secretkey) = grep { $_->{Type} =~ /^sec[^\@]?/ } $gpg->keyinfo("A $bits $type");
 
36
    $gpg->secretkey($secretkey);
 
37
    $gpg->encryptsafe(0);
 
38
 
 
39
    # Encrypt
 
40
    #########
 
41
    ok(sub {
 
42
         @x = $gpg->encrypt("Test\n", "A $bits $type");
 
43
       });
 
44
 
 
45
    for my $nopass (0,1) {
 
46
      if ($nopass) {
 
47
        # Blank out the Key password and do another round of tests
 
48
        ##########################################################
 
49
        ok(sub {
 
50
             $gpg->passphrase('');
 
51
             $gpg->keypass($secretkey, "$bits Bit $type Test Key", '');
 
52
           });
 
53
      }
 
54
      
 
55
      # Decrypt
 
56
      #########
 
57
      ok(sub {
 
58
           $gpg->passphrase("$bits Bit $type Test Key") unless $nopass;
 
59
           my ($clear) = $gpg->decrypt(@x);
 
60
           $clear eq "Test\n";
 
61
         });
 
62
    }
 
63
 
 
64
    # Set passphrase back to original
 
65
    #################################
 
66
    ok(sub {
 
67
         $gpg->keypass($secretkey, '', "$bits Bit $type Test Key");
 
68
       });
 
69
  }
 
70
}
 
71
 
 
72