Check availability of _hashlib.openssl_ (**kwargs). The constructor function is returned (without binding **kwargs), or SkipTest is raised if none exists.
(digestname, /, **kwargs)
| 663 | |
| 664 | |
| 665 | def _openssl_hash(digestname, /, **kwargs): |
| 666 | """Check availability of _hashlib.openssl_<digestname>(**kwargs). |
| 667 | |
| 668 | The constructor function is returned (without binding **kwargs), |
| 669 | or SkipTest is raised if none exists. |
| 670 | """ |
| 671 | assert isinstance(digestname, str), digestname |
| 672 | method_name = f"openssl_{digestname}" |
| 673 | fullname = f"_hashlib.{method_name}" |
| 674 | try: |
| 675 | # re-import '_hashlib' in case it was mocked |
| 676 | _hashlib = importlib.import_module("_hashlib") |
| 677 | except ImportError as exc: |
| 678 | raise SkipNoHash(fullname, "openssl") from exc |
| 679 | try: |
| 680 | constructor = getattr(_hashlib, method_name) |
| 681 | except AttributeError as exc: |
| 682 | raise SkipNoHash(fullname, "openssl") from exc |
| 683 | try: |
| 684 | constructor(**kwargs) |
| 685 | except ValueError as exc: |
| 686 | raise SkipNoHash(fullname, "openssl") from exc |
| 687 | return constructor |
| 688 | |
| 689 | |
| 690 | def requires_hashdigest(digestname, openssl=None, *, usedforsecurity=True): |
no test coverage detected
searching dependent graphs…