示例#1
0
def test_trying_to_find_unknown_actor_raises_not_found():
    tony_clifton = Character()

    message = b"some_message"
    signature = ALICE.seal(message)

    # Tony can't reference Alice...
    with pytest.raises(Character.NotFound):
        verification = tony_clifton.verify_from(ALICE, signature, message)

    # ...before learning about Alice.
    tony_clifton.learn_about_actor(ALICE)
    verification, NO_DECRYPTION_PERFORMED = tony_clifton.verify_from(ALICE, signature, message)

    assert verification is True
示例#2
0
def test_anybody_can_verify():
    """
    In the last example, we used the lower-level Crypto API to verify the signature.

    Here, we show that anybody can do it without needing to directly access Crypto.
    """

    # Alice can sign by default, by dint of her _default_crypto_powerups.
    alice = Alice()

    # So, our story is fairly simple: an everyman meets Alice.
    somebody = Character()
    somebody.learn_about_actor(alice)

    # Alice signs a message.
    message = b"A message for all my friends who can only verify and not sign."
    signature = alice.seal(message)

    # Our everyman can verify it.
    verification, cleartext = somebody.verify_from(alice,
                                                   message,
                                                   signature,
                                                   decrypt=False)
    assert verification is True
    assert cleartext is NO_DECRYPTION_PERFORMED
def test_trying_to_find_unknown_actor_raises_not_found(alice):
    """
    Tony the test character can't make reference to a character he doesn't know about yet.
    """
    tony_clifton = Character()

    message = b"some_message"
    signature = alice.seal(message)

    # Tony can't reference Alice...
    with pytest.raises(Character.NotFound):
        verification = tony_clifton.verify_from(alice, signature, message)

    # ...before learning about Alice.
    tony_clifton.learn_about_actor(alice)
    verification, NO_DECRYPTION_PERFORMED = tony_clifton.verify_from(alice, message, signature)

    assert verification is True