Exemplo n.º 1
0
    def test_verified_decrypt_should_return_none_with_bad_msg(self):
        msg = "This is my party."
        bad_msg = "blah1" # Incorrect base64 padding

        # base 64
        encrypted_msg = verified_encrypt(TEST_KEY, msg, base64_encode=True)
        decrypted_msg = verified_decrypt(TEST_KEY, bad_msg, base64_decode=True)
        self.assertEqual(decrypted_msg, None)

        # not base 64
        encrypted_msg = verified_encrypt(TEST_KEY, msg, base64_encode=False)
        decrypted_msg = verified_decrypt(TEST_KEY, bad_msg, base64_decode=False)
        self.assertEqual(decrypted_msg, None)
Exemplo n.º 2
0
    def test_verified_decrypt_should_return_none_with_bad_key(self):
        msg = "This is my party."
        encrypted_msg = verified_encrypt(TEST_KEY, msg, base64_encode=False)

        decrypted_msg = verified_decrypt("bad key!", encrypted_msg, base64_decode=False)

        self.assertEqual(decrypted_msg, None)
Exemplo n.º 3
0
    def test_verified_encrypt_and_decrypt_should_be_reversible(self):
        msg = "This is my party."

        encrypted_msg = verified_encrypt(TEST_KEY, msg, base64_encode=False)
        decrypted_msg = verified_decrypt(TEST_KEY, encrypted_msg, base64_decode=False)

        self.assertEqual(decrypted_msg, msg)
Exemplo n.º 4
0
    def test_verified_encrypt_and_decrypt_in_base64_should_be_reversible(self):
        msg = "This is my party."

        encrypted_msg = verified_encrypt(TEST_KEY, msg, base64_encode=True)

        # Should not raise TypeError.
        base64.b64decode(encrypted_msg)

        decrypted_msg = verified_decrypt(TEST_KEY, encrypted_msg, base64_decode=True)

        self.assertEqual(msg, decrypted_msg)