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
This commit is contained in:
@@ -49,11 +49,7 @@ def normalize_before_encryption(unencrypted, content_type, content_encoding,
|
|||||||
# Process plain-text type.
|
# Process plain-text type.
|
||||||
if normalized_media_type in mime_types.PLAIN_TEXT:
|
if normalized_media_type in mime_types.PLAIN_TEXT:
|
||||||
# normalize text to binary and then base64 encode it
|
# normalize text to binary and then base64 encode it
|
||||||
if six.PY3:
|
b64payload = base64.encode_as_bytes(unencrypted)
|
||||||
b64payload = base64.encode_as_bytes(unencrypted)
|
|
||||||
else:
|
|
||||||
unencrypted_bytes = unencrypted.encode('utf-8')
|
|
||||||
b64payload = base64.encode_as_bytes(unencrypted_bytes)
|
|
||||||
|
|
||||||
# Process binary type.
|
# Process binary type.
|
||||||
else:
|
else:
|
||||||
|
|||||||
@@ -24,9 +24,6 @@ from barbican.plugin.crypto import p11_crypto
|
|||||||
from barbican.plugin.crypto import pkcs11
|
from barbican.plugin.crypto import pkcs11
|
||||||
from barbican.tests import utils
|
from barbican.tests import utils
|
||||||
|
|
||||||
if six.PY3:
|
|
||||||
long = int
|
|
||||||
|
|
||||||
|
|
||||||
def generate_random_effect(length, session):
|
def generate_random_effect(length, session):
|
||||||
return b'0' * length
|
return b'0' * length
|
||||||
@@ -38,15 +35,15 @@ class WhenTestingP11CryptoPlugin(utils.BaseTestCase):
|
|||||||
super(WhenTestingP11CryptoPlugin, self).setUp()
|
super(WhenTestingP11CryptoPlugin, self).setUp()
|
||||||
|
|
||||||
self.pkcs11 = mock.Mock()
|
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.return_session.return_value = None
|
||||||
self.pkcs11.generate_random.side_effect = generate_random_effect
|
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.encrypt.return_value = {'iv': b'0', 'ct': b'0'}
|
||||||
self.pkcs11.decrypt.return_value = 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.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.compute_hmac.return_value = b'1'
|
||||||
self.pkcs11.verify_hmac.return_value = None
|
self.pkcs11.verify_hmac.return_value = None
|
||||||
self.pkcs11.destroy_object.return_value = None
|
self.pkcs11.destroy_object.return_value = None
|
||||||
|
|||||||
@@ -13,15 +13,11 @@
|
|||||||
|
|
||||||
from unittest import mock
|
from unittest import mock
|
||||||
|
|
||||||
import six
|
|
||||||
|
|
||||||
from barbican.common import exception
|
from barbican.common import exception
|
||||||
from barbican.plugin.crypto import pkcs11
|
from barbican.plugin.crypto import pkcs11
|
||||||
from barbican.tests import utils
|
from barbican.tests import utils
|
||||||
|
|
||||||
if six.PY3:
|
|
||||||
long = int
|
|
||||||
|
|
||||||
|
|
||||||
class WhenTestingPKCS11(utils.BaseTestCase):
|
class WhenTestingPKCS11(utils.BaseTestCase):
|
||||||
|
|
||||||
@@ -90,16 +86,16 @@ class WhenTestingPKCS11(utils.BaseTestCase):
|
|||||||
return pkcs11.CKR_OK
|
return pkcs11.CKR_OK
|
||||||
|
|
||||||
def _open_session(self, *args, **kwargs):
|
def _open_session(self, *args, **kwargs):
|
||||||
args[4][0] = long(1)
|
args[4][0] = int(1)
|
||||||
return pkcs11.CKR_OK
|
return pkcs11.CKR_OK
|
||||||
|
|
||||||
def _find_objects_one(self, session, obj_handle_ptr, max_count, count):
|
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
|
count[0] = 1
|
||||||
return pkcs11.CKR_OK
|
return pkcs11.CKR_OK
|
||||||
|
|
||||||
def _find_objects_two(self, session, obj_handle_ptr, max_count, count):
|
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
|
count[0] = 2
|
||||||
return pkcs11.CKR_OK
|
return pkcs11.CKR_OK
|
||||||
|
|
||||||
@@ -109,7 +105,7 @@ class WhenTestingPKCS11(utils.BaseTestCase):
|
|||||||
|
|
||||||
def _generate_key(self, session, mech, attributes, attributes_len,
|
def _generate_key(self, session, mech, attributes, attributes_len,
|
||||||
obj_handle_ptr):
|
obj_handle_ptr):
|
||||||
obj_handle_ptr[0] = long(3)
|
obj_handle_ptr[0] = int(3)
|
||||||
return pkcs11.CKR_OK
|
return pkcs11.CKR_OK
|
||||||
|
|
||||||
def _encrypt(self, session, pt, pt_len, ct, ct_len):
|
def _encrypt(self, session, pt, pt_len, ct, ct_len):
|
||||||
@@ -128,14 +124,14 @@ class WhenTestingPKCS11(utils.BaseTestCase):
|
|||||||
def _wrap_key(self, *args, **kwargs):
|
def _wrap_key(self, *args, **kwargs):
|
||||||
wrapped_key = args[4]
|
wrapped_key = args[4]
|
||||||
wrapped_key_len = args[5]
|
wrapped_key_len = args[5]
|
||||||
wrapped_key_len[0] = long(16)
|
wrapped_key_len[0] = int(16)
|
||||||
if wrapped_key != self.ffi.NULL:
|
if wrapped_key != self.ffi.NULL:
|
||||||
self.ffi.buffer(wrapped_key)[:] = b'0' * 16
|
self.ffi.buffer(wrapped_key)[:] = b'0' * 16
|
||||||
return pkcs11.CKR_OK
|
return pkcs11.CKR_OK
|
||||||
|
|
||||||
def _unwrap_key(self, *args, **kwargs):
|
def _unwrap_key(self, *args, **kwargs):
|
||||||
unwrapped_key = args[7]
|
unwrapped_key = args[7]
|
||||||
unwrapped_key[0] = long(1)
|
unwrapped_key[0] = int(1)
|
||||||
return pkcs11.CKR_OK
|
return pkcs11.CKR_OK
|
||||||
|
|
||||||
def _sign(self, *args, **kwargs):
|
def _sign(self, *args, **kwargs):
|
||||||
|
|||||||
Reference in New Issue
Block a user