Skip to content

Change 'simplejson' import statement to 'json' #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 19 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 11 additions & 11 deletions encryptedpickle/encryptedpickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
from struct import pack, unpack
from collections import namedtuple

import simplejson as json
import json
from pbkdf2 import PBKDF2
from Crypto.Cipher import AES
from Crypto.Random import get_random_bytes
from Crypto.Hash import HMAC, SHA, SHA256, SHA384, SHA512
from Cryptodome.Cipher import AES
from Cryptodome.Random import get_random_bytes
from Cryptodome.Hash import HMAC, SHA, SHA256, SHA384, SHA512

from .utils import (
const_equal,
Expand Down Expand Up @@ -345,7 +345,7 @@ def _encode(self, data, algorithm, key=None):
'''Encode data with specific algorithm'''

if algorithm['type'] == 'hmac':
return data + self._hmac_generate(data, algorithm, key)
return data + str(self._hmac_generate(data, algorithm, key))
elif algorithm['type'] == 'aes':
return self._aes_encrypt(data, algorithm, key)
elif algorithm['type'] == 'no-serialization':
Expand Down Expand Up @@ -400,7 +400,7 @@ def _sign_data(self, data, options):

data = self._encode(data, algorithm, key)

return data + key_salt
return data + str(key_salt)

def _unsign_data(self, data, options):
'''Verify and remove signature'''
Expand Down Expand Up @@ -561,8 +561,8 @@ def _add_magic(self, data):
'''Add magic'''

if self.magic:
return self.magic + data

return self.magic + str(data)
return data

def _add_header(self, data, options):
Expand All @@ -575,7 +575,7 @@ def _add_header(self, data, options):
flags = options['flags']

header_flags = dict(
(i, str(int(j))) for i, j in options['flags'].iteritems())
(i, str(int(j))) for i, j in options['flags'].items())
header_flags = ''.join(version_info['flags'](**header_flags))
header_flags = int(header_flags, 2)
options['flags'] = header_flags
Expand Down Expand Up @@ -722,7 +722,7 @@ def _hmac_generate(data, algorithm, key):

digestmod = EncryptedPickle._get_hashlib(algorithm['subtype'])

return HMAC.new(key, data, digestmod).digest()
return HMAC.new(key, data.encode('utf-8'), digestmod).digest()

@staticmethod
def _aes_encrypt(data, algorithm, key):
Expand All @@ -749,7 +749,7 @@ def _aes_encrypt(data, algorithm, key):
numpad = block_size - (len(data) % block_size)
data = data + numpad * chr(numpad)

enc = AES.new(key, mode, iv_value).encrypt(data)
enc = AES.new(key, mode, iv_value).encrypt(data.encode('utf-8'))

if include_iv:
enc = iv_value + enc
Expand Down
6 changes: 4 additions & 2 deletions encryptedpickle/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,14 @@
from __future__ import absolute_import

from base64 import urlsafe_b64encode, urlsafe_b64decode
import warnings


def urlsafe_nopadding_b64encode(data):
'''URL safe Base64 encode without padding (=)'''

return urlsafe_b64encode(data).rstrip('=')

warnings.warn(type(data))
return urlsafe_b64encode(data.encode('utf-8')).rstrip('=')

def urlsafe_nopadding_b64decode(data):
'''URL safe Base64 decode without padding (=)'''
Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
pbkdf2>=1.3
pycrypto>=2.6
pycryptodomex>=3.9.8
simplejson