fixes pylint warnings

pull/1/head
Moisés Guimarães 2018-01-08 15:44:18 -03:00
parent f232680c54
commit 0a6147fc9d
3 changed files with 24 additions and 18 deletions

View File

@ -18,6 +18,8 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
# pylint: disable=no-member,no-name-in-module
from wolfcrypt._ffi import ffi as _ffi from wolfcrypt._ffi import ffi as _ffi
from wolfcrypt._ffi import lib as _lib from wolfcrypt._ffi import lib as _lib
from wolfcrypt.utils import t2b from wolfcrypt.utils import t2b
@ -63,7 +65,7 @@ class _Cipher(object):
if len(key) not in self._key_sizes: if len(key) not in self._key_sizes:
raise ValueError("key must be %s in length" % self._key_sizes) raise ValueError("key must be %s in length" % self._key_sizes)
else: else:
if not len(key): if not key:
raise ValueError("key must not be 0 in length") raise ValueError("key must not be 0 in length")
if IV is not None and len(IV) != self.block_size: if IV is not None and len(IV) != self.block_size:
@ -80,7 +82,7 @@ class _Cipher(object):
self._IV = _ffi.new('byte[%d]' % self.block_size) self._IV = _ffi.new('byte[%d]' % self.block_size)
@classmethod @classmethod
def new(cls, key, mode, IV=None, **kwargs): def new(cls, key, mode, IV=None, **kwargs): # pylint: disable=W0613
""" """
Returns a ciphering object, using the secret key contained in Returns a ciphering object, using the secret key contained in
the string **key**, and using the feedback mode **mode**, which the string **key**, and using the feedback mode **mode**, which
@ -162,9 +164,9 @@ class Aes(_Cipher):
if direction == _ENCRYPTION: if direction == _ENCRYPTION:
return _lib.wc_AesSetKey( return _lib.wc_AesSetKey(
self._enc, self._key, len(self._key), self._IV, _ENCRYPTION) self._enc, self._key, len(self._key), self._IV, _ENCRYPTION)
else:
return _lib.wc_AesSetKey( return _lib.wc_AesSetKey(
self._dec, self._key, len(self._key), self._IV, _DECRYPTION) self._dec, self._key, len(self._key), self._IV, _DECRYPTION)
def _encrypt(self, destination, source): def _encrypt(self, destination, source):
return _lib.wc_AesCbcEncrypt(self._enc, destination, return _lib.wc_AesCbcEncrypt(self._enc, destination,
@ -190,9 +192,9 @@ class Des3(_Cipher):
if direction == _ENCRYPTION: if direction == _ENCRYPTION:
return _lib.wc_Des3_SetKey(self._enc, self._key, return _lib.wc_Des3_SetKey(self._enc, self._key,
self._IV, _ENCRYPTION) self._IV, _ENCRYPTION)
else:
return _lib.wc_Des3_SetKey(self._dec, self._key, return _lib.wc_Des3_SetKey(self._dec, self._key,
self._IV, _DECRYPTION) self._IV, _DECRYPTION)
def _encrypt(self, destination, source): def _encrypt(self, destination, source):
return _lib.wc_Des3_CbcEncrypt(self._enc, destination, return _lib.wc_Des3_CbcEncrypt(self._enc, destination,
@ -203,7 +205,7 @@ class Des3(_Cipher):
source, len(source)) source, len(source))
class _Rsa(object): class _Rsa(object): # pylint: disable=too-few-public-methods
RSA_MIN_PAD_SIZE = 11 RSA_MIN_PAD_SIZE = 11
def __init__(self): def __init__(self):
@ -226,7 +228,7 @@ class RsaPublic(_Rsa):
def __init__(self, key): def __init__(self, key):
key = t2b(key) key = t2b(key)
_Rsa.__init__(self) super(RsaPublic, self).__init__()
idx = _ffi.new("word32*") idx = _ffi.new("word32*")
idx[0] = 0 idx[0] = 0
@ -289,7 +291,7 @@ class RsaPrivate(RsaPublic):
def __init__(self, key): def __init__(self, key):
key = t2b(key) key = t2b(key)
_Rsa.__init__(self) super(RsaPrivate, self).__init__()
idx = _ffi.new("word32*") idx = _ffi.new("word32*")
idx[0] = 0 idx[0] = 0

View File

@ -18,6 +18,8 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
# pylint: disable=no-member,no-name-in-module, no-self-use
from wolfcrypt._ffi import ffi as _ffi from wolfcrypt._ffi import ffi as _ffi
from wolfcrypt._ffi import lib as _lib from wolfcrypt._ffi import lib as _lib
from wolfcrypt.utils import t2b, b2h from wolfcrypt.utils import t2b, b2h
@ -36,7 +38,7 @@ class _Hash(object):
if ret < 0: if ret < 0:
raise WolfCryptError("Hash init error (%d)" % ret) raise WolfCryptError("Hash init error (%d)" % ret)
if (string): if string:
self.update(string) self.update(string)
@classmethod @classmethod
@ -56,7 +58,7 @@ class _Hash(object):
""" """
copy = self.new("") copy = self.new("")
_ffi.memmove(copy._native_object, _ffi.memmove(copy._native_object, # pylint: disable=protected-access
self._native_object, self._native_object,
self._native_size) self._native_size)
@ -205,7 +207,7 @@ class _Hmac(_Hash):
_native_type = "Hmac *" _native_type = "Hmac *"
_native_size = _ffi.sizeof("Hmac") _native_size = _ffi.sizeof("Hmac")
def __init__(self, key, string=None): def __init__(self, key, string=None): # pylint: disable=W0231
key = t2b(key) key = t2b(key)
self._native_object = _ffi.new(self._native_type) self._native_object = _ffi.new(self._native_type)
@ -213,11 +215,11 @@ class _Hmac(_Hash):
if ret < 0: if ret < 0:
raise WolfCryptError("Hmac init error (%d)" % ret) raise WolfCryptError("Hmac init error (%d)" % ret)
if (string): if string:
self.update(string) self.update(string)
@classmethod @classmethod
def new(cls, key, string=None): def new(cls, key, string=None): # pylint: disable=W0221
""" """
Creates a new hashing object and returns it. **key** is Creates a new hashing object and returns it. **key** is
a required parameter containing a string giving the key a required parameter containing a string giving the key
@ -227,8 +229,8 @@ class _Hmac(_Hash):
""" """
return cls(key, string) return cls(key, string)
def _init(self, type, key): def _init(self, hmac, key):
return _lib.wc_HmacSetKey(self._native_object, type, key, len(key)) return _lib.wc_HmacSetKey(self._native_object, hmac, key, len(key))
def _update(self, data): def _update(self, data):
return _lib.wc_HmacUpdate(self._native_object, data, len(data)) return _lib.wc_HmacUpdate(self._native_object, data, len(data))

View File

@ -18,6 +18,8 @@
# along with this program; if not, write to the Free Software # along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
# pylint: disable=no-member,no-name-in-module
from wolfcrypt._ffi import ffi as _ffi from wolfcrypt._ffi import ffi as _ffi
from wolfcrypt._ffi import lib as _lib from wolfcrypt._ffi import lib as _lib