Skip to content

Commit

Permalink
Renamed sign_then_encrypt -> sign_and_encrypt and decrypt_then_verify…
Browse files Browse the repository at this point in the history
… -> decrypt_and_verify
  • Loading branch information
kmuzychko committed Aug 8, 2019
1 parent 771f87a commit d1a2177
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
4 changes: 2 additions & 2 deletions virgil_crypto/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ def decrypt(data, private_key):
result += cipher.finish_decryption()
return result

def sign_then_encrypt(self, data, private_key, *recipients):
def sign_and_encrypt(self, data, private_key, *recipients):
# type: (Union[Tuple[int], List[int], bytearray], VirgilPrivateKey, List[VirgilPublicKey]) -> Union[Tuple[int], bytearray]
"""Signs and encrypts the data.
Expand Down Expand Up @@ -323,7 +323,7 @@ def sign_then_encrypt(self, data, private_key, *recipients):

return result

def decrypt_then_verify(self, data, private_key, signers_public_keys):
def decrypt_and_verify(self, data, private_key, signers_public_keys):
# type: (Union[Tuple[int], List[int], bytearray], VirgilPrivateKey, Union[List[VirgilPublicKey], VirgilPublicKey]) -> Union[Tuple[int], bytearray]
"""Decrypts and verifies the data.
Expand Down
6 changes: 3 additions & 3 deletions virgil_crypto/tests/compatibility_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def test_sign_then_encrypt_single_recipient(self):
data = self._compatibility_data["sign_then_encrypt_single_recipient"]
private_key = self._crypto.import_private_key(data["private_key"]).private_key
public_key = self._crypto.extract_public_key(private_key)
decrypted_data = self._crypto.decrypt_then_verify(
decrypted_data = self._crypto.decrypt_and_verify(
data["cipher_data"],
private_key,
public_key
Expand All @@ -87,7 +87,7 @@ def test_sign_then_encrypt_multiple_recipients(self):
self.assertGreater(len(private_keys), 0)
public_key = self._crypto.extract_public_key(private_keys[0])
for private_key in private_keys:
decrypted_data = self._crypto.decrypt_then_verify(
decrypted_data = self._crypto.decrypt_and_verify(
data["cipher_data"],
private_key,
public_key
Expand All @@ -111,7 +111,7 @@ def test_decrypt_then_verify_multiple_signers(self):
data = self._compatibility_data["sign_then_encrypt_multiple_signers"]
private_key = self._crypto.import_private_key(data["private_key"]).private_key
public_keys = [self._crypto.import_public_key(pk) for pk in data["public_keys"]]
decrypted_data = self._crypto.decrypt_then_verify(
decrypted_data = self._crypto.decrypt_and_verify(
data["cipher_data"],
private_key,
public_keys
Expand Down
14 changes: 7 additions & 7 deletions virgil_crypto/tests/crypto_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ def __check_sign_then_encrypt(self, key_pair_type):

data = bytearray("test data".encode())

encrypted = self._crypto().sign_then_encrypt(data, key_pair_1.private_key, key_pair_1.public_key, key_pair_2.public_key)
decrypted = self._crypto().decrypt_then_verify(encrypted, key_pair_2.private_key, [key_pair_1.public_key, key_pair_2.public_key])
encrypted = self._crypto().sign_and_encrypt(data, key_pair_1.private_key, key_pair_1.public_key, key_pair_2.public_key)
decrypted = self._crypto().decrypt_and_verify(encrypted, key_pair_2.private_key, [key_pair_1.public_key, key_pair_2.public_key])

self.assertEqual(data, decrypted)

self.assertRaises(VirgilCryptoFoundationError, self._crypto().decrypt_then_verify, encrypted, key_pair_3.private_key, [key_pair_1.public_key, key_pair_2.public_key])
self.assertRaises(VirgilCryptoError, self._crypto().decrypt_then_verify, encrypted, key_pair_2.private_key, key_pair_3.public_key)
self.assertRaises(VirgilCryptoFoundationError, self._crypto().decrypt_and_verify, encrypted, key_pair_3.private_key, [key_pair_1.public_key, key_pair_2.public_key])
self.assertRaises(VirgilCryptoError, self._crypto().decrypt_and_verify, encrypted, key_pair_2.private_key, key_pair_3.public_key)

def __check_stream_sign(self, key_pair_type):
key_pair_1 = self._crypto().generate_key_pair(key_pair_type)
Expand Down Expand Up @@ -442,13 +442,13 @@ def test_sign_then_encrypt(self):
key_pair_3 = crypto.generate_key_pair()
data = [1, 2, 3]

cipher_data = crypto.sign_then_encrypt(data, key_pair_1.private_key, key_pair_2.public_key)
cipher_data = crypto.sign_and_encrypt(data, key_pair_1.private_key, key_pair_2.public_key)

decrypted_data = crypto.decrypt_then_verify(cipher_data, key_pair_2.private_key, [key_pair_1.public_key, key_pair_2.public_key])
decrypted_data = crypto.decrypt_and_verify(cipher_data, key_pair_2.private_key, [key_pair_1.public_key, key_pair_2.public_key])

self.assertEqual(data, list(decrypted_data))

self.assertRaises(VirgilCryptoError, crypto.decrypt_then_verify, cipher_data, key_pair_2.private_key, key_pair_3.public_key)
self.assertRaises(VirgilCryptoError, crypto.decrypt_and_verify, cipher_data, key_pair_2.private_key, key_pair_3.public_key)

def test_generate_key_using_seed(self):
crypto = VirgilCrypto()
Expand Down

0 comments on commit d1a2177

Please sign in to comment.