[issue27925] Nicer interface to convert hashlib digests to int

2016-09-01 Thread Serhiy Storchaka

Serhiy Storchaka added the comment:

There is another way:

int.from_bytes(x.digest(), 'big')

Note that converting to int you lose the length of the digest. md5 digest 
d41d8cd98f00b204e9800998ecf8427e and sha1 digest 
d41d8cd98f00b204e9800998ecf8427e are converted to the same int. This 
can add a vulnerability.

--
nosy: +serhiy.storchaka

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27925] Nicer interface to convert hashlib digests to int

2016-09-01 Thread Raymond Hettinger

Raymond Hettinger added the comment:

"int(x)" looks nice to me as well.

--
nosy: +rhettinger

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27925] Nicer interface to convert hashlib digests to int

2016-09-01 Thread R. David Murray

R. David Murray added the comment:

+1  I just wanted this recently.  Also note that going through hexdigest/int 
isn't particularly efficient, so an object-supported fast way to do this would 
be nice.

--
nosy: +r.david.murray
stage:  -> needs patch

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue27925] Nicer interface to convert hashlib digests to int

2016-09-01 Thread Steven D'Aprano

New submission from Steven D'Aprano:

hashlib digests should have a nicer interface to allow conversion to ints.

Currently we write int(x.hexdigest(), 16) which is less than obvious and easy 
to get wrong. It would be nice to be able to just say int(x) (that's my strong 
preference) or x.as_int().

Use-case: sometimes we need to store hashes in a database table which, for 
historical reasons, is an integer.

--
messages: 274102
nosy: steven.daprano
priority: normal
severity: normal
status: open
title: Nicer interface to convert hashlib digests to int
type: enhancement

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com