aboutsummaryrefslogtreecommitdiff
path: root/src/zklaim/plugin_reclaim_attribute_zklaim.c
diff options
context:
space:
mode:
authorSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>2018-08-16 18:48:04 +0200
committerSchanzenbach, Martin <martin.schanzenbach@aisec.fraunhofer.de>2018-08-16 18:48:04 +0200
commit1940b899b3620786b0265144ab756a3f05bcc8b0 (patch)
tree92e16378a5b6f6211bf937597b429b6c092b04bb /src/zklaim/plugin_reclaim_attribute_zklaim.c
parent5ef8d3c6cbe7970bc9c9e54b4ab23c8727200b15 (diff)
downloadgnunet-1940b899b3620786b0265144ab756a3f05bcc8b0.tar.gz
gnunet-1940b899b3620786b0265144ab756a3f05bcc8b0.zip
start zklaim service
Diffstat (limited to 'src/zklaim/plugin_reclaim_attribute_zklaim.c')
-rw-r--r--src/zklaim/plugin_reclaim_attribute_zklaim.c181
1 files changed, 181 insertions, 0 deletions
diff --git a/src/zklaim/plugin_reclaim_attribute_zklaim.c b/src/zklaim/plugin_reclaim_attribute_zklaim.c
new file mode 100644
index 000000000..a79576cb1
--- /dev/null
+++ b/src/zklaim/plugin_reclaim_attribute_zklaim.c
@@ -0,0 +1,181 @@
1/*
2 This file is part of GNUnet
3 Copyright (C) 2013, 2014, 2016 GNUnet e.V.
4
5 GNUnet is free software: you can redistribute it and/or modify it
6 under the terms of the GNU Affero General Public License as published
7 by the Free Software Foundation, either version 3 of the License,
8 or (at your option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Affero General Public License for more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/**
20 * @file zklaim/plugin_reclaim_attribute_zklaim.c
21 * @brief identity attribute plugin to provide the API for ZKlaims
22 *
23 * @author Martin Schanzenbach
24 */
25#include "platform.h"
26#include "gnunet_util_lib.h"
27#include "gnunet_reclaim_attribute_plugin.h"
28#include <inttypes.h>
29
30
31/**
32 * Convert the 'value' of an attribute to a string.
33 *
34 * @param cls closure, unused
35 * @param type type of the attribute
36 * @param data value in binary encoding
37 * @param data_size number of bytes in @a data
38 * @return NULL on error, otherwise human-readable representation of the value
39 */
40static char *
41zklaim_value_to_string (void *cls,
42 uint32_t type,
43 const void *data,
44 size_t data_size)
45{
46
47 switch (type)
48 {
49 case GNUNET_RECLAIM_ATTRIBUTE_TYPE_ZKLAIM:
50 return GNUNET_strndup (data, data_size);
51 default:
52 return NULL;
53 }
54}
55
56
57/**
58 * Convert human-readable version of a 'value' of an attribute to the binary
59 * representation.
60 *
61 * @param cls closure, unused
62 * @param type type of the attribute
63 * @param s human-readable string
64 * @param data set to value in binary encoding (will be allocated)
65 * @param data_size set to number of bytes in @a data
66 * @return #GNUNET_OK on success
67 */
68static int
69zklaim_string_to_value (void *cls,
70 uint32_t type,
71 const char *s,
72 void **data,
73 size_t *data_size)
74{
75 if (NULL == s)
76 return GNUNET_SYSERR;
77 switch (type)
78 {
79
80 case GNUNET_RECLAIM_ATTRIBUTE_TYPE_ZKLAIM:
81 *data = GNUNET_strdup (s);
82 *data_size = strlen (s);
83 return GNUNET_OK;
84 default:
85 return GNUNET_SYSERR;
86 }
87}
88
89
90/**
91 * Mapping of attribute type numbers to human-readable
92 * attribute type names.
93 */
94static struct {
95 const char *name;
96 uint32_t number;
97} zklaim_name_map[] = {
98 { "ZKLAIM", GNUNET_RECLAIM_ATTRIBUTE_TYPE_ZKLAIM },
99 { NULL, UINT32_MAX }
100};
101
102
103/**
104 * Convert a type name to the corresponding number.
105 *
106 * @param cls closure, unused
107 * @param zklaim_typename name to convert
108 * @return corresponding number, UINT32_MAX on error
109 */
110static uint32_t
111zklaim_typename_to_number (void *cls,
112 const char *zklaim_typename)
113{
114 unsigned int i;
115
116 i=0;
117 while ( (NULL != zklaim_name_map[i].name) &&
118 (0 != strcasecmp (zklaim_typename,
119 zklaim_name_map[i].name)) )
120 i++;
121 return zklaim_name_map[i].number;
122}
123
124
125/**
126 * Convert a type number (i.e. 1) to the corresponding type string
127 *
128 * @param cls closure, unused
129 * @param type number of a type to convert
130 * @return corresponding typestring, NULL on error
131 */
132static const char *
133zklaim_number_to_typename (void *cls,
134 uint32_t type)
135{
136 unsigned int i;
137
138 i=0;
139 while ( (NULL != zklaim_name_map[i].name) &&
140 (type != zklaim_name_map[i].number) )
141 i++;
142 return zklaim_name_map[i].name;
143}
144
145
146/**
147 * Entry point for the plugin.
148 *
149 * @param cls NULL
150 * @return the exported block API
151 */
152void *
153libgnunet_plugin_reclaim_attribute_zklaim_init (void *cls)
154{
155 struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions *api;
156
157 api = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions);
158 api->value_to_string = &zklaim_value_to_string;
159 api->string_to_value = &zklaim_string_to_value;
160 api->typename_to_number = &zklaim_typename_to_number;
161 api->number_to_typename = &zklaim_number_to_typename;
162 return api;
163}
164
165
166/**
167 * Exit point from the plugin.
168 *
169 * @param cls the return value from #libgnunet_plugin_block_test_init()
170 * @return NULL
171 */
172void *
173libgnunet_plugin_reclaim_attribute_zklaim_done (void *cls)
174{
175 struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions *api = cls;
176
177 GNUNET_free (api);
178 return NULL;
179}
180
181/* end of plugin_reclaim_attribute_type_zklaim.c */