Skip to content

Commit

Permalink
detect pycryptodome, don't use it
Browse files Browse the repository at this point in the history
fixes #198

backport of e92ba72 from master
  • Loading branch information
tomato42 committed Oct 1, 2020
1 parent 719628a commit ab09210
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .travis.yml
Expand Up @@ -55,6 +55,10 @@ matrix:
env: PYCRYPTO=true
- python: 3.7-dev
env: PYCRYPTO=true
- python: 3.7
dist: xenial
sudo: true
env: PYCRYPTODOME=true
- python: 2.7
env: GMPY=true
- python: 3.4
Expand Down Expand Up @@ -99,6 +103,7 @@ install:
- if [[ $TACKPY == 'true' ]]; then travis_retry pip install tackpy; fi
- if [[ $M2CRYPTO == 'true' ]]; then travis_retry pip install --pre m2crypto; fi
- if [[ $PYCRYPTO == 'true' ]]; then travis_retry pip install pycrypto; fi
- if [[ $PYCRYPTODOME == 'true' ]]; then travis_retry pip install pycryptodome; fi
- if [[ $GMPY == 'true' ]]; then travis_retry pip install gmpy; fi
- travis_retry pip install -r requirements.txt

Expand Down
11 changes: 10 additions & 1 deletion tlslite/utils/cryptomath.py
Expand Up @@ -46,11 +46,20 @@
gmpyLoaded = False

#Try to load pycrypto
# pylint: disable=invalid-name
try:
import Crypto.Cipher.AES
pycryptoLoaded = True
# check if we're not using pycryptodome
try:
# pycrypto defaults to ECB when just key is provided
# pycryptodome requires specifying the mode of operation
Crypto.Cipher.AES.AESCipher(b'2' * (128//8))
pycryptoLoaded = True
except AttributeError:
pycryptoLoaded = False
except ImportError:
pycryptoLoaded = False
# pylint: enable=invalid-name


# **************************************************************************
Expand Down

0 comments on commit ab09210

Please sign in to comment.