Browse Source

Fix enabled encrypt option on startup under py3.

Fix py3/2 compatibility with encrypt().
Add unit test for helpers.encrypt.
tags/release_0.21.48^2
Prinz23 5 years ago
committed by JackDandy
parent
commit
29ae6b382b
  1. 3
      CHANGES.md
  2. 8
      lib/sg_helpers.py
  3. 11
      sickbeard/helpers.py
  4. 9
      tests/helpers_tests.py

3
CHANGES.md

@ -1,6 +1,7 @@
### 0.21.48 (2020-09-xx xx:xx:00 UTC)
### 0.21.48 (2020-09-18 21:00:00 UTC)
* Change typo on search_episode_subtitles when subtitles are disabled
* Fix enabled encrypt option on startup under py3
### 0.21.47 (2020-09-17 16:10:00 UTC)

8
lib/sg_helpers.py

@ -76,6 +76,14 @@ PROXY_SETTING = None
NOTIFIERS = None
# try to convert to int, if the value is not already int
def try_ord(c):
# type: (Union[int, chr]) -> int
if isinstance(c, int):
return c
return ord(c)
# try to convert to int, if it fails the default will be returned
def try_int(s, s_default=0):
try:

11
sickbeard/helpers.py

@ -53,7 +53,7 @@ import subliminal
from lxml_etree import etree, is_lxml
from send2trash import send2trash
from _23 import b64decodebytes, b64encodebytes, decode_bytes, DirEntry, filter_iter, filter_list, scandir
from _23 import b64decodebytes, b64encodebytes, decode_bytes, decode_str, DirEntry, filter_iter, filter_list, scandir
from six import iteritems, PY2, string_types, text_type
# noinspection PyUnresolvedReferences
from six.moves import zip
@ -62,7 +62,7 @@ from six.moves import zip
# therefore, they intentionally don't resolve and are unused in this particular file.
# noinspection PyUnresolvedReferences
from sg_helpers import chmod_as_parent, clean_data, get_system_temp_dir, \
get_url, make_dirs, proxy_setting, remove_file_failed, try_int, write_file
get_url, make_dirs, proxy_setting, remove_file_failed, try_int, try_ord, write_file
# noinspection PyUnreachableCode
if False:
@ -1084,10 +1084,11 @@ def encrypt(data, encryption_version=0, do_decrypt=False):
# Version 1: Simple XOR encryption (this is not very secure, but works)
if 1 == encryption_version:
if do_decrypt:
return ''.join([chr(ord(x) ^ ord(y)) for (x, y) in zip(b64decodebytes(data), cycle(unique_key1))])
return ''.join([chr(try_ord(x) ^ try_ord(y)) for (x, y) in
zip(b64decodebytes(decode_bytes(data)), cycle(unique_key1))])
return b64encodebytes(
''.join([chr(ord(x) ^ ord(y)) for (x, y) in zip(data, cycle(unique_key1))])).strip()
return decode_str(b64encodebytes(decode_bytes(
''.join([chr(try_ord(x) ^ try_ord(y)) for (x, y) in zip(data, cycle(unique_key1))])))).strip()
# Version 0: Plain text
return data

9
tests/helpers_tests.py

@ -59,6 +59,15 @@ class HelpersTests(unittest.TestCase):
for c, b in test_cases:
self.assertEqual(helpers.should_delete_episode(Quality.compositeStatus(*c)), b)
def test_encrypt(self):
crypt_test = [
{'param': ('Test', 0, False), 'result': 'Test'},
{'param': ('Test', 1, False), 'result': 'ZB0QFQ=='},
{'param': ('ZB0QFQ==', 1, True), 'result': 'Test'},
]
for t in crypt_test:
self.assertEqual(t['result'], helpers.encrypt(*t['param']))
if '__main__' == __name__:
suite = unittest.TestLoader().loadTestsFromTestCase(HelpersTests)

Loading…
Cancel
Save