Ejemplo n.º 1
0
    def test_signing_parity(self):
        key1 = ECDSAECKey(private_key, ALGORITHMS.ES256)
        public_key = key1.public_key().to_pem()
        vkey1 = ECDSAECKey(public_key, ALGORITHMS.ES256)
        key2 = CryptographyECKey(private_key, ALGORITHMS.ES256)
        vkey2 = CryptographyECKey(public_key, ALGORITHMS.ES256)

        msg = b'test'
        sig1 = key1.sign(msg)
        sig2 = key2.sign(msg)

        assert vkey1.verify(msg, sig1)
        assert vkey1.verify(msg, sig2)
        assert vkey2.verify(msg, sig1)
        assert vkey2.verify(msg, sig2)

        # invalid signature
        assert not vkey2.verify(msg, b'n' * 64)
Ejemplo n.º 2
0
 def test_key_too_short(self):
     priv_key = ecdsa.SigningKey.generate(curve=ecdsa.NIST256p).to_pem()
     key = CryptographyECKey(priv_key, ALGORITHMS.ES512)
     with pytest.raises(TypeError):
         key.sign('foo')