Skip to content

Commit

Permalink
removed another useless function
Browse files Browse the repository at this point in the history
  • Loading branch information
kraih committed Jan 13, 2015
1 parent 09499d4 commit fd82bfa
Showing 1 changed file with 27 additions and 29 deletions.
56 changes: 27 additions & 29 deletions lib/Mojolicious/Controller.pm
Expand Up @@ -80,7 +80,32 @@ sub every_param {
return @$uploads ? $uploads : $req->every_param($name);
}

sub every_signed_cookie { _signed_cookie(@_) }
sub every_signed_cookie {
my ($self, $name) = @_;

my $secrets = $self->stash->{'mojo.secrets'};
my @results;
for my $value (@{$self->every_cookie($name)}) {

# Check signature with rotating secrets
if ($value =~ s/--([^\-]+)$//) {
my $signature = $1;

my $valid;
for my $secret (@$secrets) {
my $check = Mojo::Util::hmac_sha1_sum($value, $secret);
++$valid and last if Mojo::Util::secure_compare($signature, $check);
}
if ($valid) { push @results, $value }

else { $self->app->log->debug(qq{Cookie "$name" has bad signature.}) }
}

else { $self->app->log->debug(qq{Cookie "$name" not signed.}) }
}

return \@results;
}

sub finish {
my $self = shift;
Expand Down Expand Up @@ -285,7 +310,7 @@ sub signed_cookie {
return map { $self->signed_cookie($_) } @$name if ref $name eq 'ARRAY';

# Request cookie
return _signed_cookie($self, $name)->[-1] unless defined $value;
return $self->every_signed_cookie($name)->[-1] unless defined $value;

# Response cookie
my $checksum
Expand Down Expand Up @@ -365,33 +390,6 @@ sub write_chunk {
return $self->rendered;
}

sub _signed_cookie {
my ($self, $name) = @_;

my $secrets = $self->stash->{'mojo.secrets'};
my @results;
for my $value (@{$self->every_cookie($name)}) {

# Check signature with rotating secrets
if ($value =~ s/--([^\-]+)$//) {
my $signature = $1;

my $valid;
for my $secret (@$secrets) {
my $check = Mojo::Util::hmac_sha1_sum($value, $secret);
++$valid and last if Mojo::Util::secure_compare($signature, $check);
}
if ($valid) { push @results, $value }

else { $self->app->log->debug(qq{Cookie "$name" has bad signature.}) }
}

else { $self->app->log->debug(qq{Cookie "$name" not signed.}) }
}

return \@results;
}

1;

=encoding utf8
Expand Down

0 comments on commit fd82bfa

Please sign in to comment.