add unit tests in encrypt
This commit is contained in:
parent
a377cc3fb2
commit
4d5d6c7c85
1 changed files with 26 additions and 0 deletions
|
@ -163,3 +163,29 @@ def encrypt_all(password, method, op, data):
|
||||||
cipher = m(method, key, iv, op)
|
cipher = m(method, key, iv, op)
|
||||||
result.append(cipher.update(data))
|
result.append(cipher.update(data))
|
||||||
return b''.join(result)
|
return b''.join(result)
|
||||||
|
|
||||||
|
|
||||||
|
def test_encryptor():
|
||||||
|
from os import urandom
|
||||||
|
plain = urandom(10240)
|
||||||
|
for method in method_supported.keys():
|
||||||
|
logging.warn('testing %s' % method.decode('utf-8'))
|
||||||
|
encryptor = Encryptor(b'key', method)
|
||||||
|
cipher = encryptor.encrypt(plain)
|
||||||
|
decryptor = Encryptor(b'key', method)
|
||||||
|
plain2 = decryptor.decrypt(cipher)
|
||||||
|
assert plain == plain2
|
||||||
|
|
||||||
|
|
||||||
|
def test_encrypt_all():
|
||||||
|
from os import urandom
|
||||||
|
plain = urandom(10240)
|
||||||
|
for method in method_supported.keys():
|
||||||
|
cipher = encrypt_all(b'key', method, 1, plain)
|
||||||
|
plain2 = encrypt_all(b'key', method, 0, cipher)
|
||||||
|
assert plain == plain2
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
test_encrypt_all()
|
||||||
|
test_encryptor()
|
||||||
|
|
Loading…
Reference in a new issue