Hi Jim,
Jim Meyering schrieb:
> This is what I meant:
> ...
> -  i = 0;
> +  size_t i = 0;
>    while (ISWHITE (s[i]))
>      ++i;
ok, added.

> "make check" runs most tests.
> 
> Use this
> 
>   make check -C tests TESTS=misc/md5sum VERBOSE=yes
> 
> to run just the one you changed.
thanks, tests passed:
PASS: misc/md5sum
=============
1 test passed
=============
PASS: misc/sha1sum
=============
1 test passed
=============

the other sha*sum tests do not test the bsd format, so I also didnt add
the openssl format. Also the doc/coerutils.info doesnt mention yet that
the BSD checksum format is supported, so was not sure about adding now
the openssl format.

Find attached the hopefully correct git patch.

thanks, G√ľnter.


>From 941f0d07618d480110dd3417ccb7e1511e8f9504 Mon Sep 17 00:00:00 2001
From: Guenter Knauf <li...@gknw.net>
Date: Sat, 3 Oct 2009 23:24:26 +0200
Subject: [PATCH] added support for openssl checksum format to md5sum / sha*sum 
tools.

changed src/md5sum.c to also accept file checksums generated by openssl
which are very close to the format of the bsd checksum tools.
---
 NEWS               |    2 ++
 src/md5sum.c       |   11 ++++++-----
 tests/misc/md5sum  |   10 ++++++++++
 tests/misc/sha1sum |   11 +++++++++++
 4 files changed, 29 insertions(+), 5 deletions(-)

diff --git a/NEWS b/NEWS
index aff0744..dea34e4 100644
--- a/NEWS
+++ b/NEWS
@@ -46,6 +46,8 @@ GNU coreutils NEWS                                    -*- 
outline -*-
 
 ** New features
 
+  md5sum / sha*sum now also accept file checksums created with openssl. 
+
   ln now accepts the options --logical (-L) and --physical (-P),
   added by POSIX 2008.  The default behavior is -P on systems like
   GNU/Linux where link(2) creates hard links to symlinks, and -L on
diff --git a/src/md5sum.c b/src/md5sum.c
index e004c5e..aa2a144 100644
--- a/src/md5sum.c
+++ b/src/md5sum.c
@@ -251,11 +251,10 @@ static bool
 split_3 (char *s, size_t s_len,
          unsigned char **hex_digest, int *binary, char **file_name)
 {
-  size_t i;
   bool escaped_filename = false;
   size_t algo_name_len;
 
-  i = 0;
+  size_t i = 0;
   while (ISWHITE (s[i]))
     ++i;
 
@@ -263,11 +262,13 @@ split_3 (char *s, size_t s_len,
   algo_name_len = strlen (DIGEST_TYPE_STRING);
   if (strncmp (s + i, DIGEST_TYPE_STRING, algo_name_len) == 0)
     {
-      if (strncmp (s + i + algo_name_len, " (", 2) == 0)
+      if (s[i + algo_name_len] == ' ')
+        ++i;
+      if (s[i + algo_name_len] == '(')
         {
           *binary = 0;
-          return bsd_split_3 (s +      i + algo_name_len + 2,
-                              s_len - (i + algo_name_len + 2),
+          return bsd_split_3 (s +      i + algo_name_len + 1,
+                              s_len - (i + algo_name_len + 1),
                               hex_digest, file_name);
         }
     }
diff --git a/tests/misc/md5sum b/tests/misc/md5sum
index 2fb024d..30edd9e 100755
--- a/tests/misc/md5sum
+++ b/tests/misc/md5sum
@@ -67,6 +67,16 @@ my @Tests =
      ['check-bsd3', '--check', '--status',
                                 {IN=> {'f.md5' => "MD5 (f) = $degenerate\n"}},
                                 {AUX=> {f=> 'bar'}}, {EXIT=> 1}],
+     ['check-openssl', '--check', {IN=> {'f.sha1' => "SHA1(f)= 
$degenerate\n"}},
+                                {AUX=> {f=> ''}},
+                                {ERR=>"md5sum: f.sha1: no properly formatted "
+                                       . "MD5 checksum lines found\n"},
+                                {EXIT=> 1}],
+     ['check-openssl2', '--check', {IN=> {'f.md5' => "MD5(f)= $degenerate\n"}},
+                                {AUX=> {f=> ''}}, {OUT=>"f: OK\n"}],
+     ['check-openssl3', '--check', '--status',
+                                {IN=> {'f.md5' => "MD5(f)= $degenerate\n"}},
+                                {AUX=> {f=> 'bar'}}, {EXIT=> 1}],
      ['bsd-segv', '--check', {IN=> {'z' => "MD5 ("}}, {EXIT=> 1},
       {ERR=> "$prog: z: no properly formatted MD5 checksum lines found\n"}],
 
diff --git a/tests/misc/sha1sum b/tests/misc/sha1sum
index 3f09aba..d084204 100755
--- a/tests/misc/sha1sum
+++ b/tests/misc/sha1sum
@@ -60,6 +60,17 @@ my @Tests =
      ['check-bsd3', '--check', '--status',
                         {IN=> {'f.sha1' => "SHA1 (f) = $sha_degenerate\n"}},
                         {AUX=> {f=> 'bar'}}, {EXIT=> 1}],
+     ['check-openssl', '--check', {IN=> {'f.md5' => "MD5(f)= 
$sha_degenerate\n"}},
+                        {AUX=> {f=> ''}},
+                        {ERR=>"sha1sum: f.md5: no properly formatted "
+                          . "SHA1 checksum lines found\n"},
+                        {EXIT=> 1}],
+     ['check-openssl2', '--check',
+                        {IN=> {'f.sha1' => "SHA1(f)= $sha_degenerate\n"}},
+                        {AUX=> {f=> ''}}, {OUT=>"f: OK\n"}],
+     ['check-openssl3', '--check', '--status',
+                        {IN=> {'f.sha1' => "SHA1(f)= $sha_degenerate\n"}},
+                        {AUX=> {f=> 'bar'}}, {EXIT=> 1}],
      ['bsd-segv', '--check', {IN=> {'z' => "SHA1 ("}}, {EXIT=> 1},
       {ERR=> "$prog: z: no properly formatted SHA1 checksum lines found\n"}],
     );
-- 
1.6.0.2

Reply via email to