[issue18742] Abstract base class for hashlib

2013-11-17 Thread Christian Heimes

Christian Heimes added the comment:

Raymond: Good idea!

to all: Do we need more discussion about the ABC, e.g. on the pycrypto mailing 
list?

--

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



[issue18742] Abstract base class for hashlib

2013-11-17 Thread Antoine Pitrou

Antoine Pitrou added the comment:

Some comments:
- AbstractCryptoHashFunction should be called CryptoHashBase or something (but 
does it warrant being public? I don't think so)
- having Function in a class name is a bit confusing to me. Why not simply 
CryptoHash?
- you don't need to add a __slots__ to your ABCs, IMO
- the default hexdigest() implementation looks a bit suboptimal to me, why not 
use binascii?

--

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



[issue18742] Abstract base class for hashlib

2013-11-17 Thread Christian Heimes

Christian Heimes added the comment:

* Cryptographic Hash Function is the correct technical term for algorithms 
like SHA-1. http://en.wikipedia.org/wiki/Cryptographic_hash_function

* PEP 452 is going to suggest that 3rd party libraries register their hash 
function as subclasses of the ABC.

* __slots__ are required for subclassing. All our ABCs in Python 3.x have 
__slots__

* I don't want to import yet another module just for the ABC. I'd rather not 
provide a sample implementation of hexdigest() if you think it is too slow.

--

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



[issue18742] Abstract base class for hashlib

2013-11-17 Thread Antoine Pitrou

Antoine Pitrou added the comment:

 * Cryptographic Hash Function is the correct technical term for
 algorithms like SHA-1.

Sure, but in a programming context, it's confusing when the function
is implemented by a class with additional properties and methods.
Why not simply CryptoHash? It sounds descriptive enough to me.

 * I don't want to import yet another module just for the ABC. I'd
 rather not provide a sample implementation of hexdigest() if you think
 it is too slow.

Well, it's probably not excruciatingly slow, so if you don't want
another import, I guess the current implementation is ok :)

--

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



[issue18742] Abstract base class for hashlib

2013-11-17 Thread Christian Heimes

Christian Heimes added the comment:

It seems the name of the ABC needs more discussion. I'll address it in PEP 452 
for Python 3.5.

--
versions: +Python 3.5 -Python 3.4

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



[issue18742] Abstract base class for hashlib

2013-10-22 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 72d7b2185771 by Christian Heimes in branch 'default':
Issue #18742: Rework the internal hashlib construtor to pave the road for ABCs.
http://hg.python.org/cpython/rev/72d7b2185771

--
nosy: +python-dev

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



[issue18742] Abstract base class for hashlib

2013-10-22 Thread Roundup Robot

Roundup Robot added the comment:

New changeset 27da6e790c41 by Christian Heimes in branch 'default':
Issue #18742: Expose the internal hash type object for ABCs.
http://hg.python.org/cpython/rev/27da6e790c41

--

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



[issue18742] Abstract base class for hashlib

2013-10-22 Thread Christian Heimes

Christian Heimes added the comment:

I have checked in some of the basic and non-controversal parts of the PEP 
(optimization, expose type object). The ABCs are still missing. In order to 
cope with keyed and non-keyed CHF I have added a common base class for both and 
separate ABCs for keyed and non-keyed CHF. They are really different beasts but 
they provide a common API except for they constructor.

class AbstractCryptoHashFunction(metaclass=_abc.ABCMeta):
Common ABC for keyed and non-keyed cryptographic hash functions

class CryptoHashFunction(AbstractCryptoHashFunction):
Abstract base class for cryptographic hash functions (PEP 247)

class KeyedCryptoHashFunction(AbstractCryptoHashFunction):
Abstract base class for keyed cryptographic hashs function (PEP 247)

--
Added file: http://bugs.python.org/file32302/hashlib_abc4.patch

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



[issue18742] Abstract base class for hashlib

2013-10-22 Thread Gregory P. Smith

Gregory P. Smith added the comment:


 Have you had a chance to read http://www.python.org/dev/peps/pep-0452/ ,
too?

Overall pep 452 looks good but one thing popped out at me:

 import hashlib
 from Crypto.Hash import MD5
 m = MD5.new()
 isinstance(m, hashlib.CryptoHash)
True

This suggests that there is an ABC hashlib.CryptoHash that non hashlib
implementations sound use but that is not spelled out anywhere as required
or recommended for third party hash implementations or why using it is a
good thing. I believe that is what you want to do with the ABC being
defined in this issue so I'd mention that explicitly in the pep.

--

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



[issue18742] Abstract base class for hashlib

2013-10-22 Thread Raymond Hettinger

Raymond Hettinger added the comment:

Consider inheriting from abc.ABC rather than specifying metaclass=abc.ABCMeta

--
nosy: +rhettinger

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



[issue18742] Abstract base class for hashlib

2013-10-21 Thread Christian Heimes

Christian Heimes added the comment:

I'm going to add CryptoKeyedHash ABC and register hmac as keyed hash algorithm, 
too.

--

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



[issue18742] Abstract base class for hashlib

2013-08-18 Thread Christian Heimes

Christian Heimes added the comment:

Thanks Gregory!

Have you had a chance to read http://www.python.org/dev/peps/pep-0452/ , too?

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18742
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18742] Abstract base class for hashlib

2013-08-15 Thread Christian Heimes

Christian Heimes added the comment:

Updated patch.

I'm going to add documentation when everybody is happy with the patch.

--
nosy: +pitrou
Added file: http://bugs.python.org/file31302/hashlib_abc2.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18742
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18742] Abstract base class for hashlib

2013-08-15 Thread Christian Heimes

Christian Heimes added the comment:

Now with block_size

--
Added file: http://bugs.python.org/file31308/hashlib_abc3.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18742
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18742] Abstract base class for hashlib

2013-08-15 Thread Christian Heimes

Changes by Christian Heimes li...@cheimes.de:


Removed file: http://bugs.python.org/file31295/hashlib_abc.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18742
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18742] Abstract base class for hashlib

2013-08-15 Thread Christian Heimes

Changes by Christian Heimes li...@cheimes.de:


Removed file: http://bugs.python.org/file31302/hashlib_abc2.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18742
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18742] Abstract base class for hashlib

2013-08-15 Thread Gregory P. Smith

Gregory P. Smith added the comment:

your patch makes sense to me.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18742
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue18742] Abstract base class for hashlib

2013-08-14 Thread Christian Heimes

New submission from Christian Heimes:

All hashlib types provide a common interfaces but there is no common super 
class. The patch implements provides hashlib.CryptoHash abstract base class as 
common virtual class for all hash types.

The patch also exposes all internal types of the internal hash C modules so I 
don't have to jump throw the type(constructor()) hoop.

I have also changed __get_builtin_constructor() to use a lookup cache instead 
of importing the module every time. It is necessary to avoid multiple calls to 
CryptoHash.register().

--
files: hashlib_abc.patch
keywords: patch
messages: 195226
nosy: christian.heimes, gregory.p.smith
priority: normal
severity: normal
stage: patch review
status: open
title: Abstract base class for hashlib
type: enhancement
versions: Python 3.4
Added file: http://bugs.python.org/file31295/hashlib_abc.patch

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue18742
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com