Пример #1
0
 def test_signature_recoverable(self):
     private_key = PrivateKey(PRIVATE_KEY_BYTES)
     assert (private_key.public_key.format() == PublicKey(
         recover(
             MESSAGE,
             deserialize_recoverable(
                 private_key.sign_recoverable(MESSAGE)))).format())
Пример #2
0
    def test_signature_correct(self):
        private_key = PrivateKey()
        public_key = private_key.public_key

        message = urandom(200)
        signature = private_key.sign(message, schnorr=False)

        assert verify_signature(signature, message,
                                public_key.format(compressed=True))
        assert verify_signature(signature, message,
                                public_key.format(compressed=False))
Пример #3
0
    def test_ecdh(self):
        a = PrivateKey()
        b = PrivateKey()

        assert a.ecdh(b.public_key.format()) == b.ecdh(a.public_key.format())
Пример #4
0
 def test_from_der(self):
     assert PrivateKey.from_der(PRIVATE_KEY_DER).secret == PRIVATE_KEY_BYTES
Пример #5
0
 def test_from_pem(self):
     assert PrivateKey.from_pem(PRIVATE_KEY_PEM).secret == PRIVATE_KEY_BYTES
Пример #6
0
 def test_from_int(self):
     assert PrivateKey.from_int(PRIVATE_KEY_NUM).secret == PRIVATE_KEY_BYTES
Пример #7
0
 def test_from_hex(self):
     assert PrivateKey.from_hex(PRIVATE_KEY_HEX).secret == PRIVATE_KEY_BYTES
Пример #8
0
 def test_to_der(self):
     assert PrivateKey(PRIVATE_KEY_BYTES).to_der() == PRIVATE_KEY_DER
Пример #9
0
    def test_multiply_update(self):
        private_key = PrivateKey(b'\x05')
        new_private_key = private_key.multiply(b'\x05', update=True)

        assert new_private_key.to_int() == 25
        assert private_key is new_private_key
Пример #10
0
 def test_to_int(self):
     assert PrivateKey(PRIVATE_KEY_BYTES).to_int() == PRIVATE_KEY_NUM
Пример #11
0
 def test_to_hex(self):
     assert PrivateKey(PRIVATE_KEY_BYTES).to_hex() == PRIVATE_KEY_HEX
Пример #12
0
 def test_signature_invalid_hasher(self):
     with pytest.raises(ValueError):
         PrivateKey().sign(MESSAGE,
                           lambda x: sha512(x).digest(),
                           schnorr=False)
Пример #13
0
 def test_signature_deterministic(self):
     assert PrivateKey(PRIVATE_KEY_BYTES).sign(
         MESSAGE, schnorr=False) == SIGNATURE_DER
Пример #14
0
 def test_public_key(self):
     assert PrivateKey(
         PRIVATE_KEY_BYTES).public_key.format() == PUBLIC_KEY_COMPRESSED
Пример #15
0
 def test_add(self):
     assert PrivateKey(b'\x01').add(b'\x09').to_int() == 10
Пример #16
0
 def test_to_pem(self):
     assert PrivateKey(PRIVATE_KEY_BYTES).to_pem() == PRIVATE_KEY_PEM
Пример #17
0
    def test_add_update(self):
        private_key = PrivateKey(b'\x01')
        new_private_key = private_key.add(b'\x09', update=True)

        assert new_private_key.to_int() == 10
        assert private_key is new_private_key
Пример #18
0
 def test_multiply(self):
     assert PrivateKey(b'\x05').multiply(b'\x05').to_int() == 25