More Python2 fixes

This commit is contained in:
Florian Bach 2022-04-28 16:31:14 +02:00
parent 171c6f36ba
commit 5fe4dbb75a
4 changed files with 13 additions and 20 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
/calibre-plugin/keyextract/*.exe
/calibre-plugin/module_id.txt
/calibre-plugin/__pycache__
/calibre-plugin/*.pyc

View File

@ -8,9 +8,6 @@ This is an experimental Python version of libgourou.
# pyright: reportUndefinedVariable=false
import sys, os, time, shutil
if sys.version_info[0] < 3:
print("This script requires Python 3.")
exit(1)
import zipfile
from lxml import etree

View File

@ -7,10 +7,6 @@ This is an experimental Python version of libgourou.
import getpass, sys
if sys.version_info[0] < 3:
print("This script requires Python 3.")
exit(1)
from libadobe import createDeviceKeyFile, VAR_VER_SUPP_CONFIG_NAMES
from libadobeAccount import createDeviceFile, createUser, signIn, activateDevice
@ -32,9 +28,9 @@ def main():
if (VAR_MAIL == ""):
VAR_MAIL = input("Please enter your AdobeID: ")
VAR_MAIL = input("Please enter your AdobeID (or press enter for anonymous auth): ")
if (VAR_PASS == ""):
if (VAR_PASS == "" and VAR_MAIL != ""):
VAR_PASS = getpass.getpass("Please enter the password for your AdobeID: ")
if (VAR_VER is None):
@ -44,8 +40,8 @@ def main():
print("Invalid version")
exit(1)
if (VAR_MAIL == "" or VAR_PASS == ""):
print("Empty credential, aborting")
if (VAR_MAIL != "" and VAR_PASS == ""):
print("Empty password, aborting")
exit(1)
@ -61,7 +57,11 @@ def main():
print("Error, couldn't create user: %s" % resp)
exit(1)
success, resp = signIn("AdobeID", VAR_MAIL, VAR_PASS)
if VAR_MAIL == "":
success, resp = signIn("anonymous", "", "")
else:
success, resp = signIn("AdobeID", VAR_MAIL, VAR_PASS)
if (success is False):
print("Login unsuccessful: " + resp)
exit(1)

View File

@ -12,6 +12,7 @@ if sys.version_info[0] >= 3:
else:
from mock import patch
from lxml import etree
import binascii
try:
@ -187,10 +188,7 @@ class TestAdobe(unittest.TestCase):
key = rsa.PrivateKey.load_pkcs1(RSA.importKey(base64.b64decode(mock_signing_key)).exportKey())
keylen = rsa.pkcs1.common.byte_size(key.n)
if sys.version_info[0] >= 3:
padded = rsa.pkcs1._pad_for_signing(bytes(payload_bytes), keylen)
else:
padded = rsa.pkcs1._pad_for_signing(bytes(payload_bytes), keylen)
padded = rsa.pkcs1._pad_for_signing(bytes(payload_bytes), keylen)
payload = rsa.pkcs1.transform.bytes2int(padded)
encrypted = key.blinded_encrypt(payload)
block = rsa.pkcs1.transform.int2bytes(encrypted, keylen)
@ -310,10 +308,7 @@ class TestAdobe(unittest.TestCase):
expected_msg.extend(bytearray(struct.pack("B", len(passwd))))
expected_msg.extend(bytearray(passwd.encode("latin-1")))
if sys.version_info[0] >= 3:
self.assertEqual(msg.hex(), expected_msg.hex(), "devkey encryption returned invalid result")
else:
self.assertEqual(msg, expected_msg, "devkey encryption returned invalid result")
self.assertEqual(binascii.hexlify(msg), binascii.hexlify(expected_msg), "devkey encryption returned invalid result")