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

#include "omemo.h"
#include <glib-object.h>
#include "libdino.h"
#include <glib.h>
#include <stdlib.h>
#include <string.h>
#include <gio/gio.h>
#include "crypto-vala.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_free0(var) (var = (g_free (var), NULL))
enum  {
	DINO_PLUGINS_OMEMO_OMEMO_FILE_DECRYPTOR_0_PROPERTY,
	DINO_PLUGINS_OMEMO_OMEMO_FILE_DECRYPTOR_NUM_PROPERTIES
};
static GParamSpec* dino_plugins_omemo_omemo_file_decryptor_properties[DINO_PLUGINS_OMEMO_OMEMO_FILE_DECRYPTOR_NUM_PROPERTIES];
#define _g_regex_unref0(var) ((var == NULL) ? NULL : (var = (g_regex_unref (var), NULL)))
#define _dino_file_receive_data_unref0(var) ((var == NULL) ? NULL : (var = (dino_file_receive_data_unref (var), NULL)))
#define _g_object_unref0(var) ((var == NULL) ? NULL : (var = (g_object_unref (var), NULL)))
#define _g_match_info_unref0(var) ((var == NULL) ? NULL : (var = (g_match_info_unref (var), NULL)))
#define _crypto_symmetric_cipher_unref0(var) ((var == NULL) ? NULL : (var = (crypto_symmetric_cipher_unref (var), NULL)))
#define _g_error_free0(var) ((var == NULL) ? NULL : (var = (g_error_free (var), NULL)))
typedef struct _DinoPluginsOmemoOmemoFileDecryptorDecryptFileData DinoPluginsOmemoOmemoFileDecryptorDecryptFileData;
#define _vala_assert(expr, msg) if G_LIKELY (expr) ; else g_assertion_message_expr (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);
#define _vala_return_if_fail(expr, msg) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return; }
#define _vala_return_val_if_fail(expr, msg, val) if G_LIKELY (expr) ; else { g_return_if_fail_warning (G_LOG_DOMAIN, G_STRFUNC, msg); return val; }
#define _vala_warn_if_fail(expr, msg) if G_LIKELY (expr) ; else g_warn_message (G_LOG_DOMAIN, __FILE__, __LINE__, G_STRFUNC, msg);

struct _DinoPluginsOmemoOmemoFileDecryptorPrivate {
	GRegex* url_regex;
};

struct _DinoPluginsOmemoOmemoFileDecryptorDecryptFileData {
	int _state_;
	GObject* _source_object_;
	GAsyncResult* _res_;
	GTask* _async_result;
	DinoPluginsOmemoOmemoFileDecryptor* self;
	GInputStream* encrypted_stream;
	DinoEntitiesConversation* conversation;
	DinoEntitiesFileTransfer* file_transfer;
	DinoFileReceiveData* receive_data;
	GInputStream* result;
	DinoPluginsOmemoOmemoHttpFileReceiveData* omemo_http_receive_data;
	DinoPluginsOmemoOmemoHttpFileReceiveData* _tmp0_;
	DinoPluginsOmemoOmemoHttpFileReceiveData* _tmp1_;
	GMatchInfo* match_info;
	GRegex* _tmp2_;
	DinoPluginsOmemoOmemoHttpFileReceiveData* _tmp3_;
	const gchar* _tmp4_;
	GMatchInfo* _tmp5_;
	guint8* iv_and_key;
	GMatchInfo* _tmp6_;
	gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	gchar* _tmp10_;
	gint _tmp11_;
	guint8* _tmp12_;
	guint8* _tmp13_;
	gint _tmp13__length1;
	gint iv_and_key_length1;
	gint _iv_and_key_size_;
	guint8* iv;
	guint8* _tmp14_;
	gint _tmp14__length1;
	guint8* _tmp15_;
	gint _tmp15__length1;
	guint8* _tmp16_;
	gint _tmp16__length1;
	gint iv_length1;
	gint _iv_size_;
	guint8* key;
	guint8* _tmp17_;
	gint _tmp17__length1;
	guint8* _tmp18_;
	gint _tmp18__length1;
	guint8* _tmp19_;
	gint _tmp19__length1;
	guint8* _tmp20_;
	gint _tmp20__length1;
	gint key_length1;
	gint _key_size_;
	const gchar* _tmp21_;
	const gchar* _tmp22_;
	const gchar* _tmp23_;
	const gchar* _tmp24_;
	CryptoSymmetricCipher* cipher;
	CryptoSymmetricCipher* _tmp25_;
	CryptoSymmetricCipher* _tmp26_;
	guint8* _tmp27_;
	gint _tmp27__length1;
	CryptoSymmetricCipher* _tmp28_;
	guint8* _tmp29_;
	gint _tmp29__length1;
	CryptoSymmetricCipher* _tmp30_;
	CryptoSymmetricCipherDecrypter* _tmp31_;
	CryptoSymmetricCipherDecrypter* _tmp32_;
	GConverterInputStream* _tmp33_;
	GInputStream* _tmp34_;
	GError* e;
	GError* _tmp35_;
	const gchar* _tmp36_;
	gchar* _tmp37_;
	gchar* _tmp38_;
	GError* _tmp39_;
	GError* _tmp40_;
	GError* _vala1_e;
	GError* _tmp41_;
	const gchar* _tmp42_;
	gchar* _tmp43_;
	gchar* _tmp44_;
	GError* _tmp45_;
	GError* _tmp46_;
	GError* _inner_error0_;
};

static gpointer dino_plugins_omemo_omemo_http_file_receive_data_parent_class = NULL;
static gint DinoPluginsOmemoOmemoFileDecryptor_private_offset;
static gpointer dino_plugins_omemo_omemo_file_decryptor_parent_class = NULL;
static DinoFileDecryptorIface * dino_plugins_omemo_omemo_file_decryptor_dino_file_decryptor_parent_iface = NULL;

static void dino_plugins_omemo_omemo_http_file_receive_data_finalize (DinoFileReceiveData * obj);
static GType dino_plugins_omemo_omemo_http_file_receive_data_get_type_once (void);
static DinoEntitiesEncryption dino_plugins_omemo_omemo_file_decryptor_real_get_encryption (DinoFileDecryptor* base);
static DinoFileReceiveData* dino_plugins_omemo_omemo_file_decryptor_real_prepare_get_meta_info (DinoFileDecryptor* base,
                                                                                         DinoEntitiesConversation* conversation,
                                                                                         DinoEntitiesFileTransfer* file_transfer,
                                                                                         DinoFileReceiveData* receive_data);
static gchar* dino_plugins_omemo_omemo_file_decryptor_aesgcm_to_https_link (DinoPluginsOmemoOmemoFileDecryptor* self,
                                                                     const gchar* aesgcm_link);
static DinoFileMeta* dino_plugins_omemo_omemo_file_decryptor_real_prepare_download_file (DinoFileDecryptor* base,
                                                                                  DinoEntitiesConversation* conversation,
                                                                                  DinoEntitiesFileTransfer* file_transfer,
                                                                                  DinoFileReceiveData* receive_data,
                                                                                  DinoFileMeta* file_meta);
static gboolean dino_plugins_omemo_omemo_file_decryptor_real_can_decrypt_file (DinoFileDecryptor* base,
                                                                        DinoEntitiesConversation* conversation,
                                                                        DinoEntitiesFileTransfer* file_transfer,
                                                                        DinoFileReceiveData* receive_data);
static void dino_plugins_omemo_omemo_file_decryptor_real_decrypt_file_data_free (gpointer _data);
static void dino_plugins_omemo_omemo_file_decryptor_real_decrypt_file (DinoFileDecryptor* base,
                                                                GInputStream* encrypted_stream,
                                                                DinoEntitiesConversation* conversation,
                                                                DinoEntitiesFileTransfer* file_transfer,
                                                                DinoFileReceiveData* receive_data,
                                                                GAsyncReadyCallback _callback_,
                                                                gpointer _user_data_);
static gboolean dino_plugins_omemo_omemo_file_decryptor_real_decrypt_file_co (DinoPluginsOmemoOmemoFileDecryptorDecryptFileData* _data_);
static guint8* dino_plugins_omemo_omemo_file_decryptor_hex_to_bin (DinoPluginsOmemoOmemoFileDecryptor* self,
                                                            const gchar* hex,
                                                            gint* result_length1);
static guint8* _vala_array_dup2 (guint8* self,
                          gssize length);
static guint8* _vala_array_dup3 (guint8* self,
                          gssize length);
static void dino_plugins_omemo_omemo_file_decryptor_finalize (GObject * obj);
static GType dino_plugins_omemo_omemo_file_decryptor_get_type_once (void);
static void _vala_array_destroy (gpointer array,
                          gssize array_length,
                          GDestroyNotify destroy_func);
static void _vala_array_free (gpointer array,
                       gssize array_length,
                       GDestroyNotify destroy_func);
static gssize _vala_array_length (gpointer array);
static inline gpointer _vala_memdup2 (gconstpointer mem,
                        gsize byte_size);

static GRegex* _tmp_regex_0 = NULL;

DinoPluginsOmemoOmemoHttpFileReceiveData*
dino_plugins_omemo_omemo_http_file_receive_data_construct (GType object_type)
{
	DinoPluginsOmemoOmemoHttpFileReceiveData* self = NULL;
	self = (DinoPluginsOmemoOmemoHttpFileReceiveData*) dino_http_file_receive_data_construct (object_type);
	return self;
}

DinoPluginsOmemoOmemoHttpFileReceiveData*
dino_plugins_omemo_omemo_http_file_receive_data_new (void)
{
	return dino_plugins_omemo_omemo_http_file_receive_data_construct (DINO_PLUGINS_OMEMO_TYPE_OMEMO_HTTP_FILE_RECEIVE_DATA);
}

static void
dino_plugins_omemo_omemo_http_file_receive_data_class_init (DinoPluginsOmemoOmemoHttpFileReceiveDataClass * klass,
                                                            gpointer klass_data)
{
	dino_plugins_omemo_omemo_http_file_receive_data_parent_class = g_type_class_peek_parent (klass);
	((DinoFileReceiveDataClass *) klass)->finalize = dino_plugins_omemo_omemo_http_file_receive_data_finalize;
}

static void
dino_plugins_omemo_omemo_http_file_receive_data_instance_init (DinoPluginsOmemoOmemoHttpFileReceiveData * self,
                                                               gpointer klass)
{
}

static void
dino_plugins_omemo_omemo_http_file_receive_data_finalize (DinoFileReceiveData * obj)
{
	DinoPluginsOmemoOmemoHttpFileReceiveData * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OMEMO_TYPE_OMEMO_HTTP_FILE_RECEIVE_DATA, DinoPluginsOmemoOmemoHttpFileReceiveData);
	_g_free0 (self->original_url);
	DINO_FILE_RECEIVE_DATA_CLASS (dino_plugins_omemo_omemo_http_file_receive_data_parent_class)->finalize (obj);
}

static GType
dino_plugins_omemo_omemo_http_file_receive_data_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOmemoOmemoHttpFileReceiveDataClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_omemo_omemo_http_file_receive_data_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOmemoOmemoHttpFileReceiveData), 0, (GInstanceInitFunc) dino_plugins_omemo_omemo_http_file_receive_data_instance_init, NULL };
	GType dino_plugins_omemo_omemo_http_file_receive_data_type_id;
	dino_plugins_omemo_omemo_http_file_receive_data_type_id = g_type_register_static (DINO_TYPE_HTTP_FILE_RECEIVE_DATA, "DinoPluginsOmemoOmemoHttpFileReceiveData", &g_define_type_info, 0);
	return dino_plugins_omemo_omemo_http_file_receive_data_type_id;
}

GType
dino_plugins_omemo_omemo_http_file_receive_data_get_type (void)
{
	static volatile gsize dino_plugins_omemo_omemo_http_file_receive_data_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_omemo_omemo_http_file_receive_data_type_id__once)) {
		GType dino_plugins_omemo_omemo_http_file_receive_data_type_id;
		dino_plugins_omemo_omemo_http_file_receive_data_type_id = dino_plugins_omemo_omemo_http_file_receive_data_get_type_once ();
		g_once_init_leave (&dino_plugins_omemo_omemo_http_file_receive_data_type_id__once, dino_plugins_omemo_omemo_http_file_receive_data_type_id);
	}
	return dino_plugins_omemo_omemo_http_file_receive_data_type_id__once;
}

static inline gpointer
dino_plugins_omemo_omemo_file_decryptor_get_instance_private (DinoPluginsOmemoOmemoFileDecryptor* self)
{
	return G_STRUCT_MEMBER_P (self, DinoPluginsOmemoOmemoFileDecryptor_private_offset);
}

static inline GRegex*
_thread_safe_regex_init (GRegex** re,
                         const gchar * pattern,
                         GRegexCompileFlags compile_flags)
{
	if (g_once_init_enter ((volatile gsize*) re)) {
		GRegex* val = g_regex_new (pattern, compile_flags, 0, NULL);
		g_once_init_leave ((volatile gsize*) re, (gsize) val);
	}
	return *re;
}

static gpointer
_g_regex_ref0 (gpointer self)
{
	return self ? g_regex_ref (self) : NULL;
}

static DinoEntitiesEncryption
dino_plugins_omemo_omemo_file_decryptor_real_get_encryption (DinoFileDecryptor* base)
{
	DinoPluginsOmemoOmemoFileDecryptor * self;
	DinoEntitiesEncryption result;
	self = (DinoPluginsOmemoOmemoFileDecryptor*) base;
	result = DINO_ENTITIES_ENCRYPTION_OMEMO;
	return result;
}

static gpointer
_dino_file_receive_data_ref0 (gpointer self)
{
	return self ? dino_file_receive_data_ref (self) : NULL;
}

static DinoFileReceiveData*
dino_plugins_omemo_omemo_file_decryptor_real_prepare_get_meta_info (DinoFileDecryptor* base,
                                                                    DinoEntitiesConversation* conversation,
                                                                    DinoEntitiesFileTransfer* file_transfer,
                                                                    DinoFileReceiveData* receive_data)
{
	DinoPluginsOmemoOmemoFileDecryptor * self;
	DinoHttpFileReceiveData* http_receive_data = NULL;
	DinoHttpFileReceiveData* _tmp0_;
	DinoHttpFileReceiveData* _tmp1_;
	DinoPluginsOmemoOmemoHttpFileReceiveData* omemo_http_receive_data = NULL;
	DinoPluginsOmemoOmemoHttpFileReceiveData* _tmp3_;
	DinoPluginsOmemoOmemoHttpFileReceiveData* _tmp4_;
	DinoHttpFileReceiveData* _tmp5_;
	const gchar* _tmp6_;
	const gchar* _tmp7_;
	gchar* _tmp8_;
	gchar* _tmp9_;
	DinoPluginsOmemoOmemoHttpFileReceiveData* _tmp10_;
	DinoHttpFileReceiveData* _tmp11_;
	const gchar* _tmp12_;
	const gchar* _tmp13_;
	gchar* _tmp14_;
	DinoFileReceiveData* result;
	self = (DinoPluginsOmemoOmemoFileDecryptor*) base;
	g_return_val_if_fail (conversation != NULL, NULL);
	g_return_val_if_fail (file_transfer != NULL, NULL);
	g_return_val_if_fail (receive_data != NULL, NULL);
	_tmp0_ = _dino_file_receive_data_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (receive_data, DINO_TYPE_HTTP_FILE_RECEIVE_DATA) ? ((DinoHttpFileReceiveData*) receive_data) : NULL);
	http_receive_data = _tmp0_;
	_tmp1_ = http_receive_data;
	if (_tmp1_ == NULL) {
		_vala_assert (FALSE, "false");
	}
	if ((DINO_PLUGINS_OMEMO_IS_OMEMO_HTTP_FILE_RECEIVE_DATA (receive_data) ? ((DinoPluginsOmemoOmemoHttpFileReceiveData*) receive_data) : NULL) != NULL) {
		DinoFileReceiveData* _tmp2_;
		_tmp2_ = _dino_file_receive_data_ref0 (receive_data);
		result = _tmp2_;
		_dino_file_receive_data_unref0 (http_receive_data);
		return result;
	}
	_tmp3_ = dino_plugins_omemo_omemo_http_file_receive_data_new ();
	omemo_http_receive_data = _tmp3_;
	_tmp4_ = omemo_http_receive_data;
	_tmp5_ = http_receive_data;
	_tmp6_ = dino_http_file_receive_data_get_url (_tmp5_);
	_tmp7_ = _tmp6_;
	_tmp8_ = dino_plugins_omemo_omemo_file_decryptor_aesgcm_to_https_link (self, _tmp7_);
	_tmp9_ = _tmp8_;
	dino_http_file_receive_data_set_url ((DinoHttpFileReceiveData*) _tmp4_, _tmp9_);
	_g_free0 (_tmp9_);
	_tmp10_ = omemo_http_receive_data;
	_tmp11_ = http_receive_data;
	_tmp12_ = dino_http_file_receive_data_get_url (_tmp11_);
	_tmp13_ = _tmp12_;
	_tmp14_ = g_strdup (_tmp13_);
	_g_free0 (_tmp10_->original_url);
	_tmp10_->original_url = _tmp14_;
	result = (DinoFileReceiveData*) omemo_http_receive_data;
	_dino_file_receive_data_unref0 (http_receive_data);
	return result;
}

static gpointer
_dino_file_meta_ref0 (gpointer self)
{
	return self ? dino_file_meta_ref (self) : NULL;
}

static DinoFileMeta*
dino_plugins_omemo_omemo_file_decryptor_real_prepare_download_file (DinoFileDecryptor* base,
                                                                    DinoEntitiesConversation* conversation,
                                                                    DinoEntitiesFileTransfer* file_transfer,
                                                                    DinoFileReceiveData* receive_data,
                                                                    DinoFileMeta* file_meta)
{
	DinoPluginsOmemoOmemoFileDecryptor * self;
	const gchar* _tmp0_;
	DinoFileMeta* _tmp7_;
	DinoFileMeta* result;
	self = (DinoPluginsOmemoOmemoFileDecryptor*) base;
	g_return_val_if_fail (conversation != NULL, NULL);
	g_return_val_if_fail (file_transfer != NULL, NULL);
	g_return_val_if_fail (receive_data != NULL, NULL);
	g_return_val_if_fail (file_meta != NULL, NULL);
	_tmp0_ = file_meta->file_name;
	if (_tmp0_ != NULL) {
		const gchar* _tmp1_;
		gchar** _tmp2_;
		gchar** _tmp3_;
		gchar** _tmp4_;
		gint _tmp4__length1;
		const gchar* _tmp5_;
		gchar* _tmp6_;
		_tmp1_ = file_meta->file_name;
		_tmp3_ = _tmp2_ = g_strsplit (_tmp1_, "#", 0);
		_tmp4_ = _tmp3_;
		_tmp4__length1 = _vala_array_length (_tmp2_);
		_tmp5_ = _tmp4_[0];
		_tmp6_ = g_strdup (_tmp5_);
		_g_free0 (file_meta->file_name);
		file_meta->file_name = _tmp6_;
		_tmp4_ = (_vala_array_free (_tmp4_, _tmp4__length1, (GDestroyNotify) g_free), NULL);
	}
	_tmp7_ = _dino_file_meta_ref0 (file_meta);
	result = _tmp7_;
	return result;
}

static gboolean
dino_plugins_omemo_omemo_file_decryptor_real_can_decrypt_file (DinoFileDecryptor* base,
                                                               DinoEntitiesConversation* conversation,
                                                               DinoEntitiesFileTransfer* file_transfer,
                                                               DinoFileReceiveData* receive_data)
{
	DinoPluginsOmemoOmemoFileDecryptor * self;
	DinoHttpFileReceiveData* http_file_receive = NULL;
	DinoHttpFileReceiveData* _tmp0_;
	DinoHttpFileReceiveData* _tmp1_;
	gboolean _tmp2_ = FALSE;
	GRegex* _tmp3_;
	DinoHttpFileReceiveData* _tmp4_;
	const gchar* _tmp5_;
	const gchar* _tmp6_;
	gboolean result;
	self = (DinoPluginsOmemoOmemoFileDecryptor*) base;
	g_return_val_if_fail (conversation != NULL, FALSE);
	g_return_val_if_fail (file_transfer != NULL, FALSE);
	g_return_val_if_fail (receive_data != NULL, FALSE);
	_tmp0_ = _dino_file_receive_data_ref0 (G_TYPE_CHECK_INSTANCE_TYPE (receive_data, DINO_TYPE_HTTP_FILE_RECEIVE_DATA) ? ((DinoHttpFileReceiveData*) receive_data) : NULL);
	http_file_receive = _tmp0_;
	_tmp1_ = http_file_receive;
	if (_tmp1_ == NULL) {
		result = FALSE;
		_dino_file_receive_data_unref0 (http_file_receive);
		return result;
	}
	_tmp3_ = self->priv->url_regex;
	_tmp4_ = http_file_receive;
	_tmp5_ = dino_http_file_receive_data_get_url (_tmp4_);
	_tmp6_ = _tmp5_;
	if (g_regex_match (_tmp3_, _tmp6_, 0, NULL)) {
		_tmp2_ = TRUE;
	} else {
		_tmp2_ = (DINO_PLUGINS_OMEMO_IS_OMEMO_HTTP_FILE_RECEIVE_DATA (receive_data) ? ((DinoPluginsOmemoOmemoHttpFileReceiveData*) receive_data) : NULL) != NULL;
	}
	result = _tmp2_;
	_dino_file_receive_data_unref0 (http_file_receive);
	return result;
}

static void
dino_plugins_omemo_omemo_file_decryptor_real_decrypt_file_data_free (gpointer _data)
{
	DinoPluginsOmemoOmemoFileDecryptorDecryptFileData* _data_;
	_data_ = _data;
	_g_object_unref0 (_data_->encrypted_stream);
	_g_object_unref0 (_data_->conversation);
	_g_object_unref0 (_data_->file_transfer);
	_dino_file_receive_data_unref0 (_data_->receive_data);
	_g_object_unref0 (_data_->result);
	_g_object_unref0 (_data_->self);
	g_slice_free (DinoPluginsOmemoOmemoFileDecryptorDecryptFileData, _data_);
}

static gpointer
_g_object_ref0 (gpointer self)
{
	return self ? g_object_ref (self) : NULL;
}

static void
dino_plugins_omemo_omemo_file_decryptor_real_decrypt_file (DinoFileDecryptor* base,
                                                           GInputStream* encrypted_stream,
                                                           DinoEntitiesConversation* conversation,
                                                           DinoEntitiesFileTransfer* file_transfer,
                                                           DinoFileReceiveData* receive_data,
                                                           GAsyncReadyCallback _callback_,
                                                           gpointer _user_data_)
{
	DinoPluginsOmemoOmemoFileDecryptor * self;
	DinoPluginsOmemoOmemoFileDecryptorDecryptFileData* _data_;
	DinoPluginsOmemoOmemoFileDecryptor* _tmp0_;
	GInputStream* _tmp1_;
	DinoEntitiesConversation* _tmp2_;
	DinoEntitiesFileTransfer* _tmp3_;
	DinoFileReceiveData* _tmp4_;
	g_return_if_fail (encrypted_stream != NULL);
	g_return_if_fail (conversation != NULL);
	g_return_if_fail (file_transfer != NULL);
	g_return_if_fail (receive_data != NULL);
	self = (DinoPluginsOmemoOmemoFileDecryptor*) base;
	_data_ = g_slice_new0 (DinoPluginsOmemoOmemoFileDecryptorDecryptFileData);
	_data_->_async_result = g_task_new (G_OBJECT (self), NULL, _callback_, _user_data_);
	g_task_set_task_data (_data_->_async_result, _data_, dino_plugins_omemo_omemo_file_decryptor_real_decrypt_file_data_free);
	_tmp0_ = _g_object_ref0 (self);
	_data_->self = _tmp0_;
	_tmp1_ = _g_object_ref0 (encrypted_stream);
	_g_object_unref0 (_data_->encrypted_stream);
	_data_->encrypted_stream = _tmp1_;
	_tmp2_ = _g_object_ref0 (conversation);
	_g_object_unref0 (_data_->conversation);
	_data_->conversation = _tmp2_;
	_tmp3_ = _g_object_ref0 (file_transfer);
	_g_object_unref0 (_data_->file_transfer);
	_data_->file_transfer = _tmp3_;
	_tmp4_ = _dino_file_receive_data_ref0 (receive_data);
	_dino_file_receive_data_unref0 (_data_->receive_data);
	_data_->receive_data = _tmp4_;
	dino_plugins_omemo_omemo_file_decryptor_real_decrypt_file_co (_data_);
}

static GInputStream*
dino_plugins_omemo_omemo_file_decryptor_decrypt_file_finish (DinoFileDecryptor* base,
                                                             GAsyncResult* _res_,
                                                             GError** error)
{
	GInputStream* result;
	DinoPluginsOmemoOmemoFileDecryptorDecryptFileData* _data_;
	_data_ = g_task_propagate_pointer (G_TASK (_res_), error);
	if (NULL == _data_) {
		return NULL;
	}
	result = _data_->result;
	_data_->result = NULL;
	return result;
}

static guint8*
_vala_array_dup2 (guint8* self,
                  gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (guint8));
	}
	return NULL;
}

static guint8*
_vala_array_dup3 (guint8* self,
                  gssize length)
{
	if (length > 0) {
		return _vala_memdup2 (self, length * sizeof (guint8));
	}
	return NULL;
}

static gboolean
dino_plugins_omemo_omemo_file_decryptor_real_decrypt_file_co (DinoPluginsOmemoOmemoFileDecryptorDecryptFileData* _data_)
{
	static const guint KEY_SIZE = (guint) 32;
	switch (_data_->_state_) {
		case 0:
		goto _state_0;
		default:
		g_assert_not_reached ();
	}
	_state_0:
	{
		_data_->_tmp0_ = _dino_file_receive_data_ref0 (DINO_PLUGINS_OMEMO_IS_OMEMO_HTTP_FILE_RECEIVE_DATA (_data_->receive_data) ? ((DinoPluginsOmemoOmemoHttpFileReceiveData*) _data_->receive_data) : NULL);
		_data_->omemo_http_receive_data = _data_->_tmp0_;
		_data_->_tmp1_ = _data_->omemo_http_receive_data;
		if (_data_->_tmp1_ == NULL) {
			_vala_assert (FALSE, "false");
		}
		_data_->_tmp2_ = _data_->self->priv->url_regex;
		_data_->_tmp3_ = _data_->omemo_http_receive_data;
		_data_->_tmp4_ = _data_->_tmp3_->original_url;
		_data_->_tmp5_ = NULL;
		g_regex_match (_data_->_tmp2_, _data_->_tmp4_, 0, &_data_->_tmp5_);
		_g_match_info_unref0 (_data_->match_info);
		_data_->match_info = _data_->_tmp5_;
		_data_->_tmp6_ = _data_->match_info;
		_data_->_tmp7_ = g_match_info_fetch (_data_->_tmp6_, 2);
		_data_->_tmp8_ = _data_->_tmp7_;
		_data_->_tmp9_ = g_utf8_strup (_data_->_tmp8_, (gssize) -1);
		_data_->_tmp10_ = _data_->_tmp9_;
		_data_->_tmp11_ = 0;
		_data_->_tmp12_ = dino_plugins_omemo_omemo_file_decryptor_hex_to_bin (_data_->self, _data_->_tmp10_, &_data_->_tmp11_);
		_data_->_tmp13_ = _data_->_tmp12_;
		_data_->_tmp13__length1 = _data_->_tmp11_;
		_g_free0 (_data_->_tmp10_);
		_g_free0 (_data_->_tmp8_);
		_data_->iv_and_key = _data_->_tmp13_;
		_data_->iv_and_key_length1 = _data_->_tmp13__length1;
		_data_->_iv_and_key_size_ = _data_->iv_and_key_length1;
		_data_->_tmp14_ = _data_->iv_and_key;
		_data_->_tmp14__length1 = _data_->iv_and_key_length1;
		_data_->_tmp15_ = _data_->iv_and_key;
		_data_->_tmp15__length1 = _data_->iv_and_key_length1;
		_data_->_tmp16_ = (_data_->_tmp14_ != NULL) ? _vala_array_dup2 (_data_->_tmp14_ + 0, ((gint) (_data_->_tmp15__length1 - KEY_SIZE)) - 0) : _data_->_tmp14_;
		_data_->_tmp16__length1 = ((gint) (_data_->_tmp15__length1 - KEY_SIZE)) - 0;
		_data_->iv = _data_->_tmp16_;
		_data_->iv_length1 = _data_->_tmp16__length1;
		_data_->_iv_size_ = _data_->iv_length1;
		_data_->_tmp17_ = _data_->iv_and_key;
		_data_->_tmp17__length1 = _data_->iv_and_key_length1;
		_data_->_tmp18_ = _data_->iv_and_key;
		_data_->_tmp18__length1 = _data_->iv_and_key_length1;
		_data_->_tmp19_ = _data_->iv_and_key;
		_data_->_tmp19__length1 = _data_->iv_and_key_length1;
		_data_->_tmp20_ = (_data_->_tmp17_ != NULL) ? _vala_array_dup3 (_data_->_tmp17_ + ((gint) (_data_->_tmp18__length1 - KEY_SIZE)), _data_->_tmp19__length1 - ((gint) (_data_->_tmp18__length1 - KEY_SIZE))) : _data_->_tmp17_;
		_data_->_tmp20__length1 = _data_->_tmp19__length1 - ((gint) (_data_->_tmp18__length1 - KEY_SIZE));
		_data_->key = _data_->_tmp20_;
		_data_->key_length1 = _data_->_tmp20__length1;
		_data_->_key_size_ = _data_->key_length1;
		dino_entities_file_transfer_set_encryption (_data_->file_transfer, DINO_ENTITIES_ENCRYPTION_OMEMO);
		_data_->_tmp21_ = dino_entities_file_transfer_get_file_name (_data_->file_transfer);
		_data_->_tmp22_ = _data_->_tmp21_;
		_data_->_tmp23_ = dino_entities_file_transfer_get_server_file_name (_data_->file_transfer);
		_data_->_tmp24_ = _data_->_tmp23_;
		g_debug ("file_decryptor.vala:60: Decrypting file %s from %s", _data_->_tmp22_, _data_->_tmp24_);
		_data_->_tmp25_ = crypto_symmetric_cipher_new ("AES-GCM", &_data_->_inner_error0_);
		_data_->cipher = _data_->_tmp25_;
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_data_->key = (g_free (_data_->key), NULL);
			_data_->iv = (g_free (_data_->iv), NULL);
			_data_->iv_and_key = (g_free (_data_->iv_and_key), NULL);
			_g_match_info_unref0 (_data_->match_info);
			_dino_file_receive_data_unref0 (_data_->omemo_http_receive_data);
			if (_data_->_inner_error0_->domain == CRYPTO_ERROR) {
				goto __catch0_crypto_error;
			}
			goto __catch0_g_error;
		}
		_data_->_tmp26_ = _data_->cipher;
		_data_->_tmp27_ = _data_->key;
		_data_->_tmp27__length1 = _data_->key_length1;
		crypto_symmetric_cipher_set_key (_data_->_tmp26_, _data_->_tmp27_, (gint) _data_->_tmp27__length1, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_crypto_symmetric_cipher_unref0 (_data_->cipher);
			_data_->key = (g_free (_data_->key), NULL);
			_data_->iv = (g_free (_data_->iv), NULL);
			_data_->iv_and_key = (g_free (_data_->iv_and_key), NULL);
			_g_match_info_unref0 (_data_->match_info);
			_dino_file_receive_data_unref0 (_data_->omemo_http_receive_data);
			if (_data_->_inner_error0_->domain == CRYPTO_ERROR) {
				goto __catch0_crypto_error;
			}
			goto __catch0_g_error;
		}
		_data_->_tmp28_ = _data_->cipher;
		_data_->_tmp29_ = _data_->iv;
		_data_->_tmp29__length1 = _data_->iv_length1;
		crypto_symmetric_cipher_set_iv (_data_->_tmp28_, _data_->_tmp29_, (gint) _data_->_tmp29__length1, &_data_->_inner_error0_);
		if (G_UNLIKELY (_data_->_inner_error0_ != NULL)) {
			_crypto_symmetric_cipher_unref0 (_data_->cipher);
			_data_->key = (g_free (_data_->key), NULL);
			_data_->iv = (g_free (_data_->iv), NULL);
			_data_->iv_and_key = (g_free (_data_->iv_and_key), NULL);
			_g_match_info_unref0 (_data_->match_info);
			_dino_file_receive_data_unref0 (_data_->omemo_http_receive_data);
			if (_data_->_inner_error0_->domain == CRYPTO_ERROR) {
				goto __catch0_crypto_error;
			}
			goto __catch0_g_error;
		}
		_data_->_tmp30_ = _data_->cipher;
		_data_->cipher = NULL;
		_data_->_tmp31_ = crypto_symmetric_cipher_decrypter_new (_data_->_tmp30_, (gsize) 16);
		_data_->_tmp32_ = _data_->_tmp31_;
		_data_->_tmp33_ = (GConverterInputStream*) g_converter_input_stream_new (_data_->encrypted_stream, (GConverter*) _data_->_tmp32_);
		_data_->_tmp34_ = (GInputStream*) _data_->_tmp33_;
		_g_object_unref0 (_data_->_tmp32_);
		_data_->result = _data_->_tmp34_;
		_crypto_symmetric_cipher_unref0 (_data_->cipher);
		_data_->key = (g_free (_data_->key), NULL);
		_data_->iv = (g_free (_data_->iv), NULL);
		_data_->iv_and_key = (g_free (_data_->iv_and_key), NULL);
		_g_match_info_unref0 (_data_->match_info);
		_dino_file_receive_data_unref0 (_data_->omemo_http_receive_data);
		g_task_return_pointer (_data_->_async_result, _data_, NULL);
		if (_data_->_state_ != 0) {
			while (!g_task_get_completed (_data_->_async_result)) {
				g_main_context_iteration (g_task_get_context (_data_->_async_result), TRUE);
			}
		}
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
	goto __finally0;
	__catch0_crypto_error:
	{
		_data_->e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp35_ = _data_->e;
		_data_->_tmp36_ = _data_->_tmp35_->message;
		_data_->_tmp37_ = g_strdup_printf ("OMEMO file decryption error: %s", _data_->_tmp36_);
		_data_->_tmp38_ = _data_->_tmp37_;
		_data_->_tmp39_ = g_error_new_literal (DINO_FILE_RECEIVE_ERROR, DINO_FILE_RECEIVE_ERROR_DECRYPTION_FAILED, _data_->_tmp38_);
		_data_->_tmp40_ = _data_->_tmp39_;
		_g_free0 (_data_->_tmp38_);
		_data_->_inner_error0_ = _data_->_tmp40_;
		_g_error_free0 (_data_->e);
		goto __finally0;
	}
	goto __finally0;
	__catch0_g_error:
	{
		_data_->_vala1_e = _data_->_inner_error0_;
		_data_->_inner_error0_ = NULL;
		_data_->_tmp41_ = _data_->_vala1_e;
		_data_->_tmp42_ = _data_->_tmp41_->message;
		_data_->_tmp43_ = g_strdup_printf ("OMEMO file decryption error: %s", _data_->_tmp42_);
		_data_->_tmp44_ = _data_->_tmp43_;
		_data_->_tmp45_ = g_error_new_literal (DINO_FILE_RECEIVE_ERROR, DINO_FILE_RECEIVE_ERROR_DECRYPTION_FAILED, _data_->_tmp44_);
		_data_->_tmp46_ = _data_->_tmp45_;
		_g_free0 (_data_->_tmp44_);
		_data_->_inner_error0_ = _data_->_tmp46_;
		_g_error_free0 (_data_->_vala1_e);
		goto __finally0;
	}
	__finally0:
	if (_data_->_inner_error0_->domain == DINO_FILE_RECEIVE_ERROR) {
		g_task_return_error (_data_->_async_result, _data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	} else {
		g_critical ("file %s: line %d: uncaught error: %s (%s, %d)", __FILE__, __LINE__, _data_->_inner_error0_->message, g_quark_to_string (_data_->_inner_error0_->domain), _data_->_inner_error0_->code);
		g_clear_error (&_data_->_inner_error0_);
		g_object_unref (_data_->_async_result);
		return FALSE;
	}
}

static gint
string_index_of_char (const gchar* self,
                      gunichar c,
                      gint start_index)
{
	gchar* _result_ = NULL;
	gchar* _tmp0_;
	gchar* _tmp1_;
	gint result;
	g_return_val_if_fail (self != NULL, -1);
	_tmp0_ = g_utf8_strchr (((gchar*) self) + start_index, (gssize) -1, c);
	_result_ = _tmp0_;
	_tmp1_ = _result_;
	if (_tmp1_ != NULL) {
		gchar* _tmp2_;
		_tmp2_ = _result_;
		result = (gint) (_tmp2_ - ((gchar*) self));
		return result;
	} else {
		result = -1;
		return result;
	}
}

static gchar
string_get (const gchar* self,
            glong index)
{
	gchar _tmp0_;
	gchar result;
	g_return_val_if_fail (self != NULL, '\0');
	_tmp0_ = ((gchar*) self)[index];
	result = _tmp0_;
	return result;
}

static guint8*
dino_plugins_omemo_omemo_file_decryptor_hex_to_bin (DinoPluginsOmemoOmemoFileDecryptor* self,
                                                    const gchar* hex,
                                                    gint* result_length1)
{
	guint8* bin = NULL;
	gint _tmp0_;
	gint _tmp1_;
	guint8* _tmp2_;
	gint bin_length1;
	gint _bin_size_;
	static const char HEX[] = "0123456789ABCDEF";
	guint8* _tmp8_;
	gint _tmp8__length1;
	guint8* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (hex != NULL, NULL);
	_tmp0_ = strlen (hex);
	_tmp1_ = _tmp0_;
	_tmp2_ = g_new0 (guint8, _tmp1_ / 2);
	bin = _tmp2_;
	bin_length1 = _tmp1_ / 2;
	_bin_size_ = bin_length1;
	{
		gint i = 0;
		i = 0;
		{
			gboolean _tmp3_ = FALSE;
			_tmp3_ = TRUE;
			while (TRUE) {
				gint _tmp5_;
				gint _tmp6_;
				guint8* _tmp7_;
				gint _tmp7__length1;
				if (!_tmp3_) {
					gint _tmp4_;
					_tmp4_ = i;
					i = _tmp4_ + 1;
				}
				_tmp3_ = FALSE;
				_tmp5_ = strlen (hex);
				_tmp6_ = _tmp5_;
				if (!(i < (_tmp6_ / 2))) {
					break;
				}
				_tmp7_ = bin;
				_tmp7__length1 = bin_length1;
				_tmp7_[i] = ((guint8) (string_index_of_char (HEX, (gunichar) string_get (hex, (glong) (i * 2)), 0) << 4)) | string_index_of_char (HEX, (gunichar) string_get (hex, (glong) ((i * 2) + 1)), 0);
			}
		}
	}
	_tmp8_ = bin;
	_tmp8__length1 = bin_length1;
	if (result_length1) {
		*result_length1 = _tmp8__length1;
	}
	result = _tmp8_;
	return result;
}

static gchar*
dino_plugins_omemo_omemo_file_decryptor_aesgcm_to_https_link (DinoPluginsOmemoOmemoFileDecryptor* self,
                                                              const gchar* aesgcm_link)
{
	GMatchInfo* match_info = NULL;
	GRegex* _tmp0_;
	GMatchInfo* _tmp1_ = NULL;
	gchar* _tmp2_;
	gchar* _tmp3_;
	gchar* _tmp4_;
	gchar* _tmp5_;
	gchar* result;
	g_return_val_if_fail (self != NULL, NULL);
	g_return_val_if_fail (aesgcm_link != NULL, NULL);
	_tmp0_ = self->priv->url_regex;
	g_regex_match (_tmp0_, aesgcm_link, 0, &_tmp1_);
	_g_match_info_unref0 (match_info);
	match_info = _tmp1_;
	_tmp2_ = g_match_info_fetch (match_info, 1);
	_tmp3_ = _tmp2_;
	_tmp4_ = g_strconcat ("https://", _tmp3_, NULL);
	_tmp5_ = _tmp4_;
	_g_free0 (_tmp3_);
	result = _tmp5_;
	_g_match_info_unref0 (match_info);
	return result;
}

DinoPluginsOmemoOmemoFileDecryptor*
dino_plugins_omemo_omemo_file_decryptor_construct (GType object_type)
{
	DinoPluginsOmemoOmemoFileDecryptor * self = NULL;
	self = (DinoPluginsOmemoOmemoFileDecryptor*) g_object_new (object_type, NULL);
	return self;
}

DinoPluginsOmemoOmemoFileDecryptor*
dino_plugins_omemo_omemo_file_decryptor_new (void)
{
	return dino_plugins_omemo_omemo_file_decryptor_construct (DINO_PLUGINS_OMEMO_TYPE_OMEMO_FILE_DECRYPTOR);
}

static void
dino_plugins_omemo_omemo_file_decryptor_class_init (DinoPluginsOmemoOmemoFileDecryptorClass * klass,
                                                    gpointer klass_data)
{
	dino_plugins_omemo_omemo_file_decryptor_parent_class = g_type_class_peek_parent (klass);
	g_type_class_adjust_private_offset (klass, &DinoPluginsOmemoOmemoFileDecryptor_private_offset);
	G_OBJECT_CLASS (klass)->finalize = dino_plugins_omemo_omemo_file_decryptor_finalize;
}

static void
dino_plugins_omemo_omemo_file_decryptor_dino_file_decryptor_interface_init (DinoFileDecryptorIface * iface,
                                                                            gpointer iface_data)
{
	dino_plugins_omemo_omemo_file_decryptor_dino_file_decryptor_parent_iface = g_type_interface_peek_parent (iface);
	iface->get_encryption = (DinoEntitiesEncryption (*) (DinoFileDecryptor*)) dino_plugins_omemo_omemo_file_decryptor_real_get_encryption;
	iface->prepare_get_meta_info = (DinoFileReceiveData* (*) (DinoFileDecryptor*, DinoEntitiesConversation*, DinoEntitiesFileTransfer*, DinoFileReceiveData*)) dino_plugins_omemo_omemo_file_decryptor_real_prepare_get_meta_info;
	iface->prepare_download_file = (DinoFileMeta* (*) (DinoFileDecryptor*, DinoEntitiesConversation*, DinoEntitiesFileTransfer*, DinoFileReceiveData*, DinoFileMeta*)) dino_plugins_omemo_omemo_file_decryptor_real_prepare_download_file;
	iface->can_decrypt_file = (gboolean (*) (DinoFileDecryptor*, DinoEntitiesConversation*, DinoEntitiesFileTransfer*, DinoFileReceiveData*)) dino_plugins_omemo_omemo_file_decryptor_real_can_decrypt_file;
	iface->decrypt_file = (void (*) (DinoFileDecryptor*, GInputStream*, DinoEntitiesConversation*, DinoEntitiesFileTransfer*, DinoFileReceiveData*, GAsyncReadyCallback, gpointer)) dino_plugins_omemo_omemo_file_decryptor_real_decrypt_file;
	iface->decrypt_file_finish = (GInputStream* (*) (DinoFileDecryptor*, GAsyncResult*, GError**)) dino_plugins_omemo_omemo_file_decryptor_decrypt_file_finish;
}

static void
dino_plugins_omemo_omemo_file_decryptor_instance_init (DinoPluginsOmemoOmemoFileDecryptor * self,
                                                       gpointer klass)
{
	GRegex* _tmp0_;
	self->priv = dino_plugins_omemo_omemo_file_decryptor_get_instance_private (self);
	_tmp0_ = _g_regex_ref0 (_thread_safe_regex_init (&_tmp_regex_0, "^aesgcm:\\/\\/(.*)#(([A-Fa-f0-9]{2}){48}|([A-Fa-f0-9]{2}){44})$", 0));
	self->priv->url_regex = _tmp0_;
}

static void
dino_plugins_omemo_omemo_file_decryptor_finalize (GObject * obj)
{
	DinoPluginsOmemoOmemoFileDecryptor * self;
	self = G_TYPE_CHECK_INSTANCE_CAST (obj, DINO_PLUGINS_OMEMO_TYPE_OMEMO_FILE_DECRYPTOR, DinoPluginsOmemoOmemoFileDecryptor);
	_g_regex_unref0 (self->priv->url_regex);
	G_OBJECT_CLASS (dino_plugins_omemo_omemo_file_decryptor_parent_class)->finalize (obj);
}

static GType
dino_plugins_omemo_omemo_file_decryptor_get_type_once (void)
{
	static const GTypeInfo g_define_type_info = { sizeof (DinoPluginsOmemoOmemoFileDecryptorClass), (GBaseInitFunc) NULL, (GBaseFinalizeFunc) NULL, (GClassInitFunc) dino_plugins_omemo_omemo_file_decryptor_class_init, (GClassFinalizeFunc) NULL, NULL, sizeof (DinoPluginsOmemoOmemoFileDecryptor), 0, (GInstanceInitFunc) dino_plugins_omemo_omemo_file_decryptor_instance_init, NULL };
	static const GInterfaceInfo dino_file_decryptor_info = { (GInterfaceInitFunc) dino_plugins_omemo_omemo_file_decryptor_dino_file_decryptor_interface_init, (GInterfaceFinalizeFunc) NULL, NULL};
	GType dino_plugins_omemo_omemo_file_decryptor_type_id;
	dino_plugins_omemo_omemo_file_decryptor_type_id = g_type_register_static (G_TYPE_OBJECT, "DinoPluginsOmemoOmemoFileDecryptor", &g_define_type_info, 0);
	g_type_add_interface_static (dino_plugins_omemo_omemo_file_decryptor_type_id, DINO_TYPE_FILE_DECRYPTOR, &dino_file_decryptor_info);
	DinoPluginsOmemoOmemoFileDecryptor_private_offset = g_type_add_instance_private (dino_plugins_omemo_omemo_file_decryptor_type_id, sizeof (DinoPluginsOmemoOmemoFileDecryptorPrivate));
	return dino_plugins_omemo_omemo_file_decryptor_type_id;
}

GType
dino_plugins_omemo_omemo_file_decryptor_get_type (void)
{
	static volatile gsize dino_plugins_omemo_omemo_file_decryptor_type_id__once = 0;
	if (g_once_init_enter (&dino_plugins_omemo_omemo_file_decryptor_type_id__once)) {
		GType dino_plugins_omemo_omemo_file_decryptor_type_id;
		dino_plugins_omemo_omemo_file_decryptor_type_id = dino_plugins_omemo_omemo_file_decryptor_get_type_once ();
		g_once_init_leave (&dino_plugins_omemo_omemo_file_decryptor_type_id__once, dino_plugins_omemo_omemo_file_decryptor_type_id);
	}
	return dino_plugins_omemo_omemo_file_decryptor_type_id__once;
}

static void
_vala_array_destroy (gpointer array,
                     gssize array_length,
                     GDestroyNotify destroy_func)
{
	if ((array != NULL) && (destroy_func != NULL)) {
		gssize i;
		for (i = 0; i < array_length; i = i + 1) {
			if (((gpointer*) array)[i] != NULL) {
				destroy_func (((gpointer*) array)[i]);
			}
		}
	}
}

static void
_vala_array_free (gpointer array,
                  gssize array_length,
                  GDestroyNotify destroy_func)
{
	_vala_array_destroy (array, array_length, destroy_func);
	g_free (array);
}

static gssize
_vala_array_length (gpointer array)
{
	gssize length;
	length = 0;
	if (array) {
		while (((gpointer*) array)[length]) {
			length++;
		}
	}
	return length;
}

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;
}

