proto_read_mechanism (p11_rpc_message *msg,
                      CK_MECHANISM_PTR mech)
{
	size_t offset;
	CK_MECHANISM temp;

	assert (msg != NULL);
	assert (mech != NULL);
	assert (msg->input != NULL);

	/* Make sure this is in the right order */
	assert (!msg->signature || p11_rpc_message_verify_part (msg, "M"));

	/* Check the length needed to store the parameter */
	memset (&temp, 0, sizeof (temp));
	offset = msg->parsed;
	if (!p11_rpc_buffer_get_mechanism (msg->input, &offset, &temp)) {
		msg->parsed = offset;
		return PARSE_ERROR;
	}

	mech->mechanism = temp.mechanism;

	/* The mechanism doesn't require parameter */
	if (temp.ulParameterLen == 0) {
		mech->pParameter = NULL;
		mech->ulParameterLen = 0;
		msg->parsed = offset;
		return CKR_OK;
	}

	/* Actually retrieve the parameter */
	mech->pParameter = p11_rpc_message_alloc_extra (msg, temp.ulParameterLen);
	if (!p11_rpc_buffer_get_mechanism (msg->input, &msg->parsed, mech))
		return PARSE_ERROR;

	assert (msg->parsed == offset);

	return CKR_OK;
}
proto_read_mechanism (p11_rpc_message *msg,
                      CK_MECHANISM_PTR mech)
{
	size_t offset;
	CK_MECHANISM temp;

	assert (msg != NULL);
	assert (mech != NULL);
	assert (msg->input != NULL);

	 
	assert (!msg->signature || p11_rpc_message_verify_part (msg, "M"));

	 
	memset (&temp, 0, sizeof (temp));
	offset = msg->parsed;
	if (!p11_rpc_buffer_get_mechanism (msg->input, &offset, &temp)) {
		msg->parsed = offset;
		return PARSE_ERROR;
	}

	mech->mechanism = temp.mechanism;

	 
	if (temp.ulParameterLen == 0) {
		mech->pParameter = NULL;
		mech->ulParameterLen = 0;
		msg->parsed = offset;
		return CKR_OK;
	}

	 
	mech->pParameter = p11_rpc_message_alloc_extra (msg, temp.ulParameterLen);
	if (!p11_rpc_buffer_get_mechanism (msg->input, &msg->parsed, mech))
		return PARSE_ERROR;

	assert (msg->parsed == offset);

	return CKR_OK;
}