def test_ecdsa_signverify(curve, hashname):
    key_object = objects.ECCKey(0xE100)
    pkey, _ = crypto.generate_pair(key_object, curve=curve)
    key_object_fail = objects.ECCKey(0xE101)
    pkey_fail, _ = crypto.generate_pair(key_object_fail, curve=curve)
    ha = hashname
    s = crypto.ecdsa_sign(key_object, tbs_str)
    print('[{}]'.format(', '.join(hex(x) for x in list(s.signature))))

    # Preparing a PublicKeyInfo
    pubkey_info = keys.PublicKeyInfo.load(pkey)

    # Load a public key into the oscrypto engine to using it in the verify function
    public = load_public_key(pubkey_info)

    ecdsa_verify(public, s.signature, tbs_str, ha)

    # Assert wrong text
    with pytest.raises(SignatureError):
        ecdsa_verify(public, s.signature, tbs_str_fail, ha)

    # Assert wrong key
    with pytest.raises(SignatureError):
        # Preparing a PublicKeyInfo
        pubkey_info = keys.PublicKeyInfo.load(pkey_fail)

        # Load a public key into the oscrypto engine to using it in the verify function
        public = load_public_key(pubkey_info)
        ecdsa_verify(public, s.signature, tbs_str, ha)
def test_meta_assign_execute_ac():
    obj = objects.ECCKey(0xe0f0)
    old_meta = {'execute': obj.meta['execute']}
    obj.meta = {'execute': 'never'}
    with pytest.raises(IOError):
        print(crypto.ecdsa_sign(obj, b'\x00\x00\x00'))

    obj.meta = old_meta
def test_ecdsa(oid, curve, max_sign_size, hashname):
    key_object = objects.ECCKey(oid)
    _, _ = crypto.generate_pair(key_object, curve=curve)
    s = crypto.ecdsa_sign(key_object, tbs_str)
    assert isinstance(s.signature, bytes)
    assert len(s.signature) > 0
    assert len(s.signature) <= max_sign_size
    assert s.hash_alg == hashname
    assert s.algorithm == hashname + '_ecdsa'
def test_ecdsa_nonkey_2():
    with pytest.raises(TypeError):
        crypto.ecdsa_sign(int(19273917398739829))
def test_ecdsa_nonkey():
    ecc_key = bytes(35)
    with pytest.raises(TypeError):
        crypto.ecdsa_sign(ecc_key, tbs_str)