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