def METHOD_NAME(private_key, payload):
    try:
        print("Signing payload using the HSM.")
        key_type = private_key.key_type
        mechanism, mechanism_params = get_mechanism(key_type)
        signature = private_key.sign(
            data=payload, mechanism=mechanism, mechanism_param=mechanism_params
        )
        if len(signature) != 0:
            print("Signature generation successful.")
        if key_type == pkcs11.mechanisms.KeyType.EC:
            r = int(binascii.hexlify(signature[:32]), 16)
            s = int(binascii.hexlify(signature[32:]), 16)
            # der encoding in case of ecdsa signatures
            signature = ecdsa.der.encode_sequence(
                ecdsa.der.encode_integer(r), ecdsa.der.encode_integer(s)
            )
        return signature
    except pkcs11.exceptions.PKCS11Error as e:
        handle_exceptions(e, mechanism)
        print("Payload Signing Failed")
        sys.exit(1)