Commit | Line | Data |
---|---|---|
69026470 | 1 | #!./perl -w |
7b48dbf9 MS |
2 | |
3 | BEGIN { | |
4 | chdir 't' if -d 't'; | |
69026470 | 5 | @INC = qw(. ../lib); |
7b48dbf9 MS |
6 | } |
7 | ||
7b48dbf9 | 8 | BEGIN { |
69026470 JH |
9 | use Config; |
10 | ||
11 | require "test.pl"; | |
7b48dbf9 MS |
12 | |
13 | if( !$Config{d_crypt} ) { | |
69026470 | 14 | skip_all("crypt unimplemented"); |
7b48dbf9 MS |
15 | } |
16 | else { | |
f2791508 | 17 | plan(tests => 4); |
7b48dbf9 MS |
18 | } |
19 | } | |
20 | ||
85c16d83 JH |
21 | # Can't assume too much about the string returned by crypt(), |
22 | # and about how many bytes of the encrypted (really, hashed) | |
23 | # string matter. | |
24 | # | |
25 | # HISTORICALLY the results started with the first two bytes of the salt, | |
26 | # followed by 11 bytes from the set [./0-9A-Za-z], and only the first | |
27 | # eight characters mattered, but those are probably no more safe | |
28 | # bets, given alternative encryption/hashing schemes like MD5, | |
29 | # C2 (or higher) security schemes, and non-UNIX platforms. | |
30 | ||
dcd1d1bf PG |
31 | SKIP: { |
32 | skip ("VOS crypt ignores salt.", 1) if ($^O eq 'vos'); | |
33 | ok(substr(crypt("ab", "cd"), 2) ne substr(crypt("ab", "ce"), 2), "salt makes a difference"); | |
34 | } | |
85c16d83 | 35 | |
f2791508 JH |
36 | $a = "a\xFF\x{100}"; |
37 | ||
38 | eval {$b = crypt($a, "cd")}; | |
39 | like($@, qr/Wide character in crypt/, "wide characters ungood"); | |
40 | ||
41 | chop $a; # throw away the wide character | |
42 | ||
43 | eval {$b = crypt($a, "cd")}; | |
44 | is($@, '', "downgrade to eight bit characters"); | |
45 | is($b, crypt("a\xFF", "cd"), "downgrade results agree"); | |
46 |