File: crypt.t

package info (click to toggle)
perl 5.42.0-2
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 128,392 kB
  • sloc: perl: 534,963; ansic: 240,563; sh: 72,042; pascal: 6,934; xml: 2,428; yacc: 1,360; makefile: 1,197; cpp: 208; lisp: 1
file content (41 lines) | stat: -rw-r--r-- 1,029 bytes parent folder | download | duplicates (6)
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");
}