/* 0300_cryptographic_hashes.c generated by valac 0.56.19, the Vala compiler
 * generated from 0300_cryptographic_hashes.vala, do not modify */

#include "xmpp-vala.h"
#include <gee.h>
#include <glib-object.h>
#include <glib.h>
#include <stdlib.h>
#include <string.h>

#if !defined(VALA_STRICT_C)
#if !defined(__clang__) && defined(__GNUC__) && (__GNUC__ >= 14)
#pragma GCC diagnostic warning "-Wincompatible-pointer-types"
#elif defined(__clang__) && (__clang_major__ >= 16)
#pragma clang diagnostic ignored "-Wincompatible-function-pointer-types"
#pragma clang diagnostic ignored "-Wincompatible-pointer-types"
#endif
#endif

#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _xmpp_stanza_entry_unref0(var) ((var == NULL) ? NULL : (var = (xmpp_stanza_entry_unref (var), NULL)))
#define _g_free0(var) ((var == NULL) ? NULL : (var = (g_free (var), NULL)))
enum  {
	XMPP_XEP_CRYPTOGRAPHIC_HASHES_HASH_0_PROPERTY,
	XMPP_XEP_CRYPTOGRAPHIC_HASHES_HASH_NUM_PROPERTIES
};
static GParamSpec* xmpp_xep_cryptographic_hashes_hash_properties[XMPP_XEP_CRYPTOGRAPHIC_HASHES_HASH_NUM_PROPERTIES];
#define _g_checksum_free0(var) ((var == NULL) ? NULL : (var = (g_checksum_free (var), NULL)))

static gpointer xmpp_xep_cryptographic_hashes_hash_parent_class = NULL;

static void xmpp_xep_cryptographic_hashes_hash_finalize (GObject * obj);
static GType xmpp_xep_cryptographic_hashes_hash_get_type_once (void);
static GChecksumType* _g_checksum_type_dup (GChecksumType* self);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

GeeList*
xmpp_xep_cryptographic_hashes_get_hashes (XmppStanzaNode* node)
{
	GeeArrayList* hashes = NULL;
	GeeArrayList* _tmp0_;
	GeeList* result;
	g_return_val_if_fail (node != NULL, NULL);
	_tmp0_ = gee_array_list_new (XMPP_XEP_CRYPTOGRAPHIC_HASHES_TYPE_HASH, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	hashes = _tmp0_;
	{
		GeeList* _hash_node_list = NULL;
		GeeList* _tmp1_;
		gint _hash_node_size = 0;
		GeeList* _tmp2_;
		gint _tmp3_;
		gint _tmp4_;
		gint _hash_node_index = 0;
		_tmp1_ = xmpp_stanza_node_get_subnodes (node, "hash", XMPP_XEP_CRYPTOGRAPHIC_HASHES_NS_URI, FALSE);
		_hash_node_list = _tmp1_;
		_tmp2_ = _hash_node_list;
		_tmp3_ = gee_collection_get_size ((GeeCollection*) _tmp2_);
		_tmp4_ = _tmp3_;
		_hash_node_size = _tmp4_;
		_hash_node_index = -1;
		while (TRUE) {
			gint _tmp5_;
			gint _tmp6_;
			XmppStanzaNode* hash_node = NULL;
			GeeList* _tmp7_;
			gpointer _tmp8_;
			GeeArrayList* _tmp9_;
			XmppStanzaNode* _tmp10_;
			XmppXepCryptographicHashesHash* _tmp11_;
			XmppXepCryptographicHashesHash* _tmp12_;
			_hash_node_index = _hash_node_index + 1;
			_tmp5_ = _hash_node_index;
			_tmp6_ = _hash_node_size;
			if (!(_tmp5_ < _tmp6_)) {
				break;
			}
			_tmp7_ = _hash_node_list;
			_tmp8_ = gee_list_get (_tmp7_, _hash_node_index);
			hash_node = (XmppStanzaNode*) _tmp8_;
			_tmp9_ = hashes;
			_tmp10_ = hash_node;
			_tmp11_ = xmpp_xep_cryptographic_hashes_hash_new_from_stanza_node (_tmp10_);
			_tmp12_ = _tmp11_;
			gee_abstract_collection_add ((GeeAbstractCollection*) _tmp9_, _tmp12_);
			_g_object_unref0 (_tmp12_);
			_xmpp_stanza_entry_unref0 (hash_node);
		}
		_g_object_unref0 (_hash_node_list);
	}
	result = (GeeList*) hashes;
	return result;
}

GeeList*
xmpp_xep_cryptographic_hashes_get_supported_hashes (GeeList* hashes)
{
	GeeArrayList* ret = NULL;
	GeeArrayList* _tmp0_;
	GeeList* result;
	g_return_val_if_fail (hashes != NULL, NULL);
	_tmp0_ = gee_array_list_new (XMPP_XEP_CRYPTOGRAPHIC_HASHES_TYPE_HASH, (GBoxedCopyFunc) g_object_ref, (GDestroyNotify) g_object_unref, NULL, NULL, NULL);
	ret = _tmp0_;
	{
		GeeList* _hash_list = NULL;
		gint _hash_size = 0;
		GeeList* _tmp1_;
		gint _tmp2_;
		gint _tmp3_;
		gint _hash_index = 0;
		_hash_list = hashes;
		_tmp1_ = _hash_list;
		_tmp2_ = gee_collection_get_size ((GeeCollection*) _tmp1_);
		_tmp3_ = _tmp2_;
		_hash_size = _tmp3_;
		_hash_index = -1;
		while (TRUE) {
			gint _tmp4_;
			gint _tmp5_;
			XmppXepCryptographicHashesHash* hash = NULL;
			GeeList* _tmp6_;
			gpointer _tmp7_;
			GChecksumType* hash_type = NULL;
			XmppXepCryptographicHashesHash* _tmp8_;
			const gchar* _tmp9_;
			GChecksumType* _tmp10_;
			GChecksumType* _tmp11_;
			_hash_index = _hash_index + 1;
			_tmp4_ = _hash_index;
			_tmp5_ = _hash_size;
			if (!(_tmp4_ < _tmp5_)) {
				break;
			}
			_tmp6_ = _hash_list;
			_tmp7_ = gee_list_get (_tmp6_, _hash_index);
			hash = (XmppXepCryptographicHashesHash*) _tmp7_;
			_tmp8_ = hash;
			_tmp9_ = _tmp8_->algo;
			_tmp10_ = xmpp_xep_cryptographic_hashes_hash_string_to_type (_tmp9_);
			hash_type = _tmp10_;
			_tmp11_ = hash_type;
			if (_tmp11_ != NULL) {
				GeeArrayList* _tmp12_;
				XmppXepCryptographicHashesHash* _tmp13_;
				_tmp12_ = ret;
				_tmp13_ = hash;
				gee_abstract_collection_add ((GeeAbstractCollection*) _tmp12_, _tmp13_);
			}
			_g_free0 (hash_type);
			_g_object_unref0 (hash);
		}
	}
	result = (GeeList*) ret;
	return result;
}

gboolean
xmpp_xep_cryptographic_hashes_has_supported_hashes (GeeList* hashes)
{
	gboolean result;
	g_return_val_if_fail (hashes != NULL, FALSE);
	{
		GeeList* _hash_list = NULL;
		gint _hash_size = 0;
		GeeList* _tmp0_;
		gint _tmp1_;
		gint _tmp2_;
		gint _hash_index = 0;
		_hash_list = hashes;
		_tmp0_ = _hash_list;
		_tmp1_ = gee_collection_get_size ((GeeCollection*) _tmp0_);
		_tmp2_ = _tmp1_;
		_hash_size = _tmp2_;
		_hash_index = -1;
		while (TRUE) {
			gint _tmp3_;
			gint _tmp4_;
			XmppXepCryptographicHashesHash* hash = NULL;
			GeeList* _tmp5_;
			gpointer _tmp6_;
			GChecksumType* hash_type = NULL;
			XmppXepCryptographicHashesHash* _tmp7_;
			const gchar* _tmp8_;
			GChecksumType* _tmp9_;
			GChecksumType* _tmp10_;
			_hash_index = _hash_index + 1;
			_tmp3_ = _hash_index;
			_tmp4_ = _hash_size;
			if (!(_tmp3_ < _tmp4_)) {
				break;
			}
			_tmp5_ = _hash_list;
			_tmp6_ = gee_list_get (_tmp5_, _hash_index);
			hash = (XmppXepCryptographicHashesHash*) _tmp6_;
			_tmp7_ = hash;
			_tmp8_ = _tmp7_->algo;
			_tmp9_ = xmpp_xep_cryptographic_hashes_hash_string_to_type (_tmp8_);
			hash_type = _tmp9_;
			_tmp10_ = hash_type;
			if (_tmp10_ != NULL) {
				result = TRUE;
				_g_free0 (hash_type);
				_g_object_unref0 (hash);
				return result;
			}
			_g_free0 (hash_type);
			_g_object_unref0 (hash);
		}
	}
	result = FALSE;
	return result;
}

XmppXepCryptographicHashesHash*
xmpp_xep_cryptographic_hashes_hash_construct_with_checksum (GType object_type,
                                                            GChecksumType checksum_type,
                                                            const gchar* hash)
{
	XmppXepCryptographicHashesHash * self = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	g_return_val_if_fail (hash != NULL, NULL);
	self = (XmppXepCryptographicHashesHash*) g_object_new (object_type, NULL);
	_tmp0_ = xmpp_xep_cryptographic_hashes_hash_type_to_string (checksum_type);
	_g_free0 (self->algo);
	self->algo = _tmp0_;
	_tmp1_ = g_strdup (hash);
	_g_free0 (self->val);
	self->val = _tmp1_;
	return self;
}

XmppXepCryptographicHashesHash*
xmpp_xep_cryptographic_hashes_hash_new_with_checksum (GChecksumType checksum_type,
                                                      const gchar* hash)
{
	return xmpp_xep_cryptographic_hashes_hash_construct_with_checksum (XMPP_XEP_CRYPTOGRAPHIC_HASHES_TYPE_HASH, checksum_type, hash);
}

XmppXepCryptographicHashesHash*
xmpp_xep_cryptographic_hashes_hash_construct_compute (GType object_type,
                                                      GChecksumType type,
                                                      guint8* data,
                                                      gint data_length1)
{
	XmppXepCryptographicHashesHash * self = NULL;
	GChecksum* checksum = NULL;
	GChecksum* _tmp0_;
	guint8* digest = NULL;
	guint8* _tmp1_;
	gint digest_length1;
	gint _digest_size_;
	gsize length = 0UL;
	gchar* _tmp2_;
	gchar* _tmp3_;
	self = (XmppXepCryptographicHashesHash*) g_object_new (object_type, NULL);
	_tmp0_ = g_checksum_new (type);
	checksum = _tmp0_;
	g_checksum_update (checksum, data, (gsize) data_length1);
	_tmp1_ = g_new0 (guint8, 64);
	digest = _tmp1_;
	digest_length1 = 64;
	_digest_size_ = digest_length1;
	length = (gsize) digest_length1;
	g_checksum_get_digest (checksum, digest, &length);
	_tmp2_ = xmpp_xep_cryptographic_hashes_hash_type_to_string (type);
	_g_free0 (self->algo);
	self->algo = _tmp2_;
	_tmp3_ = g_base64_encode (digest + 0, (gint) (((gint) length) - 0));
	_g_free0 (self->val);
	self->val = _tmp3_;
	digest = (g_free (digest), NULL);
	_g_checksum_free0 (checksum);
	return self;
}

XmppXepCryptographicHashesHash*
xmpp_xep_cryptographic_hashes_hash_new_compute (GChecksumType type,
                                                guint8* data,
                                                gint data_length1)
{
	return xmpp_xep_cryptographic_hashes_hash_construct_compute (XMPP_XEP_CRYPTOGRAPHIC_HASHES_TYPE_HASH, type, data, data_length1);
}

XmppStanzaNode*
xmpp_xep_cryptographic_hashes_hash_to_stanza_node (XmppXepCryptographicHashesHash* self)
{
	XmppStanzaNode* _tmp0_;
	XmppStanzaNode* _tmp1_;
	XmppStanzaNode* _tmp2_;
	XmppStanzaNode* _tmp3_;
	const gchar* _tmp4_;
	XmppStanzaNode* _tmp5_;
	XmppStanzaNode* _tmp6_;
	const gchar* _tmp7_;
	XmppStanzaNode* _tmp8_;
	XmppStanzaNode* _tmp9_;
	XmppStanzaNode* _tmp10_;
	XmppStanzaNode* _tmp11_;
	XmppStanzaNode* result;
	g_return_val_if_fail (self != NULL, NULL);
	_tmp0_ = xmpp_stanza_node_new_build ("hash", XMPP_XEP_CRYPTOGRAPHIC_HASHES_NS_URI, NULL, NULL);
	_tmp1_ = _tmp0_;
	_tmp2_ = xmpp_stanza_node_add_self_xmlns (_tmp1_);
	_tmp3_ = _tmp2_;
	_tmp4_ = self->algo;
	_tmp5_ = xmpp_stanza_node_put_attribute (_tmp3_, "algo", _tmp4_, NULL);
	_tmp6_ = _tmp5_;
	_tmp7_ = self->val;
	_tmp8_ = xmpp_stanza_node_new_text (_tmp7_);
	_tmp9_ = _tmp8_;
	_tmp10_ = xmpp_stanza_node_put_node (_tmp6_, _tmp9_);
	_tmp11_ = _tmp10_;
	_xmpp_stanza_entry_unref0 (_tmp9_);
	_xmpp_stanza_entry_unref0 (_tmp6_);
	_xmpp_stanza_entry_unref0 (_tmp3_);
	_xmpp_stanza_entry_unref0 (_tmp1_);
	result = _tmp11_;
	return result;
}

XmppXepCryptographicHashesHash*
xmpp_xep_cryptographic_hashes_hash_construct_from_stanza_node (GType object_type,
                                                               XmppStanzaNode* node)
{
	XmppXepCryptographicHashesHash * self = NULL;
	const gchar* _tmp0_;
	gchar* _tmp1_;
	const gchar* _tmp2_;
	gchar* _tmp3_;
	g_return_val_if_fail (node != NULL, NULL);
	self = (XmppXepCryptographicHashesHash*) g_object_new (object_type, NULL);
	_tmp0_ = xmpp_stanza_node_get_attribute (node, "algo", NULL);
	_tmp1_ = g_strdup (_tmp0_);
	_g_free0 (self->algo);
	self->algo = _tmp1_;
	_tmp2_ = xmpp_stanza_entry_get_string_content ((XmppStanzaEntry*) node);
	_tmp3_ = g_strdup (_tmp2_);
	_g_free0 (self->val);
	self->val = _tmp3_;
	return self;
}

XmppXepCryptographicHashesHash*
xmpp_xep_cryptographic_hashes_hash_new_from_stanza_node (XmppStanzaNode* node)
{
	return xmpp_xep_cryptographic_hashes_hash_construct_from_stanza_node (XMPP_XEP_CRYPTOGRAPHIC_HASHES_TYPE_HASH, node);
}

XmppXepCryptographicHashesHash*
xmpp_xep_cryptographic_hashes_hash_construct (GType object_type)
{
	XmppXepCryptographicHashesHash * self = NULL;
	self = (XmppXepCryptographicHashesHash*) g_object_new (object_type, NULL);
	return self;
}

XmppXepCryptographicHashesHash*
xmpp_xep_cryptographic_hashes_hash_new (void)
{
	return xmpp_xep_cryptographic_hashes_hash_construct (XMPP_XEP_CRYPTOGRAPHIC_HASHES_TYPE_HASH);
}

static void
xmpp_xep_cryptographic_hashes_hash_class_init (XmppXepCryptographicHashesHashClass * klass,
                                               gpointer klass_data)
{
	xmpp_xep_cryptographic_hashes_hash_parent_class = g_type_class_peek_parent (klass);
	G_OBJECT_CLASS (klass)->finalize = xmpp_xep_cryptographic_hashes_hash_finalize;
}

static void
xmpp_xep_cryptographic_hashes_hash_instance_init (XmppXepCryptographicHashesHash * self,
                                                  gpointer klass)
{
}

static void
xmpp_xep_cryptographic_hashes_hash_finalize (GObject * obj)
{
	XmppXepCryptographicHashesHash * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, XMPP_XEP_CRYPTOGRAPHIC_HASHES_TYPE_HASH, XmppXepCryptographicHashesHash);
	_g_free0 (self->algo);
	_g_free0 (self->val);
	G_OBJECT_CLASS (xmpp_xep_cryptographic_hashes_hash_parent_class)->finalize (obj);
}

static GType
xmpp_xep_cryptographic_hashes_hash_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (XmppXepCryptographicHashesHashClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) xmpp_xep_cryptographic_hashes_hash_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (XmppXepCryptographicHashesHash), 0, (GInstanceInitFunc) xmpp_xep_cryptographic_hashes_hash_instance_init, NULL };
	GType xmpp_xep_cryptographic_hashes_hash_type_id;
	xmpp_xep_cryptographic_hashes_hash_type_id = g_type_register_static (G_TYPE_OBJECT, "XmppXepCryptographicHashesHash", &g_define_type_info, 0);
	return xmpp_xep_cryptographic_hashes_hash_type_id;
}

GType
xmpp_xep_cryptographic_hashes_hash_get_type (void)
{
	static volatile gsize xmpp_xep_cryptographic_hashes_hash_type_id__once = 0;
	if (g_once_init_enter (&xmpp_xep_cryptographic_hashes_hash_type_id__once)) {
		GType xmpp_xep_cryptographic_hashes_hash_type_id;
		xmpp_xep_cryptographic_hashes_hash_type_id = xmpp_xep_cryptographic_hashes_hash_get_type_once ();
		g_once_init_leave (&xmpp_xep_cryptographic_hashes_hash_type_id__once, xmpp_xep_cryptographic_hashes_hash_type_id);
	}
	return xmpp_xep_cryptographic_hashes_hash_type_id__once;
}

gchar*
xmpp_xep_cryptographic_hashes_hash_type_to_string (GChecksumType type)
{
	gchar* _tmp5_;
	gchar* result;
	switch (type) {
		case G_CHECKSUM_MD5:
		{
			gchar* _tmp0_;
			_tmp0_ = g_strdup ("md5");
			result = _tmp0_;
			return result;
		}
		case G_CHECKSUM_SHA1:
		{
			gchar* _tmp1_;
			_tmp1_ = g_strdup ("sha-1");
			result = _tmp1_;
			return result;
		}
		case G_CHECKSUM_SHA256:
		{
			gchar* _tmp2_;
			_tmp2_ = g_strdup ("sha-256");
			result = _tmp2_;
			return result;
		}
		case G_CHECKSUM_SHA384:
		{
			gchar* _tmp3_;
			_tmp3_ = g_strdup ("sha-384");
			result = _tmp3_;
			return result;
		}
		case G_CHECKSUM_SHA512:
		{
			gchar* _tmp4_;
			_tmp4_ = g_strdup ("sha-512");
			result = _tmp4_;
			return result;
		}
		default:
		break;
	}
	_tmp5_ = g_strdup ("(null)");
	result = _tmp5_;
	return result;
}

static GChecksumType*
_g_checksum_type_dup (GChecksumType* self)
{
	GChecksumType* dup;
	dup = g_new0 (GChecksumType, 1);
	memcpy (dup, self, sizeof (GChecksumType));
	return dup;
}

static gpointer
__g_checksum_type_dup0 (gpointer self)
{
	return self ? _g_checksum_type_dup (self) : NULL;
}

GChecksumType*
xmpp_xep_cryptographic_hashes_hash_string_to_type (const gchar* hash)
{
	const gchar* _tmp0_;
	GQuark _tmp2_ = 0U;
	static GQuark _tmp1_label0 = 0;
	static GQuark _tmp1_label1 = 0;
	static GQuark _tmp1_label2 = 0;
	static GQuark _tmp1_label3 = 0;
	GChecksumType* result;
	g_return_val_if_fail (hash != NULL, NULL);
	_tmp0_ = hash;
	_tmp2_ = (NULL == _tmp0_) ? 0 : g_quark_from_string (_tmp0_);
	if (_tmp2_ == ((0 != _tmp1_label0) ? _tmp1_label0 : (_tmp1_label0 = g_quark_from_static_string ("sha-1")))) {
		switch (0) {
			default:
			{
				GChecksumType _tmp3_;
				GChecksumType* _tmp4_;
				_tmp3_ = G_CHECKSUM_SHA1;
				_tmp4_ = __g_checksum_type_dup0 (&_tmp3_);
				result = _tmp4_;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label1) ? _tmp1_label1 : (_tmp1_label1 = g_quark_from_static_string ("sha-256")))) {
		switch (0) {
			default:
			{
				GChecksumType _tmp5_;
				GChecksumType* _tmp6_;
				_tmp5_ = G_CHECKSUM_SHA256;
				_tmp6_ = __g_checksum_type_dup0 (&_tmp5_);
				result = _tmp6_;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label2) ? _tmp1_label2 : (_tmp1_label2 = g_quark_from_static_string ("sha-384")))) {
		switch (0) {
			default:
			{
				GChecksumType _tmp7_;
				GChecksumType* _tmp8_;
				_tmp7_ = G_CHECKSUM_SHA384;
				_tmp8_ = __g_checksum_type_dup0 (&_tmp7_);
				result = _tmp8_;
				return result;
			}
		}
	} else if (_tmp2_ == ((0 != _tmp1_label3) ? _tmp1_label3 : (_tmp1_label3 = g_quark_from_static_string ("sha-512")))) {
		switch (0) {
			default:
			{
				GChecksumType _tmp9_;
				GChecksumType* _tmp10_;
				_tmp9_ = G_CHECKSUM_SHA512;
				_tmp10_ = __g_checksum_type_dup0 (&_tmp9_);
				result = _tmp10_;
				return result;
			}
		}
	}
	result = NULL;
	return result;
}

static inline gpointer
_vala_memdup2 (gconstpointer mem,
               gsize byte_size)
{
	gpointer new_mem;
	if (mem && byte_size != 0) {
		new_mem = g_malloc (byte_size);
		memcpy (new_mem, mem, byte_size);
	} else {
		new_mem = NULL;
	}
	return new_mem;
}

