Skip to content

gh-135571: Guard _hashlib usage in test_hashlib.py #135572

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

WillChilds-Klein
Copy link
Contributor

@WillChilds-Klein WillChilds-Klein commented Jun 16, 2025

Comment on lines 277 to 279
# when using a combination of libcrypto and interned hash
# implementations, we need to make sure that _hashlib contains
# the constructor we're testing
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# when using a combination of libcrypto and interned hash
# implementations, we need to make sure that _hashlib contains
# the constructor we're testing
# Make sure that _hashlib contains the constructor
# to test when using a combination of libcrypto and
# interned hash implementations.

By "interned" hash implementations, do you mean HACL* implementations or others? because hash_constructors should actually only contain the the constructors that are "correct"?

Also, I think you can use _hashlib.algorithms_available instead of _constructors, but I don't remember well now. I'm leaving so I won't be able to review more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By "interned" hash implementations, do you mean HACL* implementations or others?

I'm not sure which are HACL and which are not, but by "interned" I mean all the hash functions that use source in CPython's tree for hash implementations instead of a linking to libcrypto.

because hash_constructors should actually only contain the the constructors that are "correct"

In PR #135402, I observed hash_constructors containing blake2b/blake2s constructors while _hashlib did not, causing failures when this test tried to invoke it.

Also, I think you can use _hashlib.algorithms_available instead of _constructors

Hm, I don't see an algorithms_available attr of _hashlib:

$ ./python
Python 3.15.0a0 (heads/add-awslc-ci-job-dirty:be1b72c13b2, Jun 12 2025, 15:30:29) [GCC 11.4.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>> ssl.OPENSSL_VERSION
'AWS-LC 1.52.1'
>>> import _hashlib
>>> dir(_hashlib)
['HASH', 'HASHXOF', 'HMAC', 'UnsupportedDigestmodError', '_GIL_MINSIZE', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_constructors', 'compare_digest', 'get_fips_mode', 'hmac_digest', 'hmac_new', 'new', 'openssl_md5', 'openssl_md_meth_names', 'openssl_sha1', 'openssl_sha224', 'openssl_sha256', 'openssl_sha384', 'openssl_sha3_224', 'openssl_sha3_256', 'openssl_sha3_384', 'openssl_sha3_512', 'openssl_sha512', 'openssl_shake_128', 'openssl_shake_256', 'pbkdf2_hmac', 'scrypt']
>>> _hashlib.algorithms_available
Traceback (most recent call last):
  File "<python-input-2>", line 1, in <module>
    _hashlib.algorithms_available
AttributeError: module '_hashlib' has no attribute 'algorithms_available'

@zware zware changed the title gh-135571: Guard _hahslib usage in test_hashlib.py gh-135571: Guard _hashlib usage in test_hashlib.py Jun 16, 2025
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
@WillChilds-Klein WillChilds-Klein requested a review from picnixz June 16, 2025 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting review skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants