If Crypto can't be found, try to import Cryptodome

This commit is contained in:
Frédéric Perrin 2021-10-16 21:29:22 +01:00 committed by Florian Bach
parent 89dcaf75c1
commit aca0157004
2 changed files with 22 additions and 8 deletions

View File

@ -5,19 +5,26 @@
Helper library with code needed for Adobe stuff. Helper library with code needed for Adobe stuff.
''' '''
from Crypto import Random
from uuid import getnode from uuid import getnode
import os, hashlib, base64 import os, hashlib, base64
import urllib.request, ssl import urllib.request, ssl
from Crypto.Cipher import AES
from datetime import datetime, timedelta from datetime import datetime, timedelta
from lxml import etree from lxml import etree
import rsa import rsa
try:
from Crypto.PublicKey import RSA from Crypto import Random
from Crypto.Hash import SHA from Crypto.Cipher import AES
from Crypto.PublicKey import RSA
from Crypto.Hash import SHA
except ImportError:
# Debian (and Ubuntu) ship pycryptodome, but not in its compatible mode with pycrypto
# If `Crypto` can't be found, try under pycryptodome's own namespace
from Cryptodome import Random
from Cryptodome.Cipher import AES
from Cryptodome.PublicKey import RSA
from Cryptodome.Hash import SHA
from oscrypto import keys from oscrypto import keys
from oscrypto.asymmetric import dump_certificate, dump_private_key, dump_public_key from oscrypto.asymmetric import dump_certificate, dump_private_key, dump_public_key

View File

@ -2,9 +2,16 @@ from lxml import etree
import base64 import base64
import os, locale, platform import os, locale, platform
from Crypto.PublicKey import RSA try:
from Crypto.Util.asn1 import DerSequence from Crypto.PublicKey import RSA
from Crypto.Cipher import PKCS1_v1_5 from Crypto.Util.asn1 import DerSequence
from Crypto.Cipher import PKCS1_v1_5
except ImportError:
# Debian (and Ubuntu) ship pycryptodome, but not in its compatible mode with pycrypto
# If `Crypto` can't be found, try under pycryptodome's own namespace
from Cryptodome.PublicKey import RSA
from Cryptodome.Util.asn1 import DerSequence
from Cryptodome.Cipher import PKCS1_v1_5
try: try:
from libadobe import addNonce, sign_node, sendRequestDocu, sendHTTPRequest from libadobe import addNonce, sign_node, sendRequestDocu, sendHTTPRequest