Пример #1
0
def test_split_two_signatures():
    """
    We make two random Signatures and concat them.  Then split them and show that we got the proper result.
    """
    sig1 = Signature.from_bytes(secure_random(64))
    sig2 = Signature.from_bytes(secure_random(64))
    sigs_concatted = sig1 + sig2
    two_signature_splitter = BytestringSplitter(Signature, Signature)
    rebuilt_sig1, rebuilt_sig2 = two_signature_splitter(sigs_concatted)
    assert (sig1, sig2) == (rebuilt_sig1, rebuilt_sig2)
Пример #2
0
def test_signature_rs_serialization():
    privkey = UmbralPrivateKey.gen_key()
    message = b"attack at dawn"
    der_sig_bytes = ecdsa_sign(message, privkey)

    signature_from_der = Signature.from_bytes(der_sig_bytes, der_encoded=True)
    rs_sig_bytes = bytes(signature_from_der)
    assert len(rs_sig_bytes) == 64

    signature_from_rs = Signature.from_bytes(rs_sig_bytes, der_encoded=False)

    assert signature_from_rs == signature_from_der
    assert signature_from_rs == der_sig_bytes
    assert signature_from_rs.verify(message, privkey.get_pubkey())
Пример #3
0
def test_split_signature_from_arbitrary_bytes():
    how_many_bytes = 10
    signature = Signature.from_bytes(secure_random(64))
    some_bytes = secure_random(how_many_bytes)
    splitter = BytestringSplitter(Signature, (bytes, how_many_bytes))

    rebuilt_signature, rebuilt_bytes = splitter(signature + some_bytes)
Пример #4
0
    def sign(self, message: bytes) -> bytes:
        """
        Signs a hashed message and returns a signature.

        :param message: The message to sign

        :return: Signature in bytes
        """
        signature_der_bytes = API.ecdsa_sign(message, self._privkey)
        return Signature.from_bytes(signature_der_bytes, der_encoded=True)
Пример #5
0
def test_trying_to_extract_too_many_bytes_raises_typeerror():
    how_many_bytes = 10
    too_many_bytes = 11
    signature = Signature.from_bytes(secure_random(64))
    some_bytes = secure_random(how_many_bytes)
    splitter = BytestringSplitter(Signature, (bytes, too_many_bytes))

    with pytest.raises(ValueError):
        rebuilt_signature, rebuilt_bytes = splitter(signature + some_bytes,
                                                    return_remainder=True)
Пример #6
0
def test_signature_can_verify():
    privkey = UmbralPrivateKey.gen_key()
    message = b"attack at dawn"
    der_sig_bytes = ecdsa_sign(message, privkey)
    signature = Signature.from_bytes(der_sig_bytes, der_encoded=True)
    assert signature.verify(message, privkey.get_pubkey())