From 25a56939ea87abb0195bd9e714084178765cf63b Mon Sep 17 00:00:00 2001 From: wangzihao Date: Tue, 22 Sep 2020 11:21:12 +0800 Subject: [PATCH] Remove six.PY3 The Python 2.7 Support has been dropped since Ussuri. So remove hacking rules for compatibility between python 2 and 3. Change-Id: I7f6331a74ad7a51c473ce28a9dd880db92b47d3c --- barbican/plugin/util/translations.py | 6 +----- barbican/tests/plugin/crypto/test_p11_crypto.py | 11 ++++------- barbican/tests/plugin/crypto/test_pkcs11.py | 16 ++++++---------- 3 files changed, 11 insertions(+), 22 deletions(-) diff --git a/barbican/plugin/util/translations.py b/barbican/plugin/util/translations.py index 447a2f266..23994a448 100644 --- a/barbican/plugin/util/translations.py +++ b/barbican/plugin/util/translations.py @@ -49,11 +49,7 @@ def normalize_before_encryption(unencrypted, content_type, content_encoding, # Process plain-text type. if normalized_media_type in mime_types.PLAIN_TEXT: # normalize text to binary and then base64 encode it - if six.PY3: - b64payload = base64.encode_as_bytes(unencrypted) - else: - unencrypted_bytes = unencrypted.encode('utf-8') - b64payload = base64.encode_as_bytes(unencrypted_bytes) + b64payload = base64.encode_as_bytes(unencrypted) # Process binary type. else: diff --git a/barbican/tests/plugin/crypto/test_p11_crypto.py b/barbican/tests/plugin/crypto/test_p11_crypto.py index 78ef5b9a5..afae19cc6 100644 --- a/barbican/tests/plugin/crypto/test_p11_crypto.py +++ b/barbican/tests/plugin/crypto/test_p11_crypto.py @@ -24,9 +24,6 @@ from barbican.plugin.crypto import p11_crypto from barbican.plugin.crypto import pkcs11 from barbican.tests import utils -if six.PY3: - long = int - def generate_random_effect(length, session): return b'0' * length @@ -38,15 +35,15 @@ class WhenTestingP11CryptoPlugin(utils.BaseTestCase): super(WhenTestingP11CryptoPlugin, self).setUp() self.pkcs11 = mock.Mock() - self.pkcs11.get_session.return_value = long(1) + self.pkcs11.get_session.return_value = int(1) self.pkcs11.return_session.return_value = None self.pkcs11.generate_random.side_effect = generate_random_effect - self.pkcs11.get_key_handle.return_value = long(2) + self.pkcs11.get_key_handle.return_value = int(2) self.pkcs11.encrypt.return_value = {'iv': b'0', 'ct': b'0'} self.pkcs11.decrypt.return_value = b'0' - self.pkcs11.generate_key.return_value = long(3) + self.pkcs11.generate_key.return_value = int(3) self.pkcs11.wrap_key.return_value = {'iv': b'1', 'wrapped_key': b'1'} - self.pkcs11.unwrap_key.return_value = long(4) + self.pkcs11.unwrap_key.return_value = int(4) self.pkcs11.compute_hmac.return_value = b'1' self.pkcs11.verify_hmac.return_value = None self.pkcs11.destroy_object.return_value = None diff --git a/barbican/tests/plugin/crypto/test_pkcs11.py b/barbican/tests/plugin/crypto/test_pkcs11.py index ab33eb48c..fbc01fbb3 100644 --- a/barbican/tests/plugin/crypto/test_pkcs11.py +++ b/barbican/tests/plugin/crypto/test_pkcs11.py @@ -13,15 +13,11 @@ from unittest import mock -import six from barbican.common import exception from barbican.plugin.crypto import pkcs11 from barbican.tests import utils -if six.PY3: - long = int - class WhenTestingPKCS11(utils.BaseTestCase): @@ -90,16 +86,16 @@ class WhenTestingPKCS11(utils.BaseTestCase): return pkcs11.CKR_OK def _open_session(self, *args, **kwargs): - args[4][0] = long(1) + args[4][0] = int(1) return pkcs11.CKR_OK def _find_objects_one(self, session, obj_handle_ptr, max_count, count): - obj_handle_ptr[0] = long(2) + obj_handle_ptr[0] = int(2) count[0] = 1 return pkcs11.CKR_OK def _find_objects_two(self, session, obj_handle_ptr, max_count, count): - obj_handle_ptr[0] = long(2) + obj_handle_ptr[0] = int(2) count[0] = 2 return pkcs11.CKR_OK @@ -109,7 +105,7 @@ class WhenTestingPKCS11(utils.BaseTestCase): def _generate_key(self, session, mech, attributes, attributes_len, obj_handle_ptr): - obj_handle_ptr[0] = long(3) + obj_handle_ptr[0] = int(3) return pkcs11.CKR_OK def _encrypt(self, session, pt, pt_len, ct, ct_len): @@ -128,14 +124,14 @@ class WhenTestingPKCS11(utils.BaseTestCase): def _wrap_key(self, *args, **kwargs): wrapped_key = args[4] wrapped_key_len = args[5] - wrapped_key_len[0] = long(16) + wrapped_key_len[0] = int(16) if wrapped_key != self.ffi.NULL: self.ffi.buffer(wrapped_key)[:] = b'0' * 16 return pkcs11.CKR_OK def _unwrap_key(self, *args, **kwargs): unwrapped_key = args[7] - unwrapped_key[0] = long(1) + unwrapped_key[0] = int(1) return pkcs11.CKR_OK def _sign(self, *args, **kwargs):