(self, *args, **kwargs)
| 129 | return None |
| 130 | |
| 131 | def __init__(self, *args, **kwargs): |
| 132 | algorithms = set() |
| 133 | for algorithm in self.supported_hash_names: |
| 134 | algorithms.add(algorithm.lower()) |
| 135 | |
| 136 | _blake2 = self._conditional_import_module('_blake2') |
| 137 | blake2_hashes = {'blake2b', 'blake2s'} |
| 138 | if _blake2: |
| 139 | algorithms.update(blake2_hashes) |
| 140 | else: |
| 141 | algorithms.difference_update(blake2_hashes) |
| 142 | |
| 143 | self.constructors_to_test = {} |
| 144 | for algorithm in algorithms: |
| 145 | self.constructors_to_test[algorithm] = set() |
| 146 | |
| 147 | # For each algorithm, test the direct constructor and the use |
| 148 | # of hashlib.new given the algorithm name. |
| 149 | for algorithm, constructors in self.constructors_to_test.items(): |
| 150 | constructors.add(getattr(hashlib, algorithm)) |
| 151 | def c(*args, __algorithm_name=algorithm, **kwargs): |
| 152 | return hashlib.new(__algorithm_name, *args, **kwargs) |
| 153 | c.__name__ = f'do_test_algorithm_via_hashlib_new_{algorithm}' |
| 154 | constructors.add(c) |
| 155 | |
| 156 | _hashlib = self._conditional_import_module('_hashlib') |
| 157 | self._hashlib = _hashlib |
| 158 | if _hashlib: |
| 159 | # These algorithms should always be present when this module |
| 160 | # is compiled. If not, something was compiled wrong. |
| 161 | self.assertHasAttr(_hashlib, 'openssl_md5') |
| 162 | self.assertHasAttr(_hashlib, 'openssl_sha1') |
| 163 | for algorithm, constructors in self.constructors_to_test.items(): |
| 164 | constructor = getattr(_hashlib, 'openssl_'+algorithm, None) |
| 165 | if constructor: |
| 166 | try: |
| 167 | constructor() |
| 168 | except ValueError: |
| 169 | # default constructor blocked by crypto policy |
| 170 | pass |
| 171 | else: |
| 172 | constructors.add(constructor) |
| 173 | |
| 174 | def add_builtin_constructor(name): |
| 175 | constructor = getattr(hashlib, "__get_builtin_constructor")(name) |
| 176 | self.constructors_to_test[name].add(constructor) |
| 177 | |
| 178 | _md5 = self._conditional_import_module('_md5') |
| 179 | if _md5: |
| 180 | add_builtin_constructor('md5') |
| 181 | _sha1 = self._conditional_import_module('_sha1') |
| 182 | if _sha1: |
| 183 | add_builtin_constructor('sha1') |
| 184 | _sha2 = self._conditional_import_module('_sha2') |
| 185 | if _sha2: |
| 186 | add_builtin_constructor('sha224') |
| 187 | add_builtin_constructor('sha256') |
| 188 | add_builtin_constructor('sha384') |
nothing calls this directly
no test coverage detected