SRS/Shortcut.pm

filter: Statementstmt 87.8% 29 / 33 Branchbran 60.0% 6 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 7 / 7 Podpod 100% 2 / 2 totaltotal 84.6% 44 / 52 CC 6 SCAR 10.5
CC
6
Cov
81%
parse
5.0
compile
3.1
BEGIN
1.0
CRAP 2.9
« SRS/Guarded.pm ↑ Summary SRS/Reversable.pm »
1 package Mail::SRS::Shortcut;
2  
3 9 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 9 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 9 ▶use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
6 9 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 9 ▶use Mail::SRS qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 9 @ISA = qw(Mail::SRS);
10  
11 =head1 NAME
12  
13 Mail::SRS::Shortcut - A shortcutting Sender Rewriting Scheme
14  
15 =head1 SYNOPSIS
16  
17 use Mail::SRS::Shortcut;
18 my $srs = new Mail::SRS::Shortcut(...);
19  
20 =head1 DESCRIPTION
21  
22 WARNING: Using the simple Shortcut strategy is a very bad idea. Use the
23 Guarded strategy instead. The weakness in the Shortcut strategy is
24 documented at http://www.anarres.org/projects/srs/
25  
26 See Mail::SRS for details of the standard SRS subclass interface.
27 This module provides the methods compile() and parse(). It operates
28 without store, and shortcuts around all middleman resenders.
29  
30 =head1 SEE ALSO
31  
32 L<Mail::SRS>
33  
34 =cut
35  
36 64 ▶sub compile {
Subroutine compile: called CC=3 SCAR=11.2
Pod documented
37 64 my ($self, $sendhost, $senduser) = @_;
38  
39 64 ▶ if ($senduser =~ s/^$SRS0RE//io) {
Branch: 2 branches
BranchTrueFalseTotal
if ($senduser =~ s/^$Mail::SRS::Shortcut::SRS0RE//io) { } 16 48 64
elsif ($senduser =~ s/$Mail::SRS::Shortcut::SRS1RE//io) { } 0 48 48
40 # This duplicates effort in Guarded.pm but makes this file work
41 # standalone.
42 # We just do the split because this was hashed with someone
43 # else's secret key and we can't check it.
44 # hash, timestamp, host, user
45 16 (undef, undef, $sendhost, $senduser) =
46 split(qr/\Q$SRSSEP\E/, $senduser, 4);
47 # We should do a sanity check. After all, it might NOT be
48 # an SRS address, unlikely though that is. We are in the
49 # presence of malicious agents. However, this code is
50 # never reached if the Guarded subclass is used.
51 }
52 elsif ($senduser =~ s/$SRS1RE//io) {
53 # This should never be hit in practice. It would be bad.
54 # Introduce compatibility with the guarded format?
55 # SRSHOST, hash, timestamp, host, user
56 0 (undef, undef, undef, $sendhost, $senduser) =
57 split(qr/\Q$SRSSEP\E/, $senduser, 6);
58 }
59  
60 64 my $timestamp = $self->timestamp_create();
61  
62 64 my $hash = $self->hash_create($timestamp, $sendhost, $senduser);
63  
64 # Note that there are 5 fields here and that sendhost may
65 # not contain a valid separator. Therefore, we do not need to
66 # escape separators anywhere in order to reverse this
67 # transformation.
68 64 return $SRS0TAG . $self->separator .
69 join($SRSSEP, $hash, $timestamp, $sendhost, $senduser);
70 }
71  
72 95 ▶sub parse {
Subroutine parse: called CC=4 SCAR=16.1
Pod documented
73 95 my ($self, $user) = @_;
74  
75 95 ▶ unless ($user =~ s/$SRS0RE//oi) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($user =~ s/$Mail::SRS::Shortcut::SRS0RE//io) 0 95 95
76 # We should deal with SRS1 addresses here, just in case?
77 0 die "Reverse address does not match $SRS0RE.";
78 }
79  
80 # The 4 here matches the number of fields we encoded above. If
81 # there are more separators, then they belong in senduser anyway.
82 95 my ($hash, $timestamp, $sendhost, $senduser) =
83 split(qr/\Q$SRSSEP\E/, $user, 4);
84 # Again, this must match as above.
85 95 ▶ unless ($self->hash_verify($hash,$timestamp,$sendhost,$senduser)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->hash_verify($hash, $timestamp, $sendhost, $senduser)) 0 95 95
86 0 die "Invalid hash";
87 }
88  
89 95 ▶ unless ($self->timestamp_check($timestamp)) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->timestamp_check($timestamp)) 0 95 95
90 0 die "Invalid timestamp";
91 }
92  
93 95 return ($sendhost, $senduser);
94 }
95  
96 9 1;
« SRS/Guarded.pm ↑ Summary SRS/Reversable.pm »