/*
 * Copyright (C) 2023 Hasl Developers
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
 */

#ifndef HASL_GS2_HEADER_H
#define HASL_GS2_HEADER_H

#include <glib.h>
#include <glib-object.h>

#include <hasl/haslversion.h>

G_BEGIN_DECLS

/**
 * HaslGs2HeaderChannelBinding:
 * @HaslGs2HeaderChannelBindingClientNotSupported: The client doesn't support
 *                                                 channel binding.
 * @HaslGs2HeaderChannelBindingClientSupported: The client supports channel
 *                                              binding and has specified a
 *                                              name.
 * @HaslGs2HeaderChannelBindingClientSupportedServerUnknown: The client
 *                                                           supports
 *                                                           channel binding,
 *                                                           doesn't know if
 *                                                           the server does.
 *
 * This enum tells the header about channel bindings for this connection. See
 * https://datatracker.ietf.org/doc/html/rfc5801#section-4 for more
 * information.
 *
 * Since: 0.3
 */
typedef enum {
	HaslGs2HeaderChannelBindingClientNotSupported,
	HaslGs2HeaderChannelBindingClientSupported,
	HaslGs2HeaderChannelBindingClientSupportedServerUnknown,
} HaslGs2HeaderChannelBinding;

#define HASL_GS2_HEADER_DOMAIN (g_quark_from_static_string("hash-gs2-header"))

/**
 * HaslGs2Header:
 *
 * This is an object to make it easier to generate a GS2 Header. See
 * https://www.rfc-editor.org/rfc/rfc5801#section-4 for the formal definition.
 *
 * This is primarily meant to be used by mechanism implementations and should
 * not be needed for normal use cases.
 *
 * Since: 0.3
 */
#define HASL_TYPE_GS2_HEADER (hasl_gs2_header_get_type())

HASL_AVAILABLE_IN_0_3
G_DECLARE_FINAL_TYPE(HaslGs2Header, hasl_gs2_header, HASL, GS2_HEADER, GObject)

/**
 * hasl_gs2_header_new:
 *
 * Creates a new gs2_header.
 *
 * Returns: (transfer full): The new gs2_header.
 *
 * Since: 0.3
 */
HASL_AVAILABLE_IN_0_3
HaslGs2Header *hasl_gs2_header_new(void);

/**
 * hasl_gs2_header_to_string:
 * @header: The instance.
 * @error: (out): A return address for an error.
 *
 * Serializes @header to a string in the correct format.
 *
 * Returns: (transfer full): The serialized header.
 *
 * Since: 0.3
 */
HASL_AVAILABLE_IN_0_3
char *hasl_gs2_header_to_string(HaslGs2Header *header, GError **error);

/**
 * hasl_gs2_header_get_standard_mechanism:
 * @header: The instance.
 *
 * Gets whether or not this header is for a standard GSS-API mechanism.
 *
 * Returns: %TRUE if this mechanism is standard, %FALSE otherwise.
 *
 * Since: 0.3
 */
HASL_AVAILABLE_IN_0_3
gboolean hasl_gs2_header_get_standard_mechanism(HaslGs2Header *header);

/**
 * hasl_gs2_header_set_standard_mechanism:
 * @header: The instance.
 * @standard: The new value.
 *
 * Sets whether or not the mechanism is a standard GSS-API mechanism.
 *
 * Since: 0.3
 */
HASL_AVAILABLE_IN_0_3
void hasl_gs2_header_set_standard_mechanism(HaslGs2Header *header, gboolean standard);

/**
 * hasl_gs2_header_get_channel_binding:
 * @header: The instance.
 *
 * Gets the channel binding value for this header.
 *
 * Returns: The channel binding value.
 *
 * Since: 0.3
 */
HASL_AVAILABLE_IN_0_3
HaslGs2HeaderChannelBinding hasl_gs2_header_get_channel_binding(HaslGs2Header *header);

/**
 * hasl_gs2_header_set_channel_binding:
 * @header: The instance.
 * @channel_binding: The channel binding flag.
 *
 * Sets the channel binding flag for @header.
 *
 * Since: 0.3
 */
HASL_AVAILABLE_IN_0_3
void hasl_gs2_header_set_channel_binding(HaslGs2Header *header, HaslGs2HeaderChannelBinding channel_binding);

/**
 * hasl_gs2_header_get_channel_binding_name:
 * @header: The instance.
 *
 * Gets the name of the channel binding that is in use.
 *
 * Returns: (nullable): The channel binding name.
 *
 * Since: 0.3
 */
HASL_AVAILABLE_IN_0_3
const char *hasl_gs2_header_get_channel_binding_name(HaslGs2Header *header);

/**
 * hasl_gs2_header_set_channel_binding_name:
 * @header: The instance.
 * @name: (nullable): The name of the channel binding data.
 *
 * Sets the name of the channel binding data that should be used.
 *
 * Since: 0.3
 */
HASL_AVAILABLE_IN_0_3
void hasl_gs2_header_set_channel_binding_name(HaslGs2Header *header, const char *name);

/**
 * hasl_gs2_header_get_authzid:
 * @header: The instance.
 *
 * Gets the authzid to use for this header.
 *
 * Returns: (nullable): The authzid for this header.
 *
 * Since: 0.3
 */
HASL_AVAILABLE_IN_0_3
const char *hasl_gs2_header_get_authzid(HaslGs2Header *header);

/**
 * hasl_gs2_header_set_authzid:
 * @header: The instance.
 * @authzid: (nullable): The username to authenticate for.
 *
 * Sets the username to authenticate for. This is used when an administrator
 * or moderator needs to authenticate as a specific user using their own
 * credentials.
 *
 * Since: 0.3
 */
HASL_AVAILABLE_IN_0_3
void hasl_gs2_header_set_authzid(HaslGs2Header *header, const char *authzid);

G_END_DECLS

#endif /* HASL_GS2_HEADER_H */
