Cryptodome.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. from ..compat.compat_utils import passthrough_module
  2. try:
  3. import Cryptodome as _parent
  4. except ImportError:
  5. try:
  6. import Crypto as _parent
  7. except (ImportError, SyntaxError): # Old Crypto gives SyntaxError in newer Python
  8. _parent = passthrough_module(__name__, 'no_Cryptodome')
  9. __bool__ = lambda: False
  10. del passthrough_module
  11. __version__ = ''
  12. AES = PKCS1_v1_5 = Blowfish = PKCS1_OAEP = SHA1 = CMAC = RSA = None
  13. try:
  14. if _parent.__name__ == 'Cryptodome':
  15. from Cryptodome import __version__
  16. from Cryptodome.Cipher import AES, PKCS1_OAEP, Blowfish, PKCS1_v1_5
  17. from Cryptodome.Hash import CMAC, SHA1
  18. from Cryptodome.PublicKey import RSA
  19. elif _parent.__name__ == 'Crypto':
  20. from Crypto import __version__
  21. from Crypto.Cipher import AES, PKCS1_OAEP, Blowfish, PKCS1_v1_5 # noqa: F401
  22. from Crypto.Hash import CMAC, SHA1 # noqa: F401
  23. from Crypto.PublicKey import RSA # noqa: F401
  24. except ImportError:
  25. __version__ = f'broken {__version__}'.strip()
  26. _yt_dlp__identifier = _parent.__name__
  27. if AES and _yt_dlp__identifier == 'Crypto':
  28. try:
  29. # In pycrypto, mode defaults to ECB. See:
  30. # https://www.pycryptodome.org/en/latest/src/vs_pycrypto.html#:~:text=not%20have%20ECB%20as%20default%20mode
  31. AES.new(b'abcdefghijklmnop')
  32. except TypeError:
  33. _yt_dlp__identifier = 'pycrypto'