File: 09-clone-digest.t

package info (click to toggle)
libcrypt-gcrypt-perl 1.26-7
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 364 kB
  • sloc: perl: 237; makefile: 3
file content (56 lines) | stat: -rw-r--r-- 1,366 bytes parent folder | download | duplicates (6)
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
# Before `make install' is performed this script should be runnable with
# `make test'. After `make install' it should work as `perl 09-clone-digest.t'

#########################

use Test;
use ExtUtils::testlib;
use Crypt::GCrypt;

#########################

# SHA1 progressive digests (can we read what the digest should be along the way?):

my %dgsts = (
    '' => 'da39a3ee5e6b4b0d3255bfef95601890afd80709',
    'a' => '86f7e437faa5a7fce15d1ddcb9eaeaea377667b8',
    'abc' => 'a9993e364706816aba3e25717850c26c9cd0d89d',
    'abcdefghijklmnopqrstuvwxyz' => '32d10c7b8cf96570ca04ce37f2a19d84240d3a89',
);

plan tests => 5;

my $md0 = Crypt::GCrypt->new(
                             type => 'digest',
                             algorithm => 'sha1',
                            );
my $result;

my $md1 = $md0->clone();
$result = unpack('H*', $md1->read());
ok($result eq $dgsts{''});

$md0->write('a');

my $md2 = $md0->clone();
$result = unpack('H*', $md2->read());
ok($result eq $dgsts{'a'});

$md0->write('bc');

my $md3 = $md0->clone();
$result = unpack('H*', $md3->read());
ok($result eq $dgsts{'abc'});

$md0->write('defghijklmnopqrstuvwxyz');

my $md4 = $md0->clone();
$result = unpack('H*', $md4->read());
ok($result eq $dgsts{'abcdefghijklmnopqrstuvwxyz'});


$result = unpack('H*', $md0->read());
ok($result eq $dgsts{'abcdefghijklmnopqrstuvwxyz'});