4 use File::Basename qw(dirname);
19 "ungWv48Bz+pBQUDeXa4iI7ADYaOWF3qctBD/YfIAFa0",
20 "248d6a61d20638b8e5c026930c3e6039a33ce45964ff2167f6ecedd419db06c1"
23 plan tests => 6 + scalar(@vec);
26 # attempt to use an invalid algorithm, and check for failure
28 my $NSA = "SHA-42"; # No Such Algorithm
29 ok(Digest::SHA->new($NSA), undef);
31 # test OO methods using first two SHA-256 vectors from NIST
33 my $temp = File::Spec->catfile(dirname($0), "oo.tmp");
34 my $file = File::Spec->canonpath($temp);
37 print FILE "bcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
40 my $ctx = Digest::SHA->new()->reset("SHA-256")->new();
41 $ctx->add_bits("a", 5)->add_bits("001");
43 my $rsp = shift(@vec);
44 ok($ctx->clone->add("b", "c")->b64digest, $rsp);
49 ok($ctx->clone->addfile(*FILE)->hexdigest, $rsp);
52 # use indirect filehandle
54 open(my $fh, "<$file");
56 ok($ctx->clone->addfile($fh)->hexdigest, $rsp);
59 # test addfile using file name instead of handle
61 ok($ctx->addfile($file, "b")->hexdigest, $rsp);
63 # test addfile portable mode
67 print FILE "abc\012" x 2048; # using UNIX newline
70 ok($ctx->new(1)->addfile($file, "p")->hexdigest,
71 "d449e19c1b0b0c191294c8dc9fa2e4a6ff77fc51");
75 print FILE "abc\015\012" x 2048; # using DOS/Windows newline
78 ok($ctx->new(1)->addfile($file, "p")->hexdigest,
79 "d449e19c1b0b0c191294c8dc9fa2e4a6ff77fc51");
83 print FILE "abc\015" x 2048; # using Apple/Mac newline
86 ok($ctx->new(1)->addfile($file, "p")->hexdigest,
87 "d449e19c1b0b0c191294c8dc9fa2e4a6ff77fc51");