File: 03-clone.t

package info (click to toggle)
libcrypt-pbkdf2-perl 0.160410-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 156 kB
  • ctags: 45
  • sloc: perl: 589; makefile: 2
file content (41 lines) | stat: -rw-r--r-- 1,151 bytes parent folder | download | duplicates (4)
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
#!perl
use strict;
use warnings;

use Test::More;

BEGIN {
  use_ok 'Crypt::PBKDF2';
  use_ok 'Crypt::PBKDF2::Hash::HMACSHA1';
  use_ok 'Crypt::PBKDF2::Hash::HMACSHA2';
}

{
  my $orig = Crypt::PBKDF2->new(hash_class => 'HMACSHA1');
  my $orig_hasher = $orig->hasher;
  is ref $orig_hasher, 'Crypt::PBKDF2::Hash::HMACSHA1', 'Got the right hasher class';

  {
    my $clone = $orig->clone;
    my $clone_hasher = $clone->hasher;
    isnt $clone_hasher, $orig_hasher, 'Hasher was rebuilt';
    is ref $clone_hasher, 'Crypt::PBKDF2::Hash::HMACSHA1', 'Still the right class';
  }

  {
    my $clone = $orig->clone(hash_class => 'HMACSHA2');
    my $clone_hasher = $clone->hasher;
    isnt $clone_hasher, $orig_hasher, 'Hasher was rebuilt again';
    is ref $clone_hasher, 'Crypt::PBKDF2::Hash::HMACSHA2', 'Rebuilt under the right class';
  }
}

{
  my $hasher = Crypt::PBKDF2::Hash::HMACSHA1->new;
  my $orig = Crypt::PBKDF2->new(hasher => $hasher);
  is $orig->hasher, $hasher, 'Used the hasher we passed in';
  is $orig->clone->hasher, $hasher, 'Same hasher on clone';
  ok ! $orig->has_lazy_hasher, q{Hasher wasn't marked lazy-built};
}

done_testing;