Re: [FEATURE_REQUEST] support openssl checksum format too

2009-10-07 Thread Guenter Knauf
Hi Jim,
Jim Meyering schrieb:
> Guenter Knauf wrote:
>> was still something wrong with my last patch?
> 
> Just the timing ;-)
> It was a little too close to release time,
> and applying it, adjusting NEWS and the commit log,
> reviewing, and testing would have taken time I didn't have.
no prob.

> And the fact that you haven't filed copyright assignment paperwork.
> Your change is under the 10-15-line threshold if we look only at the
> changes to md5sum.c, yet over if we also count the added tests.
> I've applied the patch, but would appreciate it if you'd start
> the process:
aah, please not! That paperwork is really not worth at all for such a
trivial change. Dont count the tests - they are not copyright-able :)
Anyway the patch is entirely based on your suggestions, and no new code
was introduced. Claiming a copyright for skipping one space char is a
little bit crazy, isnt it? Even the idea for it is only a logical
conclusion if you just compare the different checksum tools, nothing more.

** I post here on a public list that I donate any rights on this trivial
change to the FSF, and that it was entirely my own idea, and that I am
an independent developer, and not connected to any company. **

I only looked into the patch to speed up the process of getting this
into coreutils, and to the benefit of all users.

thanks, Gün.






Re: [FEATURE_REQUEST] support openssl checksum format too

2009-10-06 Thread Guenter Knauf
Hi Jim,
was still something wrong with my last patch?

Günter.







Re: [FEATURE_REQUEST] support openssl checksum format too

2009-10-03 Thread Guenter Knauf
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 
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\

Re: [FEATURE_REQUEST] support openssl checksum format too

2009-10-03 Thread Guenter Knauf
Jim,
thanks for the very quick review.

Jim Meyering schrieb:
> Guenter Knauf wrote:
>> -  size_t i;
>> +  size_t i = 0;
>>bool escaped_filename = false;
>>size_t algo_name_len;
>>
>> -  i = 0;
>>while (ISWHITE (s[i]))
>>  ++i;
> 
> Instead, please move the declaration "down".
hmm, not sure what you mean here - moving it down is bad since var
declarations in the middle of the code are not allowed, although
accepted by gcc. In this case its no problem, but if a while later
someone adds code before the declaration then it clashes with non-gcc
compilers. What's bad with initializing a var with the declaration?
That's valid for all compilers AFAIK. Anyway, since its not needed I
left this part out from my new patch - was just only a suggestion to
save a line.

> That allows two or more white-space bytes.
> Let's restrict it to just 0 or 1 space (not white-space) byte.
ok.

>> +  if (strncmp (s + j, "(", 1) == 0)
> 
> This would be better as:
> 
>  if (s[j] == '(')
ok.

here's 2nd trial inline (and also attached) which looks even more simple
thanks to your comments:

--- src/md5sum.c.orig   2009-09-01 13:01:16.0 +0200
+++ src/md5sum.c2009-10-03 20:32:28.0 +0200
@@ -263,11 +263,13 @@
   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);
 }
 }

> And a test, please.
I guess you mean something like that (also attached)?

--- tests/misc/md5sum.orig  2009-09-01 13:01:16.0 +0200
+++ tests/misc/md5sum   2009-10-03 20:46:44.0 +0200
@@ -67,6 +67,16 @@
  ['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"}],

does this work for you? Sorry, but I've not yet figured out how I could
run these tests - a 'make tests' didnt work (therefore wrote above
blindly assumed)- can you please give me a quick hint before I read me
dead? Thanks. Once I know I create patches for the sha*sum tests too.
Also, is it possible to run single tests?

thanks, Günter.


--- src/md5sum.c.orig	2009-09-01 13:01:16.0 +0200
+++ src/md5sum.c	2009-10-03 20:32:28.0 +0200
@@ -263,11 +263,13 @@
   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);
 }
 }
--- tests/misc/md5sum.orig	2009-09-01 13:01:16.0 +0200
+++ tests/misc/md5sum	2009-10-03 20:46:44.0 +0200
@@ -67,6 +67,16 @@
  ['ch

Re: [FEATURE_REQUEST] support openssl checksum format too

2009-10-03 Thread Guenter Knauf
Hi Jim,
Jim Meyering schrieb:
> Would you like to write the patch (including NEWS and
> a small doc update), following these guidelines?
> 
>   http://git.sv.gnu.org/cgit/coreutils.git/plain/HACKING
I've just tested a bit, and it seems that its enough to hack around the
first place where the blank can appear (bsd tools) or not (openssl).
Since the patch is really small I would like to ask you for a review
without urging me to go through all the git stuff; if you accept the
simple patch then I will follow up with the docs / NEWS update.
I've tested this patch successfully with both bsd and openssl format.
The first hunk is not needed, but I thought while on it we can save
there a line 

thanks, Günter.

--- src/md5sum.c.orig   2009-09-01 13:01:16.0 +0200
+++ src/md5sum.c2009-10-03 19:13:27.0 +0200
@@ -251,11 +251,10 @@
 split_3 (char *s, size_t s_len,
  unsigned char **hex_digest, int *binary, char **file_name)
 {
-  size_t i;
+  size_t i = 0;
   bool escaped_filename = false;
   size_t algo_name_len;

-  i = 0;
   while (ISWHITE (s[i]))
 ++i;

@@ -263,11 +262,14 @@
   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)
+  size_t j = i + algo_name_len;
+  while (ISWHITE (s[j]))
+++j;
+
+  if (strncmp (s + j, "(", 1) == 0)
 {
   *binary = 0;
-  return bsd_split_3 (s +  i + algo_name_len + 2,
-  s_len - (i + algo_name_len + 2),
+  return bsd_split_3 (s + j + 1, s_len - (j + 1),
   hex_digest, file_name);
 }
 }
--- src/md5sum.c.orig	2009-09-01 13:01:16.0 +0200
+++ src/md5sum.c	2009-10-03 19:13:27.0 +0200
@@ -251,11 +251,10 @@
 split_3 (char *s, size_t s_len,
  unsigned char **hex_digest, int *binary, char **file_name)
 {
-  size_t i;
+  size_t i = 0;
   bool escaped_filename = false;
   size_t algo_name_len;
 
-  i = 0;
   while (ISWHITE (s[i]))
 ++i;
 
@@ -263,11 +262,14 @@
   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)
+  size_t j = i + algo_name_len;
+  while (ISWHITE (s[j]))
+++j;
+
+  if (strncmp (s + j, "(", 1) == 0)
 {
   *binary = 0;
-  return bsd_split_3 (s +  i + algo_name_len + 2,
-  s_len - (i + algo_name_len + 2),
+  return bsd_split_3 (s + j + 1, s_len - (j + 1),
   hex_digest, file_name);
 }
 }


Re: [FEATURE_REQUEST] support openssl checksum format too

2009-09-26 Thread Guenter Knauf
Hi Jim,
Jim Meyering schrieb:
> But it's even easier to convert openssl's format
> into one that is recognized.  Filter it through this:
> 
> sed 's/(/ (/;s/\(= [0-9a-f]*\)$/ \1/'
> 
> E.g.,
> 
> $ touch f; openssl md5 f
> MD5(f)= d41d8cd98f00b204e9800998ecf8427e
> $ openssl md5 f | sed 's/(/ (/;s/\(= [0-9a-f]*\)$/ \1/'
> MD5 (f) = d41d8cd98f00b204e9800998ecf8427e
> 
sure, I know that; but in the sense of user-friendly tools I (and most
likely many other users too) would really appreciate if md5sum / sha1sum
could support more of these other crappy formats as input ...
I've summarized what I've found so far about the different tools and
their output formats:
http://www.gknw.net/phpbb/viewtopic.php?t=570
personally md5sum / sha1sum are my preferred tools, but since I come
every now and then over other formats I've now hacked my Perl script
which automatically detects those crappy formats I get from other places
where I have no control about what I get.

thanks, Gün.






[FEATURE_REQUEST] support openssl checksum format too

2009-09-25 Thread Guenter Knauf
Hi all,
suprisingly I just found that md5sum and sha1sum also accept the formats
of the md5 and sha1 tools as input with option -c. There's though a
third checksum format which is produced by the openssl tool which only
slightly differs to the format from md5 and sha1 - two blanks are
missing ...
output of 'md5 file':
MD5 (httpd-2.2.14.tar.bz2) = a5226203aaf97e5b941c41a71c112704
output of 'openssl md5 file':
MD5(httpd-2.2.14.tar.bz2)= a5226203aaf97e5b941c41a71c112704
output of 'sha1 file':
SHA1 (httpd-2.2.14.tar.bz2) = eacd04c87b489231ae708c84a77dc8e9ee176fd2
output of 'openssl md5 file':
SHA1(httpd-2.2.14.tar.bz2)= eacd04c87b489231ae708c84a77dc8e9ee176fd2

I think that it cant be hard to make md5sum and sha1sum accept the
openssl format too.

thanks, Günter.