Skip to content

Commit

Permalink
test that length of encrypted data == length of raw data (#282)
Browse files Browse the repository at this point in the history
* test that length of encrypted data == length of raw data

* fix test for php
  • Loading branch information
Lagovas authored and vixentael committed Jan 18, 2018
1 parent be45387 commit e4efcb3
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
2 changes: 2 additions & 0 deletions tests/phpthemis/scell_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ public function testTokenProtectWithContext($key, $message, $context, $iscorrect
$this->setExpectedException('Exception');
}
$encrypted_message = phpthemis_scell_token_protect_encrypt($key, $message, $context);
$this->assertEquals(strlen($encrypted_message["encrypted_message"]), strlen($message));
$decrypted_message = phpthemis_scell_token_protect_decrypt($key, $encrypted_message['encrypted_message'], $encrypted_message['token'], $context);
$this->assertEquals($decrypted_message, $message);
}
Expand Down Expand Up @@ -165,6 +166,7 @@ public function testTokenProtectWithoutContext($key, $message, $iscorrect){
$this->setExpectedException('Exception');
}
$encrypted_message = phpthemis_scell_token_protect_encrypt($key, $message);
$this->assertEquals(strlen($encrypted_message["encrypted_message"]), strlen($message));
$decrypted_message = phpthemis_scell_token_protect_decrypt($key, $encrypted_message['encrypted_message'], $encrypted_message['token']);
$this->assertEquals($decrypted_message, $message);
}
Expand Down
2 changes: 2 additions & 0 deletions tests/pythemis/test_scell.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def test_encrypt_decrypt(self):
scell2 = SCellTokenProtect(self.key)
scell3 = SCellTokenProtect(self.incorrect_key)
encrypted, token = scell1.encrypt(self.data)
self.assertEqual(len(self.data), len(encrypted))
self.assertEqual(self.data, scell2.decrypt(encrypted, token))

with self.assertRaises(ThemisError):
Expand All @@ -114,6 +115,7 @@ def test_encrypt_decrypt_context(self):
scell2 = SCellTokenProtect(self.key)
scell3 = SCellTokenProtect(self.incorrect_key)
encrypted, token = scell1.encrypt(self.data, self.context)
self.assertEqual(len(self.data), len(encrypted))
self.assertEqual(self.data,
scell2.decrypt(encrypted, token, self.context))

Expand Down
10 changes: 10 additions & 0 deletions tests/themis/themis_secure_cell.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ static int secure_cell_token_protect(){
testsuite_fail_if(true, "themis_secure_cell_encrypt_token_protect (encrypted_message_length determination) fail");
return -1;
}
if(encrypted_message_length != sizeof(message)){
testsuite_fail_if(true, "themis_secure_cell_encrypt_token_protect (encrypted_message_length != message length) fail");
return -1;
}
encrypted_message=malloc(encrypted_message_length);
if(encrypted_message==NULL){
testsuite_fail_if(true, "encrypted_message malloc fail");
Expand All @@ -105,6 +109,12 @@ static int secure_cell_token_protect(){
free(context);
return -3;
}
if(encrypted_message_length != sizeof(message)){
testsuite_fail_if(true, "themis_secure_cell_encrypt_token_protect (encrypted_message_length != message length) fail");
free(encrypted_message);
free(context);
return -3;
}
uint8_t* decrypted_message;
size_t decrypted_message_length=0;

Expand Down

0 comments on commit e4efcb3

Please # to comment.