From 249146ae2680e0d4b8ccc6f1d5d7c9a84cee2969 Mon Sep 17 00:00:00 2001 From: Rafael Casado Sanchez Date: Tue, 17 Mar 2015 12:04:23 +0100 Subject: [PATCH] Added padding for Base64 outputs in case RIPEMD modules comply with the CPAN Digest convention in the future --- lib/DDG/Goodie/RIPEMD.pm | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/DDG/Goodie/RIPEMD.pm b/lib/DDG/Goodie/RIPEMD.pm index ef982744c..398a4ae20 100644 --- a/lib/DDG/Goodie/RIPEMD.pm +++ b/lib/DDG/Goodie/RIPEMD.pm @@ -31,7 +31,7 @@ my @triggers = qw(ripemd ripemdsum ripemd128 ripemd128sum ripemd-128 ripemd160 r triggers start => @triggers; handle query => sub { - return unless $_ =~ qr/^ripemd\-?(?128|160|256|320|)?(?:sum|)\s* + return unless $_ =~ /^ripemd\-?(?128|160|256|320|)?(?:sum|)\s* (?hex|base64|)\s+(?.*)$/ix; my $ver = $+{'ver'} || 160; # RIPEMD-160 is the most common version in the family @@ -50,6 +50,16 @@ handle query => sub { my $out = $func->($str); + # By convention, CPAN Digest modules do not pad their Base64 output, but the + # Crypt::Digest::RIPEMDXXX doesn't comply with that convention and returns the + # output with padding. In case they change it in the future and to avoid wrong + # results the necessary padding will be implemented here. + if ($enc eq 'base64'){ + while (length($out) % 4) { + $out .= '='; + } + } + return $out, structured_answer => { input => [html_enc($str)],