Subject: | lowercase and undef Signature tag checks |
Date: | Tue, 15 Oct 2019 18:00:24 +0000 |
To: | "bug-Mail-DKIM [...] rt.cpan.org" <bug-Mail-DKIM [...] rt.cpan.org> |
From: | Todd Richmond <trichmond [...] proofpoint.com> |
There are several instances where signature tags need to be lowercased to ensure proper comparison. Many checks can also be simplified by using the // operator which also ensures that values of ‘0’ work correctly
--- lib/Mail/DKIM/DkSignature.pm.orig 2019-03-14 18:24:59.425580152 -0700
+++ lib/Mail/DKIM/DkSignature.pm 2019-03-26 17:23:13.135808333 -0700
@@ -148,8 +148,7 @@
$self->set_tag( 'a', shift );
}
- my $a = $self->get_tag('a');
- return defined $a && $a ne '' ? lc $a : 'rsa-sha1';
+ return lc $self->get_tag('a') // 'rsa-sha1';
}
=head2 canonicalization()
@@ -175,7 +174,7 @@
$self->set_tag( 'c', shift );
}
- return lc( $self->get_tag('c') ) || 'simple';
+ return lc( $self->get_tag('c') ) // 'simple';
}
sub DEFAULT_PREFIX {
@@ -201,8 +200,7 @@
$self->set_tag( 'd', shift );
}
- my $d = $self->get_tag('d');
- return defined $d ? lc $d : undef;
+ return lc( $self->get_tag('d') // '' );
}
sub expiration {
@@ -358,7 +356,7 @@
# although draft-delany-domainkeys-base-06 does mandate presence of a
# q=dns tag, it is quote common that q tag is missing - be merciful
- return !defined( $self->get_tag('q') ) ? 'dns' : $self->get_tag('q');
+ return lc $self->get_tag('q') // 'dns';
}
=head2 selector()
--- lib/Mail/DKIM/Signature.pm.orig 2019-03-15 14:50:01.725404613 -0700
+++ lib/Mail/DKIM/Signature.pm 2019-03-26 17:20:48.643066419 -0700
@@ -138,8 +138,8 @@
$self->set_tag( 'a', shift );
}
- my $a = $self->get_tag('a');
- return defined $a ? lc $a : undef;
+ # pushing the problem up the stack, but no "lc(undef)" here...
+ return ( defined( $self->get_tag('a') ) ) ? lc( $self->get_tag('a') ) : undef;
}
=head2 as_string() - the signature header as a string
@@ -265,8 +265,7 @@
$self->set_tag( 'c', join( '/', @_ ) );
}
- my $c = $self->get_tag('c');
- $c = lc $c if defined $c;
+ my $c = lc( $self->get_tag('c') // 'simple/simple' );
if ( not $c ) {
$c = 'simple/simple';
}
@@ -441,8 +440,7 @@
$self->set_tag( 'd', shift );
}
- my $d = $self->get_tag('d');
- return defined $d ? lc $d : undef;
+ return lc( $self->get_tag('d') // '' );
}
=head2 expiration() - get or set the signature expiration (x=) field
@@ -733,7 +731,7 @@
$self->set_tag( 'c', shift );
}
- return ( lc $self->get_tag('c') ) || 'simple';
+ return lc $self->get_tag('c') // 'simple';
}
=head2 protocol() - get or set the query methods (q=) field
Message body is not shown because it is too large.