| 1 | package Authen::ModAuthToken; | ||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 3 | require Exporter; | |||||||||||
| 5 | 3 | ▶ | use Carp; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 3 | ▶ | use URI::Escape; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 3 | ▶ | use Digest::MD5 qw/md5_hex/; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | |||||||||||||
| 9 | 3 | our @ISA = qw(Exporter); | |||||||||||
| 10 | 3 | our @EXPORT_OK = qw/generate_mod_auth_token/; | |||||||||||
| 11 | |||||||||||||
| 12 | 3 | our $VERSION = '0.03'; | |||||||||||
| 13 | |||||||||||||
| 14 | sub generate_mod_auth_token | ||||||||||||
| 15 | 1 | ▶ | { | ||||||||||
|
Subroutine
generate_mod_auth_token: called CC=7 SCAR=19.8
Pod
documented
| |||||||||||||
| 16 | 1 | my %args = @_; | |||||||||||
| 17 | |||||||||||||
| 18 | 1 | ▶ | my $secret = $args{secret} or croak "Missing 'secret' key value"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 19 | 1 | ▶ | my $remote_addr = $args{remote_addr} || ""; | ||||||||||
|
Condition50%1/2
$args{'remote_addr'} || ''
MC/DC0%0/1
$args{'remote_addr'} || ''
$args{'remote_addr'}
Truth table50%1/2
A
A= $args{'remote_addr'}
| |||||||||||||
| 20 | 1 | ▶ | my $filepath = $args{filepath} or croak "Missing 'filepath' key value"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 21 | 1 | ▶ | die "'filepath' key value should start with '/'" unless substr($filepath,0,1) eq "/"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 22 | |||||||||||||
| 23 | 1 | my $hexTime = sprintf("%08x", time()); | |||||||||||
| 24 | 1 | my $token_md5 = md5_hex ( $secret . $filepath . $hexTime . $remote_addr); | |||||||||||
| 25 | |||||||||||||
| 26 | 1 | my $encoded_url = ""; | |||||||||||
| 27 | 1 | foreach my $part ( split '/', $filepath ) { | |||||||||||
| 28 | 2 | ▶ | next unless $part; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 29 | 1 | $encoded_url .= "/" . uri_escape($part) ; | |||||||||||
| 30 | } | ||||||||||||
| 31 | |||||||||||||
| 32 | 1 | my $url = "/" . $token_md5 . "/" . $hexTime . $encoded_url; | |||||||||||
| 33 | |||||||||||||
| 34 | 1 | return $url; | |||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | # ABSTRACT: A Module to generate Mod-Auth-Token compatible URLs | ||||||||||||
| 38 | |||||||||||||
| 39 | 3 | 1; | |||||||||||
| 40 | __END__ | ||||||||||||