File: crypt.t

package info (click to toggle)
perl 5.20.2-3%2Bdeb8u11
  • links: PTS, VCS
  • area: main
  • in suites: jessie
  • size: 102,964 kB
  • sloc: perl: 555,553; ansic: 214,041; sh: 38,121; pascal: 8,783; cpp: 3,895; makefile: 2,393; xml: 2,325; yacc: 1,741
file content (46 lines) | stat: -rw-r--r-- 1,193 bytes parent folder | download | duplicates (8)
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
42
43
44
45
46
#!./perl -w

BEGIN {
    chdir 't' if -d 't';
    @INC = qw(. ../lib);
}

BEGIN {
    use Config;

    require "test.pl";

    if( !$Config{d_crypt} ) {
        skip_all("crypt unimplemented");
    }
    else {
        plan(tests => 4);
    }
}

# Can't assume too much about the string returned by crypt(),
# and about how many bytes of the encrypted (really, hashed)
# string matter.
#
# HISTORICALLY the results started with the first two bytes of the salt,
# followed by 11 bytes from the set [./0-9A-Za-z], and only the first
# eight characters mattered, but those are probably no more safe
# bets, given alternative encryption/hashing schemes like MD5,
# C2 (or higher) security schemes, and non-UNIX platforms.

SKIP: {
	skip ("VOS crypt ignores salt.", 1) if ($^O eq 'vos');
	ok(substr(crypt("ab", "cd"), 2) ne substr(crypt("ab", "ce"), 2), "salt makes a difference");
}

$a = "a\xFF\x{100}";

eval {$b = crypt($a, "cd")};
like($@, qr/Wide character in crypt/, "wide characters ungood");

chop $a; # throw away the wide character

eval {$b = crypt($a, "cd")};
is($@, '',                   "downgrade to eight bit characters");
is($b, crypt("a\xFF", "cd"), "downgrade results agree");