Пример #1
0
 def test_invalid_decrytion(self):
     decryption = PkDecryption()
     encryption = PkEncryption(decryption.public_key)
     plaintext = "It's a secret to everybody."
     message = encryption.encrypt(plaintext)
     message.ephemeral_key = "?"
     with pytest.raises(PkDecryptionError):
         decryption.decrypt(message)
Пример #2
0
 def test_decrytion(self):
     decryption = PkDecryption()
     encryption = PkEncryption(decryption.public_key)
     plaintext = "It's a secret to everybody."
     message = encryption.encrypt(plaintext)
     decrypted_plaintext = decryption.decrypt(message)
     isinstance(decrypted_plaintext, str)
     assert plaintext == decrypted_plaintext
Пример #3
0
    def test_pickling(self):
        decryption = PkDecryption()
        encryption = PkEncryption(decryption.public_key)
        plaintext = "It's a secret to everybody."
        message = encryption.encrypt(plaintext)

        pickle = decryption.pickle()
        unpickled = PkDecryption.from_pickle(pickle)
        decrypted_plaintext = unpickled.decrypt(message)
        assert plaintext == decrypted_plaintext
Пример #4
0
 def test_invalid_unicode_decrypt(self):
     decryption = PkDecryption()
     encryption = PkEncryption(decryption.public_key)
     message = encryption.encrypt(b"\xed")
     plaintext = decryption.decrypt(message)
     assert plaintext == u"�"
Пример #5
0
    def test_invalid_pass_pickling(self):
        decryption = PkDecryption()
        pickle = decryption.pickle("Secret")

        with pytest.raises(PkDecryptionError):
            PkDecryption.from_pickle(pickle, "Not secret")
Пример #6
0
 def test_invalid_unpickling(self):
     with pytest.raises(ValueError):
         PkDecryption.from_pickle("")