/*
 * 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_MECHANISM_ANONYMOUS_H
#define HASL_MECHANISM_ANONYMOUS_H

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

#include <hasl/haslcontext.h>
#include <hasl/haslmechanism.h>
#include <hasl/haslversion.h>

G_BEGIN_DECLS

#define HASL_MECHANISM_ANONYMOUS_ERROR hasl_mechanism_anonymous_error_quark()

/**
 * hasl_mechanism_anonymous_error_quark:
 *
 * The error domain for errors with the anonymous mechanism.
 *
 * Returns: The error domain.
 *
 * Since: 0.5
 */
HASL_AVAILABLE_IN_0_5
GQuark hasl_mechanism_anonymous_error_quark(void);

/**
 * HaslMechanismAnonymousError:
 * @HASL_MECHANISM_ANONYMOUS_ERROR_MISSING_USERNAME: No username was set in the
 *  context.
 * @HASL_MECHANISM_ANONYMOUS_ERROR_CLEARTEXT_NOT_ALLOWED: The allow cleartext
 *  property of the context is false and the context is not using TLS.
 * @HASL_MECHANISM_ANONYMOUS_ERROR_STRINGPREP_FAILED: Stringprep of the
 *  username failed.
 *
 * Error codes for the anonymous mechanism.
 *
 * Since: 0.5
 */
typedef enum {
    HASL_MECHANISM_ANONYMOUS_ERROR_MISSING_USERNAME HASL_AVAILABLE_ENUMERATOR_IN_0_5,
    HASL_MECHANISM_ANONYMOUS_ERROR_CLEARTEXT_NOT_ALLOWED HASL_AVAILABLE_ENUMERATOR_IN_0_5,
    HASL_MECHANISM_ANONYMOUS_ERROR_STRINGPREP_FAILED HASL_AVAILABLE_ENUMERATOR_IN_0_5,
} HaslMechanismAnonymousError;

#define HASL_MECHANISM_ANONYMOUS_DOMAIN \
    HASL_MECHANISM_ANONYMOUS_ERROR \
    HASL_DEPRECATED_MACRO_IN_0_5_FOR(HASL_MECHANISM_ANONYMOUS_ERROR)

/**
 * HaslMechanismAnonymous:
 *
 * This mechanism implements the ANONYMOUS method described in
 * [RFC 4505](https://www.rfc-editor.org/rfc/rfc4505). It uses the value of
 * [property@Context:username] as the token.
 *
 * This mechanism is not secure, so you must set
 * [property@Context:allow-clear-text] to %TRUE if [property@Context:tls] is
 * %FALSE.
 *
 * Since: 0.2
 */

#define HASL_TYPE_MECHANISM_ANONYMOUS (hasl_mechanism_anonymous_get_type())

HASL_AVAILABLE_IN_0_2
G_DECLARE_FINAL_TYPE(HaslMechanismAnonymous, hasl_mechanism_anonymous, HASL,
                     MECHANISM_ANONYMOUS, HaslMechanism)

G_END_DECLS

#endif /* HASL_MECHANISM_ANONYMOUS_H */
