cipher pylint fixes
This commit is contained in:
parent
fa65b17fc9
commit
e0d81bb7e8
|
@ -1,5 +1,9 @@
|
|||
#!/usr/bin/env python
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
src/pyelliptic/cipher.py
|
||||
========================
|
||||
"""
|
||||
|
||||
# Copyright (C) 2011 Yann GUIBET <yannguibet@gmail.com>
|
||||
# See LICENSE for details.
|
||||
|
@ -7,7 +11,8 @@
|
|||
from openssl import OpenSSL
|
||||
|
||||
|
||||
class Cipher:
|
||||
# pylint: disable=redefined-builtin
|
||||
class Cipher(object):
|
||||
"""
|
||||
Symmetric encryption
|
||||
|
||||
|
@ -44,30 +49,34 @@ class Cipher:
|
|||
|
||||
@staticmethod
|
||||
def get_blocksize(ciphername):
|
||||
"""This Method returns cipher blocksize"""
|
||||
cipher = OpenSSL.get_cipher(ciphername)
|
||||
return cipher.get_blocksize()
|
||||
|
||||
@staticmethod
|
||||
def gen_IV(ciphername):
|
||||
"""Generate random initialization vector"""
|
||||
cipher = OpenSSL.get_cipher(ciphername)
|
||||
return OpenSSL.rand(cipher.get_blocksize())
|
||||
|
||||
def update(self, input):
|
||||
"""Update result with more data"""
|
||||
i = OpenSSL.c_int(0)
|
||||
buffer = OpenSSL.malloc(b"", len(input) + self.cipher.get_blocksize())
|
||||
inp = OpenSSL.malloc(input, len(input))
|
||||
if OpenSSL.EVP_CipherUpdate(self.ctx, OpenSSL.byref(buffer),
|
||||
OpenSSL.byref(i), inp, len(input)) == 0:
|
||||
raise Exception("[OpenSSL] EVP_CipherUpdate FAIL ...")
|
||||
return buffer.raw[0:i.value]
|
||||
return buffer.raw[0:i.value] # pylint: disable=invalid-slice-index
|
||||
|
||||
def final(self):
|
||||
"""Returning the final value"""
|
||||
i = OpenSSL.c_int(0)
|
||||
buffer = OpenSSL.malloc(b"", self.cipher.get_blocksize())
|
||||
if (OpenSSL.EVP_CipherFinal_ex(self.ctx, OpenSSL.byref(buffer),
|
||||
OpenSSL.byref(i))) == 0:
|
||||
raise Exception("[OpenSSL] EVP_CipherFinal_ex FAIL ...")
|
||||
return buffer.raw[0:i.value]
|
||||
return buffer.raw[0:i.value] # pylint: disable=invalid-slice-index
|
||||
|
||||
def ciphering(self, input):
|
||||
"""
|
||||
|
@ -77,6 +86,7 @@ class Cipher:
|
|||
return buff + self.final()
|
||||
|
||||
def __del__(self):
|
||||
# pylint: disable=protected-access
|
||||
if OpenSSL._hexversion > 0x10100000 and not OpenSSL._libreSSL:
|
||||
OpenSSL.EVP_CIPHER_CTX_reset(self.ctx)
|
||||
else:
|
||||
|
|
|
@ -27,6 +27,7 @@ def _equals_str(a, b):
|
|||
|
||||
|
||||
def equals(a, b):
|
||||
"""Compare two strings or bytearrays"""
|
||||
if isinstance(a, str):
|
||||
return _equals_str(a, b)
|
||||
else:
|
||||
|
@ -58,6 +59,7 @@ def hmac_sha512(k, m):
|
|||
|
||||
|
||||
def pbkdf2(password, salt=None, i=10000, keylen=64):
|
||||
"""Compute the salt, key and the message with pbkdf2"""
|
||||
if salt is None:
|
||||
salt = OpenSSL.rand(8)
|
||||
p_password = OpenSSL.malloc(password, len(password))
|
||||
|
|
Reference in New Issue
Block a user