line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTTP::Session::ID::Urandom; |
2
|
1
|
|
|
1
|
|
1397
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
33
|
|
4
|
1
|
|
|
1
|
|
952
|
use utf8; |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
9
|
|
5
|
1
|
|
|
1
|
|
49
|
use 5.008_001; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
42
|
|
6
|
1
|
|
|
1
|
|
889
|
use MIME::Base64; |
|
1
|
|
|
|
|
786
|
|
|
1
|
|
|
|
|
79
|
|
7
|
1
|
|
|
1
|
|
968
|
use POSIX; |
|
1
|
|
|
|
|
8189
|
|
|
1
|
|
|
|
|
8
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $URANDOM_FH; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
# $URANDOM_FH is undef if there is no /dev/urandom |
12
|
|
|
|
|
|
|
open $URANDOM_FH, '<:raw', '/dev/urandom' |
13
|
|
|
|
|
|
|
or die "Cannot open /dev/urandom: $!."; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub generate_id { |
16
|
3
|
|
|
3
|
0
|
17
|
my ($class, $sid_length) = @_; |
17
|
3
|
|
|
|
|
29
|
my $src_len = POSIX::ceil($sid_length/3.0*4.0); |
18
|
|
|
|
|
|
|
# Generate session id from /dev/urandom. |
19
|
3
|
|
|
|
|
908
|
my $read = read($URANDOM_FH, my $buf, $src_len); |
20
|
3
|
50
|
|
|
|
12
|
if ($read != $src_len) { |
21
|
0
|
|
|
|
|
0
|
die "Cannot read bytes from /dev/urandom: $!"; |
22
|
|
|
|
|
|
|
} |
23
|
3
|
|
|
|
|
21
|
my $result = MIME::Base64::encode_base64($buf, ''); |
24
|
3
|
|
|
|
|
8
|
$result =~ tr|+/=|\-_|d; # make it url safe |
25
|
3
|
|
|
|
|
24
|
return substr($result, 0, $sid_length); |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
1; |
29
|
|
|
|
|
|
|
|