File: opertations.t

package info (click to toggle)
libtie-encryptedhash-perl 1.24-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, buster, forky, sid, trixie
  • size: 136 kB
  • sloc: perl: 555; makefile: 2
file content (124 lines) | stat: -rw-r--r-- 3,518 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/perl -s
##
## Copyright (c) 2000, Vipul Ved Prakash.  All rights reserved.
## This code is free software; you can redistribute it and/or modify
## it under the same terms as Perl itself.
##
## $Id: opertations.t,v 1.1 2000/08/31 16:31:10 vipul Exp vipul $

use lib 'lib';
use lib '../lib';
use lib '/home/vipul/PERL/crypto/secrethash/lib';

use Tie::EncryptedHash; 
use Crypt::Blowfish;
use Data::Dumper;

%v = ( password => 'Doorknob', 
       password_wrong => 'Bweoo',
       cipher => 'Blowfish',
       plaintext => 'Mirrorshades.',
     );


print "1..30\n";
my $i = 1;
for (qw(Object TiedHash)) {

    if (/Object/) { $h = new Tie::EncryptedHash }
    if (/Tied/) { $h = {}; tie %$h, Tie::EncryptedHash }

    $h->{__password} = $v{password};
    $h->{__cipher}   = $v{cipher};


    print qq{($_) STORE/FETCH to/from unencrypted field: \n};
    $h->{plain} = $v{plaintext};
    print $h->{plain} eq $v{plaintext} ? "ok $i\n" : "not ok $i\n"; 
    $i++;

    print qq{($_) STORE/FETCH to/from encrypted field:\n};
    $h->{_encrypted} = $v{plaintext};
    print $h->{_encrypted} eq $v{plaintext} ? "ok $i\n" : "not ok $i\n"; 
    $i++;

    print qq{($_) STORE/FETCH with incorrect password:\n};
    $h->{__password} = $v{password_wrong};
    print $h->{_encrypted} eq $v{plaintext} ? "not ok $i\n" : "ok $i\n";
    $i++;

    print qq{($_) Recover from password change:\n};
    $h->{__password} = $v{password};
    print $h->{_encrypted} eq $v{plaintext} ? "ok $i\n" : "not ok $i\n";
    $i++;

    print qq{($_) EXISTS unencrypted field:\n};
    print exists $h->{plain} ? "ok $i\n" : "not ok $i\n";
    $i++;

    print qq{($_) !EXISTS unencrypted field:\n};
    print exists $$h{plain2} ? "not ok $i\n" : "ok $i\n";
    $i++;

    print qq{($_) EXISTS encrypted field:\n};
    print exists $h->{_encrypted} ? "ok $i\n" : "not ok $i\n";
    $i++;

    print qq{($_) !EXISTS encrypted field:\n};
    print exists $$h{_encrypted2} ? "not ok $i\n" : "ok $i\n";
    $i++;

    print qq{($_) EXISTS encrypted field (incorrect password):\n};
    $h->{__password} = $v{password_wrong};
    print exists $h->{_encrypted} ? "ok $i\n" : "not ok $i\n";
    print Dumper $h;
    $i++;

    print qq{($_) EXISTS encrypted field (incorrect password + hide):\n};
    $h->{__password} = $v{password_wrong};
    $h->{__hide} = "yes";
    print exists $h->{_encrypted} ? "no ok $i\n" : "ok $i\n";
    $i++;
    $h->{__hide} = "no";

    print qq{($_) DELETE plaintext field:\n};
    delete $$h{plain};
    print exists $h->{plain} ? "no ok $i\n" : "ok $i\n";
    $i++;

    print qq{($_) DELETE encrypted field:\n};
    $h->{__password} = $v{password};
    delete $$h{_encrypted};
    print exists $h->{_encrypted} ? "no ok $i\n" : "ok $i\n";
    $i++;

    print qq{($_) FIRSTKEY/NEXTKEY:\n};
    $$h{plain} = $v{plaintext};
    $$h{clone} = $v{plaintext};
    $$h{_encrypted} = $v{plaintext};
    @keys = keys %$h;
    print "@keys\n";
    print $#keys == 2  ? "ok $i\n" : "no ok $i\n";
    $i++;

    print qq{($_) CLEAR Hash with incorrect password:\n};
    $$h{plain} = $v{plaintext};
    $$h{_encrypted} = $v{plaintext};
    $$h{__password} = $v{password_wrong};
    %$h = (); 
    print exists $h->{plain} ? "ok $i\n" : "no ok $i\n";
    $i++;

    print qq{($_) CLEAR Hash with correct password:\n};
    $$h{__password} = $v{password};
    $$h{plain} = $v{plaintext};
    $$h{_encrypted} = $v{plaintext};
    %$h = (); 
    print exists $h->{plain} ? "no ok $i\n" : "ok $i\n";
    $i++;

    undef $h;

}