gnulib-tool-py
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [gnulib-tool-py] Calculating md5sum


From: Bruno Haible
Subject: Re: [gnulib-tool-py] Calculating md5sum
Date: Fri, 29 Jun 2012 11:34:43 +0200
User-agent: KMail/4.7.4 (Linux/3.1.10-1.9-desktop; KDE/4.7.4; x86_64; ; )

Hi Dmitriy,

> today I've investigated the code and found that there are some places where
> we need to use md5sum. There is hashlib.md5 algorithm in Python, but it
> returns different value than Linux md5sum utility.
> 
> Python:
> >>> hashlib.md5(b'FILENAME').hexdigest()
> '496475a066afb2d2e50a4133b9822497'
> 
> Linux:
> $ echo FILENAME | md5sum
> f2320a63dfa06e5586a86d44fe8e12eb

As Jim points out, the difference is that 'echo FILENAME' emits a newline
after FILENAME. You can do the same in Python, then you get the same value:

>>> import hashlib
>>> hashlib.md5(b'FILENAME\n').hexdigest()
'f2320a63dfa06e5586a86d44fe8e12eb'

> Is it necessary how bad names are represented?

Yes, on August 20 I would like to be able to run the old gnulib-tool and
the new gnulib-tool with the same arguments and verify that they produce
the exact same output files.

But you can add a TODO that reminds us to remove the useless newline once
the migration to the Python gnulib-tool is finished.

Jim Meyering wrote:
>     $ printf FILENAME | md5sum
>     496475a066afb2d2e50a4133b9822497  -

I would rather use this command:

$ printf %s FILENAME | md5sum
496475a066afb2d2e50a4133b9822497  -

Just in case FILENAME contains a percent character...

> Thanks, that works! That's strange, in functions from old gnulib-tool we
> use echo (e.g. see func_uncond_add_module).

Nowadays we consider 'printf' to be portable. When gnulib-tool was written
initially, we didn't consider 'printf' as usable in a portable program,
that's why I used 'echo'.

> we can use hashlib module. That is very good news, because we can save time.

Yes, absolutely.

Bruno




reply via email to

[Prev in Thread] Current Thread [Next in Thread]