utils.py 821 B

12345678910111213141516171819202122232425262728
  1. # This file is dual licensed under the terms of the Apache License, Version
  2. # 2.0, and the BSD License. See the LICENSE file in the root of this repository
  3. # for complete details.
  4. from __future__ import annotations
  5. from cryptography.hazmat.bindings._rust import asn1
  6. from cryptography.hazmat.primitives import hashes
  7. decode_dss_signature = asn1.decode_dss_signature
  8. encode_dss_signature = asn1.encode_dss_signature
  9. class NoDigestInfo:
  10. pass
  11. class Prehashed:
  12. def __init__(self, algorithm: hashes.HashAlgorithm):
  13. if not isinstance(algorithm, hashes.HashAlgorithm):
  14. raise TypeError("Expected instance of HashAlgorithm.")
  15. self._algorithm = algorithm
  16. self._digest_size = algorithm.digest_size
  17. @property
  18. def digest_size(self) -> int:
  19. return self._digest_size