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(federated_only=True, start_learning_now=False) # So, our story is fairly simple: an everyman meets Alice. somebody = Character(start_learning_now=False, federated_only=True) # Alice signs a message. message = b"A message for all my friends who can only verify and not sign." signature = alice.stamp(message) # Our everyman can verify it. somebody.verify_from(alice, message, signature) # Of course, verification fails with any fake message with pytest.raises(InvalidSignature): fake = b"McLovin 892 Momona St. Honolulu, HI 96820" somebody.verify_from(alice, fake, signature) # Signature verification also works when Alice is not living with our # everyman in the same process, and he only knows her by her public key alice_pubkey_bytes = bytes(alice.stamp) hearsay_alice = Character.from_public_keys({SigningPower: alice_pubkey_bytes}) somebody.verify_from(hearsay_alice, message, signature) hearsay_alice = Character.from_public_keys(verifying_key=alice_pubkey_bytes) somebody.verify_from(hearsay_alice, message, signature) alice.disenchant()
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(federated_only=True, start_learning_now=False) # So, our story is fairly simple: an everyman meets Alice. somebody = Character(start_learning_now=False, federated_only=True) # Alice signs a message. message = b"A message for all my friends who can only verify and not sign." signature = alice.stamp(message) # Our everyman can verify it. cleartext = somebody.verify_from(alice, message, signature, decrypt=False) assert cleartext is constants.NO_DECRYPTION_PERFORMED