diff options
-rw-r--r-- | Doc/library/hashlib.rst | 9 | ||||
-rw-r--r-- | Lib/hashlib.py | 4 | ||||
-rw-r--r-- | Lib/test/test_hashlib.py | 5 |
3 files changed, 17 insertions, 1 deletions
diff --git a/Doc/library/hashlib.rst b/Doc/library/hashlib.rst index a776df1..3c98af7 100644 --- a/Doc/library/hashlib.rst +++ b/Doc/library/hashlib.rst @@ -82,6 +82,15 @@ Using :func:`new` with an algorithm provided by OpenSSL: >>> h.hexdigest() 'cc4a5ce1b3df48aec5d22d1f16b894a0b894eccc' +This module provides the following constant attribute: + +.. data:: hashlib.algorithms + + A tuple providing the names of the hash algorithms guaranteed to be + supported by this module. + + .. versionadded:: 3.2 + The following values are provided as constant attributes of the hash objects returned by the constructors: diff --git a/Lib/hashlib.py b/Lib/hashlib.py index 9709cde..aacb268 100644 --- a/Lib/hashlib.py +++ b/Lib/hashlib.py @@ -57,7 +57,9 @@ More condensed: # always available algorithm is added. __always_supported = ('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512') -__all__ = __always_supported + ('new',) +algorithms = __always_supported + +__all__ = __always_supported + ('new', 'algorithms') def __get_builtin_constructor(name): diff --git a/Lib/test/test_hashlib.py b/Lib/test/test_hashlib.py index 7d58da9..e1a1bd3 100644 --- a/Lib/test/test_hashlib.py +++ b/Lib/test/test_hashlib.py @@ -102,6 +102,11 @@ class HashLibTestCase(unittest.TestCase): c = cons(a) c.hexdigest() + def test_algorithms_attribute(self): + self.assertEqual(hashlib.algorithms, + tuple(_algo for _algo in self.supported_hash_names + if _algo.islower())) + def test_unknown_hash(self): try: hashlib.new('spam spam spam spam spam') |