1 /*
2  * gnome-keyring
3  *
4  * Copyright (C) 2018 Red Hat, Inc.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU Lesser General Public License as
8  * published by the Free Software Foundation; either version 2.1 of
9  * the License, or (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this program; if not, see
18  * <http://www.gnu.org/licenses/>.
19  *
20  * Author: Daiki Ueno
21  */
22 
23 #include <glib.h>
24 #include "egg/egg-buffer.h"
25 
26 void prepare_request_identities (EggBuffer *req);
27 void prepare_add_identity (EggBuffer *req);
28 void prepare_remove_identity (EggBuffer *req);
29 void prepare_remove_all_identities (EggBuffer *req);
30 void prepare_sign_request (EggBuffer *req);
31 
32 void check_identities_answer (EggBuffer *resp, gsize count);
33 void check_sign_response (EggBuffer *resp);
34 void check_response (EggBuffer *resp, unsigned char expected);
35 void check_success (EggBuffer *resp);
36 void check_failure (EggBuffer *resp);
37 
38 GBytes *public_key_from_file (const gchar *path, gchar **comment);
39 
40 #define DEFINE_CALL_FUNCS(Test, Call)			\
41 static inline void					\
42 call_request_identities (Test *test, gsize count)	\
43 {							\
44 	egg_buffer_reset (&test->req);			\
45 	egg_buffer_reset (&test->resp);			\
46 							\
47 	prepare_request_identities (&test->req);	\
48 	Call (test);					\
49 	check_identities_answer (&test->resp, count);	\
50 }							\
51 							\
52 static inline void					\
53 call_add_identity (Test *test)				\
54 {							\
55 	egg_buffer_reset (&test->req);			\
56 	egg_buffer_reset (&test->resp);			\
57 							\
58 	prepare_add_identity (&test->req);		\
59 	Call (test);					\
60 	check_success (&test->resp);			\
61 }							\
62 							\
63 static inline void					\
64 call_remove_identity (Test *test)			\
65 {							\
66 	egg_buffer_reset (&test->req);			\
67 	egg_buffer_reset (&test->resp);			\
68 							\
69 	prepare_remove_identity (&test->req);		\
70 	Call (test);					\
71 	check_success (&test->resp);			\
72 }							\
73 							\
74 static inline void					\
75 call_remove_all_identities (Test *test)			\
76 {							\
77 	egg_buffer_reset (&test->req);			\
78 	egg_buffer_reset (&test->resp);			\
79 							\
80 	prepare_remove_all_identities (&test->req);	\
81 	Call (test);					\
82 	check_success (&test->resp);			\
83 }							\
84 							\
85 static inline void					\
86 call_sign (Test *test)					\
87 {							\
88 	egg_buffer_reset (&test->req);			\
89 	egg_buffer_reset (&test->resp);			\
90 							\
91 	prepare_sign_request (&test->req);		\
92 	Call (test);					\
93 	check_sign_response (&test->resp);		\
94 }
95