aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c')
-rw-r--r--src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c109
1 files changed, 109 insertions, 0 deletions
diff --git a/src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c b/src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c
index bb60909d9..ade2a27bb 100644
--- a/src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c
+++ b/src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c
@@ -90,6 +90,63 @@ gnuid_string_to_value (void *cls,
90 } 90 }
91} 91}
92 92
93/**
94 * Convert the 'value' of an attestation to a string.
95 *
96 * @param cls closure, unused
97 * @param type type of the attestation
98 * @param data value in binary encoding
99 * @param data_size number of bytes in @a data
100 * @return NULL on error, otherwise human-readable representation of the value
101 */
102static char *
103gnuid_value_to_string_attest (void *cls,
104 uint32_t type,
105 const void *data,
106 size_t data_size)
107{
108 switch (type)
109 {
110 case GNUNET_RECLAIM_ATTESTATION_TYPE_JWT:
111 return GNUNET_strndup (data, data_size);
112
113 default:
114 return NULL;
115 }
116}
117
118
119/**
120 * Convert human-readable version of a 'value' of an attestation to the binary
121 * representation.
122 *
123 * @param cls closure, unused
124 * @param type type of the attestation
125 * @param s human-readable string
126 * @param data set to value in binary encoding (will be allocated)
127 * @param data_size set to number of bytes in @a data
128 * @return #GNUNET_OK on success
129 */
130static int
131gnuid_string_to_value_attest (void *cls,
132 uint32_t type,
133 const char *s,
134 void **data,
135 size_t *data_size)
136{
137 if (NULL == s)
138 return GNUNET_SYSERR;
139 switch (type)
140 {
141 case GNUNET_RECLAIM_ATTESTATION_TYPE_JWT:
142 *data = GNUNET_strdup (s);
143 *data_size = strlen (s);
144 return GNUNET_OK;
145
146 default:
147 return GNUNET_SYSERR;
148 }
149}
93 150
94/** 151/**
95 * Mapping of attribute type numbers to human-readable 152 * Mapping of attribute type numbers to human-readable
@@ -102,6 +159,16 @@ static struct
102} gnuid_name_map[] = { { "STRING", GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING }, 159} gnuid_name_map[] = { { "STRING", GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING },
103 { NULL, UINT32_MAX } }; 160 { NULL, UINT32_MAX } };
104 161
162/**
163 * Mapping of attestation type numbers to human-readable
164 * attestation type names.
165 */
166static struct
167{
168 const char *name;
169 uint32_t number;
170} gnuid_attest_name_map[] = { { "JWT", GNUNET_RECLAIM_ATTESTATION_TYPE_JWT },
171 { NULL, UINT32_MAX } };
105 172
106/** 173/**
107 * Convert a type name to the corresponding number. 174 * Convert a type name to the corresponding number.
@@ -141,6 +208,44 @@ gnuid_number_to_typename (void *cls, uint32_t type)
141 return gnuid_name_map[i].name; 208 return gnuid_name_map[i].name;
142} 209}
143 210
211/**
212 * Convert a type name to the corresponding number.
213 *
214 * @param cls closure, unused
215 * @param gnuid_typename name to convert
216 * @return corresponding number, UINT32_MAX on error
217 */
218static uint32_t
219gnuid_typename_to_number_attest (void *cls, const char *gnuid_typename)
220{
221 unsigned int i;
222
223 i = 0;
224 while ((NULL != gnuid_attest_name_map[i].name) &&
225 (0 != strcasecmp (gnuid_typename, gnuid_attest_name_map[i].name)))
226 i++;
227 return gnuid_attest_name_map[i].number;
228}
229
230/**
231 * Convert a type number (i.e. 1) to the corresponding type string
232 *
233 * @param cls closure, unused
234 * @param type number of a type to convert
235 * @return corresponding typestring, NULL on error
236 */
237static const char *
238gnuid_number_to_typename_attest (void *cls, uint32_t type)
239{
240 unsigned int i;
241
242 i = 0;
243 while ((NULL != gnuid_attest_name_map[i].name) && (type !=
244 gnuid_attest_name_map[i].
245 number))
246 i++;
247 return gnuid_attest_name_map[i].name;
248}
144 249
145/** 250/**
146 * Entry point for the plugin. 251 * Entry point for the plugin.
@@ -158,6 +263,10 @@ libgnunet_plugin_reclaim_attribute_gnuid_init (void *cls)
158 api->string_to_value = &gnuid_string_to_value; 263 api->string_to_value = &gnuid_string_to_value;
159 api->typename_to_number = &gnuid_typename_to_number; 264 api->typename_to_number = &gnuid_typename_to_number;
160 api->number_to_typename = &gnuid_number_to_typename; 265 api->number_to_typename = &gnuid_number_to_typename;
266 api->value_to_string_attest = &gnuid_value_to_string_attest;
267 api->string_to_value_attest = &gnuid_string_to_value_attest;
268 api->typename_to_number_attest = &gnuid_typename_to_number_attest;
269 api->number_to_typename_attest = &gnuid_number_to_typename_attest;
161 return api; 270 return api;
162} 271}
163 272