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 $file = File::Spec->catfile(dirname($0), "oo.tmp");
34 open(my $fh, q{>}, $file);
36 print $fh "bcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq";
39 my $ctx = Digest::SHA->new()->reset("SHA-256")->new();
40 $ctx->add_bits("a", 5)->add_bits("001");
42 my $rsp = shift(@vec);
43 ok($ctx->clone->add("b", "c")->b64digest, $rsp);
47 # test addfile with bareword filehandle
49 open(FILE, "<$file"); ## no critic
50 binmode(FILE); ## no critic
51 ok($ctx->clone->addfile(*FILE)->hexdigest, $rsp); ## no critic
52 close(FILE); ## no critic
54 # test addfile with indirect filehandle
56 undef($fh); open($fh, q{<}, $file);
58 ok($ctx->clone->addfile($fh)->hexdigest, $rsp);
61 # test addfile using file name instead of handle
63 ok($ctx->addfile($file, "b")->hexdigest, $rsp);
65 # test addfile portable mode
67 undef($fh); open($fh, q{>}, $file);
69 print $fh "abc\012" x 2048; # using UNIX newline
72 ok($ctx->new(1)->addfile($file, "p")->hexdigest,
73 "d449e19c1b0b0c191294c8dc9fa2e4a6ff77fc51");
75 undef($fh); open($fh, q{>}, $file);
77 print $fh "abc\015\012" x 2048; # using DOS/Windows newline
80 ok($ctx->new(1)->addfile($file, "p")->hexdigest,
81 "d449e19c1b0b0c191294c8dc9fa2e4a6ff77fc51");
83 undef($fh); open($fh, q{>}, $file);
85 print $fh "abc\015" x 2048; # using Apple/Mac newline
88 ok($ctx->new(1)->addfile($file, "p")->hexdigest,
89 "d449e19c1b0b0c191294c8dc9fa2e4a6ff77fc51");