summaryrefslogtreecommitdiff
path: root/t/win32/crypt.t
blob: f0e89ab1434d6d9fb07e319b008ab181ef99adec (plain)
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

BEGIN {
    chdir 't' if -d 't';
    @INC = '../lib';
    require "./test.pl";
    eval 'use Errno';
    die $@ if $@ and !is_miniperl();
}

my @bad_salts =
   (
    [ '',   'zero-length' ],
    [ 'a',  'length 1' ],
    [ '!a', 'bad first character' ],
    [ 'a!', 'bad second character' ],
    [ '@a', 'fencepost before A' ],
    [ '[a', 'fencepost after Z' ],
    [ '`a', 'fencepost before a' ],
    [ '{a', 'fencepost after z' ],
    [ '-a', 'fencepost before .' ],
    [ ':a', 'fencepost after 9' ],
   );

my @good_salts = qw(aa zz AA ZZ .. 99);

plan tests => 2 * @bad_salts + 1 + @good_salts;

for my $bad_salt (@bad_salts) {
    my ($salt, $what) = @$bad_salt;
    $! = 0;
    is(crypt("abc", $salt), undef, "bad salt ($what)");
    is(0+$!, &Errno::EINVAL, "check errno ($what)");
}

is(crypt("abcdef", "ab"), "abDMWw5NL.afs", "sanity check result");

# just to check we're not rejecting any good salts
for my $good_salt (@good_salts) {
    isnt(crypt("abcdef", $good_salt), undef, "good salt $good_salt");
}