summaryrefslogtreecommitdiff
path: root/egg
diff options
context:
space:
mode:
authorDaiki Ueno <dueno@src.gnome.org>2018-02-16 16:20:45 +0100
committerDaiki Ueno <dueno@src.gnome.org>2018-03-04 10:25:00 +0100
commit9ec7de589a32e9f8409c5e2a04efb75a11cc1620 (patch)
tree9b85e5bbe6516c46a149f13be3bdaeabf82581f1 /egg
parent66288946435307fff618ca8cef5bb6bca7b8c209 (diff)
downloadgnome-keyring-9ec7de589a32e9f8409c5e2a04efb75a11cc1620.tar.gz
egg: Import mock-interaction.[ch] from gcr
https://bugzilla.gnome.org/show_bug.cgi?id=775981
Diffstat (limited to 'egg')
-rw-r--r--egg/Makefile.am4
-rw-r--r--egg/mock-interaction.c96
-rw-r--r--egg/mock-interaction.h42
3 files changed, 141 insertions, 1 deletions
diff --git a/egg/Makefile.am b/egg/Makefile.am
index 9e081eb7..d7205ab6 100644
--- a/egg/Makefile.am
+++ b/egg/Makefile.am
@@ -36,6 +36,7 @@ libegg_la_SOURCES = \
egg/egg-symkey.c egg/egg-symkey.h \
egg/egg-testing.c egg/egg-testing.h \
egg/egg-timegm.c egg/egg-timegm.h \
+ egg/mock-interaction.c egg/mock-interaction.h \
egg/egg-asn1-defs.h \
egg/pk.asn.h egg/pkix.asn.h \
$(NULL)
@@ -92,7 +93,8 @@ libegg_hex_la_LIBS = \
$(GLIB_LIBS)
libegg_test_la_SOURCES = \
- egg/egg-testing.c egg/egg-testing.h
+ egg/egg-testing.c egg/egg-testing.h \
+ egg/mock-interaction.c egg/mock-interaction.h
libegg_test_la_CFLAGS = \
$(GLIB_CFLAGS)
diff --git a/egg/mock-interaction.c b/egg/mock-interaction.c
new file mode 100644
index 00000000..c431454b
--- /dev/null
+++ b/egg/mock-interaction.c
@@ -0,0 +1,96 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* mock-interaction.c
+
+ Copyright (C) 2011 Collabora Ltd
+
+ The Gnome Keyring Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Keyring 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ see <http://www.gnu.org/licenses/>.
+
+ Author: Stef Walter <stefw@collabora.co.uk>
+*/
+
+#include "config.h"
+
+#include "mock-interaction.h"
+
+#define MOCK_INTERACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), MOCK_TYPE_INTERACTION, MockInteraction))
+#define MOCK_IS_INTERACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), MOCK_TYPE_INTERACTION))
+#define MOCK_INTERACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), MOCK_TYPE_INTERACTION, MockInteractionClass))
+
+typedef struct _MockInteractionClass MockInteractionClass;
+
+struct _MockInteraction {
+ GTlsInteraction interaction;
+ gchar *password;
+};
+
+struct _MockInteractionClass {
+ GTlsInteractionClass parent;
+};
+
+G_DEFINE_TYPE (MockInteraction, mock_interaction, G_TYPE_TLS_INTERACTION);
+
+static void
+mock_interaction_init (MockInteraction *self)
+{
+
+}
+
+static void
+mock_interaction_finalize (GObject *obj)
+{
+ MockInteraction *self = MOCK_INTERACTION (obj);
+
+ g_free (self->password);
+
+ G_OBJECT_CLASS (mock_interaction_parent_class)->dispose (obj);
+}
+
+static GTlsInteractionResult
+mock_interaction_ask_password (GTlsInteraction *interaction,
+ GTlsPassword *password,
+ GCancellable *cancellable,
+ GError **error)
+{
+ MockInteraction *self = MOCK_INTERACTION (interaction);
+
+ if (self->password) {
+ g_tls_password_set_value (password, (const guchar *)self->password, -1);
+ return G_TLS_INTERACTION_HANDLED;
+ } else {
+ return G_TLS_INTERACTION_UNHANDLED;
+ }
+}
+
+static void
+mock_interaction_class_init (MockInteractionClass *klass)
+{
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ GTlsInteractionClass *interaction_class = G_TLS_INTERACTION_CLASS (klass);
+
+ object_class->finalize = mock_interaction_finalize;
+
+ interaction_class->ask_password = mock_interaction_ask_password;
+}
+
+GTlsInteraction *
+mock_interaction_new (const gchar *password)
+{
+ MockInteraction *result;
+
+ result = g_object_new (MOCK_TYPE_INTERACTION, NULL);
+ result->password = g_strdup (password);
+
+ return G_TLS_INTERACTION (result);
+}
diff --git a/egg/mock-interaction.h b/egg/mock-interaction.h
new file mode 100644
index 00000000..5053cd22
--- /dev/null
+++ b/egg/mock-interaction.h
@@ -0,0 +1,42 @@
+/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */
+/* mock-interaction.h
+
+ Copyright (C) 2011 Collabora Ltd
+
+ The Gnome Keyring Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Library General Public License as
+ published by the Free Software Foundation; either version 2 of the
+ License, or (at your option) any later version.
+
+ The Gnome Keyring 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
+ Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public
+ License along with the Gnome Library; see the file COPYING.LIB. If not,
+ see <http://www.gnu.org/licenses/>.
+
+ Author: Stef Walter <stefw@collabora.co.uk>
+*/
+
+#ifndef MOCK_INTERACTION_H
+#define MOCK_INTERACTION_H
+
+#include <gio/gio.h>
+
+G_BEGIN_DECLS
+
+#define MOCK_TYPE_INTERACTION (mock_interaction_get_type ())
+#define MOCK_INTERACTION(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), MOCK_TYPE_INTERACTION, MockInteraction))
+#define MOCK_IS_INTERACTION(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), MOCK_TYPE_INTERACTION))
+
+typedef struct _MockInteraction MockInteraction;
+
+GType mock_interaction_get_type (void) G_GNUC_CONST;
+
+GTlsInteraction * mock_interaction_new (const gchar *password);
+
+G_END_DECLS
+
+#endif /* MOCK_INTERACTION_H */