Codebase list libcryptx-perl / 653122d _generators / Digest.t.tt
653122d

Tree @653122d (Download .tar.gz)

Digest.t.tt @653122draw · history · blame

[%comment%]

use strict;
use warnings;

use Test::More tests => 8*[%t_strings_count%] + 9*[%t_files_count%] + 10 + 6;

use Crypt::Digest qw( digest_data digest_data_hex digest_data_b64 digest_data_b64u digest_file digest_file_hex digest_file_b64 digest_file_b64u );
use Crypt::Digest::[%orig_name%] qw( [%lc_name%] [%lc_name%]_hex [%lc_name%]_b64 [%lc_name%]_b64u [%lc_name%]_file [%lc_name%]_file_hex [%lc_name%]_file_b64 [%lc_name%]_file_b64u );

is( Crypt::Digest::hashsize('[%orig_name%]'), [%hashsize%], 'hashsize/1');
is( Crypt::Digest->hashsize('[%orig_name%]'), [%hashsize%], 'hashsize/2');
is( Crypt::Digest::[%orig_name%]::hashsize, [%hashsize%], 'hashsize/3');
is( Crypt::Digest::[%orig_name%]->hashsize, [%hashsize%], 'hashsize/4');
is( Crypt::Digest->new('[%orig_name%]')->hashsize, [%hashsize%], 'hashsize/5');
is( Crypt::Digest::[%orig_name%]->new->hashsize, [%hashsize%], 'hashsize/6');

is( [%lc_name%]("A","A","A"), pack("H*","[%tripple_A.hex%]"), '[%lc_name%] (raw/tripple_A)');
is( [%lc_name%]_hex("A","A","A"), "[%tripple_A.hex%]", '[%lc_name%] (hex/tripple_A)');
is( [%lc_name%]_b64("A","A","A"), "[%tripple_A.base64%]", '[%lc_name%] (base64/tripple_A)');
is( [%lc_name%]_b64u("A","A","A"), "[%tripple_A.base64url%]", '[%lc_name%] (base64url/tripple_A)');
is( digest_data('[%orig_name%]', "A","A","A"), pack("H*","[%tripple_A.hex%]"), '[%lc_name%] (digest_data_raw/tripple_A)');
is( digest_data_hex('[%orig_name%]', "A","A","A"), "[%tripple_A.hex%]", '[%lc_name%] (digest_data_hex/tripple_A)');
is( digest_data_b64('[%orig_name%]', "A","A","A"), "[%tripple_A.base64%]", '[%lc_name%] (digest_data_b64/tripple_A)');
is( digest_data_b64u('[%orig_name%]', "A","A","A"), "[%tripple_A.base64url%]", '[%lc_name%] (digest_data_b64u/tripple_A)');
is( Crypt::Digest::[%orig_name%]->new->add("A","A","A")->hexdigest, "[%tripple_A.hex%]", '[%lc_name%] (OO/tripple_A)');
is( Crypt::Digest::[%orig_name%]->new->add("A")->add("A")->add("A")->hexdigest, "[%tripple_A.hex%]", '[%lc_name%] (OO3/tripple_A)');

[% FOREACH v IN t_strings %]
is( [%lc_name%]([%v.data%]), pack("H*","[%v.hex%]"), '[%lc_name%] (raw/[%loop.count%])');
is( [%lc_name%]_hex([%v.data%]), "[%v.hex%]", '[%lc_name%] (hex/[%loop.count%])');
is( [%lc_name%]_b64([%v.data%]), "[%v.base64%]", '[%lc_name%] (base64/[%loop.count%])');
is( digest_data('[%orig_name%]', [%v.data%]), pack("H*","[%v.hex%]"), '[%lc_name%] (digest_data_raw/[%loop.count%])');
is( digest_data_hex('[%orig_name%]', [%v.data%]), "[%v.hex%]", '[%lc_name%] (digest_data_hex/[%loop.count%])');
is( digest_data_b64('[%orig_name%]', [%v.data%]), "[%v.base64%]", '[%lc_name%] (digest_data_b64/[%loop.count%])');
is( digest_data_b64u('[%orig_name%]', [%v.data%]), "[%v.base64url%]", '[%lc_name%] (digest_data_b64u/[%loop.count%])');
is( Crypt::Digest::[%orig_name%]->new->add([%v.data%])->hexdigest, "[%v.hex%]", '[%lc_name%] (OO/[%loop.count%])');
[% END %]
[% FOREACH v IN t_files %]
is( [%lc_name%]_file('[%v.file%]'), pack("H*","[%v.hex%]"), '[%lc_name%] (raw/file/[%loop.count%])');
is( [%lc_name%]_file_hex('[%v.file%]'), "[%v.hex%]", '[%lc_name%] (hex/file/[%loop.count%])');
is( [%lc_name%]_file_b64('[%v.file%]'), "[%v.base64%]", '[%lc_name%] (base64/file/[%loop.count%])');
is( digest_file('[%orig_name%]', '[%v.file%]'), pack("H*","[%v.hex%]"), '[%lc_name%] (digest_file_raw/file/[%loop.count%])');
is( digest_file_hex('[%orig_name%]', '[%v.file%]'), "[%v.hex%]", '[%lc_name%] (digest_file_hex/file/[%loop.count%])');
is( digest_file_b64('[%orig_name%]', '[%v.file%]'), "[%v.base64%]", '[%lc_name%] (digest_file_b64/file/[%loop.count%])');
is( digest_file_b64u('[%orig_name%]', '[%v.file%]'), "[%v.base64url%]", '[%lc_name%] (digest_file_b64u/file/[%loop.count%])');
is( Crypt::Digest::[%orig_name%]->new->addfile('[%v.file%]')->hexdigest, "[%v.hex%]", '[%lc_name%] (OO/file/[%loop.count%])');
{
  open(my $fh, '<', '[%v.file%]');
  binmode($fh);
  is( Crypt::Digest::[%orig_name%]->new->addfile($fh)->hexdigest, "[%v.hex%]", '[%lc_name%] (OO/filehandle/[%loop.count%])');
  close($fh);
}
[% END %]