diff options
author | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-02-04 18:42:04 +0100 |
---|---|---|
committer | Schanzenbach, Martin <mschanzenbach@posteo.de> | 2020-02-09 20:38:10 +0100 |
commit | 55f6d26b7424d660c99bc89f3677b20294e87a27 (patch) | |
tree | a8080fdcf0d9688c154417e50c58055e364f8b6b /src/reclaim-attribute | |
parent | 5b6bb2ce4d60635b2af950d72b45f12686fd5218 (diff) | |
download | gnunet-55f6d26b7424d660c99bc89f3677b20294e87a27.tar.gz gnunet-55f6d26b7424d660c99bc89f3677b20294e87a27.zip |
Refactoring reclaim attestations
Diffstat (limited to 'src/reclaim-attribute')
-rw-r--r-- | src/reclaim-attribute/Makefile.am | 21 | ||||
-rw-r--r-- | src/reclaim-attribute/plugin_reclaim_attestation_jwt.c | 182 | ||||
-rw-r--r-- | src/reclaim-attribute/plugin_reclaim_attribute_basic.c | 180 | ||||
-rw-r--r-- | src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c | 290 | ||||
-rw-r--r-- | src/reclaim-attribute/reclaim_attestation.c | 502 | ||||
-rw-r--r-- | src/reclaim-attribute/reclaim_attestation.h | 64 | ||||
-rw-r--r-- | src/reclaim-attribute/reclaim_attribute.c | 720 | ||||
-rw-r--r-- | src/reclaim-attribute/reclaim_attribute.h | 34 |
8 files changed, 1049 insertions, 944 deletions
diff --git a/src/reclaim-attribute/Makefile.am b/src/reclaim-attribute/Makefile.am index 490e77398..a1c220340 100644 --- a/src/reclaim-attribute/Makefile.am +++ b/src/reclaim-attribute/Makefile.am | |||
@@ -17,7 +17,8 @@ lib_LTLIBRARIES = \ | |||
17 | 17 | ||
18 | libgnunetreclaimattribute_la_SOURCES = \ | 18 | libgnunetreclaimattribute_la_SOURCES = \ |
19 | reclaim_attribute.h \ | 19 | reclaim_attribute.h \ |
20 | reclaim_attribute.c | 20 | reclaim_attribute.c \ |
21 | reclaim_attestation.c | ||
21 | libgnunetreclaimattribute_la_LIBADD = \ | 22 | libgnunetreclaimattribute_la_LIBADD = \ |
22 | $(top_builddir)/src/util/libgnunetutil.la \ | 23 | $(top_builddir)/src/util/libgnunetutil.la \ |
23 | $(GN_LIBINTL) | 24 | $(GN_LIBINTL) |
@@ -27,15 +28,23 @@ libgnunetreclaimattribute_la_LDFLAGS = \ | |||
27 | 28 | ||
28 | 29 | ||
29 | plugin_LTLIBRARIES = \ | 30 | plugin_LTLIBRARIES = \ |
30 | libgnunet_plugin_reclaim_attribute_gnuid.la | 31 | libgnunet_plugin_reclaim_attribute_basic.la \ |
32 | libgnunet_plugin_reclaim_attestation_jwt.la | ||
31 | 33 | ||
32 | 34 | ||
33 | libgnunet_plugin_reclaim_attribute_gnuid_la_SOURCES = \ | 35 | libgnunet_plugin_reclaim_attribute_basic_la_SOURCES = \ |
34 | plugin_reclaim_attribute_gnuid.c | 36 | plugin_reclaim_attribute_basic.c |
35 | libgnunet_plugin_reclaim_attribute_gnuid_la_LIBADD = \ | 37 | libgnunet_plugin_reclaim_attribute_basic_la_LIBADD = \ |
36 | $(top_builddir)/src/util/libgnunetutil.la \ | 38 | $(top_builddir)/src/util/libgnunetutil.la \ |
37 | $(LTLIBINTL) | 39 | $(LTLIBINTL) |
38 | libgnunet_plugin_reclaim_attribute_gnuid_la_LDFLAGS = \ | 40 | libgnunet_plugin_reclaim_attribute_basic_la_LDFLAGS = \ |
39 | $(GN_PLUGIN_LDFLAGS) | 41 | $(GN_PLUGIN_LDFLAGS) |
40 | 42 | ||
43 | libgnunet_plugin_reclaim_attestation_jwt_la_SOURCES = \ | ||
44 | plugin_reclaim_attestation_jwt.c | ||
45 | libgnunet_plugin_reclaim_attestation_jwt_la_LIBADD = \ | ||
46 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
47 | $(LTLIBINTL) | ||
48 | libgnunet_plugin_reclaim_attestation_jwt_la_LDFLAGS = \ | ||
49 | $(GN_PLUGIN_LDFLAGS) | ||
41 | 50 | ||
diff --git a/src/reclaim-attribute/plugin_reclaim_attestation_jwt.c b/src/reclaim-attribute/plugin_reclaim_attestation_jwt.c new file mode 100644 index 000000000..eb6043a66 --- /dev/null +++ b/src/reclaim-attribute/plugin_reclaim_attestation_jwt.c | |||
@@ -0,0 +1,182 @@ | |||
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 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file reclaim-attribute/plugin_reclaim_attestation_gnuid.c | ||
23 | * @brief reclaim-attribute-plugin-gnuid attribute plugin to provide the API for | ||
24 | * fundamental | ||
25 | * attribute types. | ||
26 | * | ||
27 | * @author Martin Schanzenbach | ||
28 | */ | ||
29 | #include "platform.h" | ||
30 | #include "gnunet_util_lib.h" | ||
31 | #include "gnunet_reclaim_plugin.h" | ||
32 | #include <inttypes.h> | ||
33 | |||
34 | |||
35 | /** | ||
36 | * Convert the 'value' of an attestation to a string. | ||
37 | * | ||
38 | * @param cls closure, unused | ||
39 | * @param type type of the attestation | ||
40 | * @param data value in binary encoding | ||
41 | * @param data_size number of bytes in @a data | ||
42 | * @return NULL on error, otherwise human-readable representation of the value | ||
43 | */ | ||
44 | static char * | ||
45 | jwt_value_to_string (void *cls, | ||
46 | uint32_t type, | ||
47 | const void *data, | ||
48 | size_t data_size) | ||
49 | { | ||
50 | switch (type) | ||
51 | { | ||
52 | case GNUNET_RECLAIM_ATTESTATION_TYPE_JWT: | ||
53 | return GNUNET_strndup (data, data_size); | ||
54 | |||
55 | default: | ||
56 | return NULL; | ||
57 | } | ||
58 | } | ||
59 | |||
60 | |||
61 | /** | ||
62 | * Convert human-readable version of a 'value' of an attestation to the binary | ||
63 | * representation. | ||
64 | * | ||
65 | * @param cls closure, unused | ||
66 | * @param type type of the attestation | ||
67 | * @param s human-readable string | ||
68 | * @param data set to value in binary encoding (will be allocated) | ||
69 | * @param data_size set to number of bytes in @a data | ||
70 | * @return #GNUNET_OK on success | ||
71 | */ | ||
72 | static int | ||
73 | jwt_string_to_value (void *cls, | ||
74 | uint32_t type, | ||
75 | const char *s, | ||
76 | void **data, | ||
77 | size_t *data_size) | ||
78 | { | ||
79 | if (NULL == s) | ||
80 | return GNUNET_SYSERR; | ||
81 | switch (type) | ||
82 | { | ||
83 | case GNUNET_RECLAIM_ATTESTATION_TYPE_JWT: | ||
84 | *data = GNUNET_strdup (s); | ||
85 | *data_size = strlen (s); | ||
86 | return GNUNET_OK; | ||
87 | |||
88 | default: | ||
89 | return GNUNET_SYSERR; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | |||
94 | /** | ||
95 | * Mapping of attestation type numbers to human-readable | ||
96 | * attestation type names. | ||
97 | */ | ||
98 | static struct | ||
99 | { | ||
100 | const char *name; | ||
101 | uint32_t number; | ||
102 | } jwt_attest_name_map[] = { { "JWT", GNUNET_RECLAIM_ATTESTATION_TYPE_JWT }, | ||
103 | { NULL, UINT32_MAX } }; | ||
104 | |||
105 | /** | ||
106 | * Convert a type name to the corresponding number. | ||
107 | * | ||
108 | * @param cls closure, unused | ||
109 | * @param jwt_typename name to convert | ||
110 | * @return corresponding number, UINT32_MAX on error | ||
111 | */ | ||
112 | static uint32_t | ||
113 | jwt_typename_to_number (void *cls, const char *jwt_typename) | ||
114 | { | ||
115 | unsigned int i; | ||
116 | |||
117 | i = 0; | ||
118 | while ((NULL != jwt_attest_name_map[i].name) && | ||
119 | (0 != strcasecmp (jwt_typename, jwt_attest_name_map[i].name))) | ||
120 | i++; | ||
121 | return jwt_attest_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 | */ | ||
132 | static const char * | ||
133 | jwt_number_to_typename (void *cls, uint32_t type) | ||
134 | { | ||
135 | unsigned int i; | ||
136 | |||
137 | i = 0; | ||
138 | while ((NULL != jwt_attest_name_map[i].name) && (type != | ||
139 | jwt_attest_name_map[i]. | ||
140 | number)) | ||
141 | i++; | ||
142 | return jwt_attest_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 | */ | ||
152 | void * | ||
153 | libgnunet_plugin_reclaim_attestation_jwt_init (void *cls) | ||
154 | { | ||
155 | struct GNUNET_RECLAIM_AttestationPluginFunctions *api; | ||
156 | |||
157 | api = GNUNET_new (struct GNUNET_RECLAIM_AttestationPluginFunctions); | ||
158 | api->value_to_string = &jwt_value_to_string; | ||
159 | api->string_to_value = &jwt_string_to_value; | ||
160 | api->typename_to_number = &jwt_typename_to_number; | ||
161 | api->number_to_typename = &jwt_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 | */ | ||
172 | void * | ||
173 | libgnunet_plugin_reclaim_attestation_jwt_done (void *cls) | ||
174 | { | ||
175 | struct GNUNET_RECLAIM_AttestationPluginFunctions *api = cls; | ||
176 | |||
177 | GNUNET_free (api); | ||
178 | return NULL; | ||
179 | } | ||
180 | |||
181 | |||
182 | /* end of plugin_reclaim_attestation_type_gnuid.c */ | ||
diff --git a/src/reclaim-attribute/plugin_reclaim_attribute_basic.c b/src/reclaim-attribute/plugin_reclaim_attribute_basic.c new file mode 100644 index 000000000..47fdd5f11 --- /dev/null +++ b/src/reclaim-attribute/plugin_reclaim_attribute_basic.c | |||
@@ -0,0 +1,180 @@ | |||
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 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file reclaim-attribute/plugin_reclaim_attribute_gnuid.c | ||
23 | * @brief reclaim-attribute-plugin-gnuid attribute plugin to provide the API for | ||
24 | * fundamental | ||
25 | * attribute types. | ||
26 | * | ||
27 | * @author Martin Schanzenbach | ||
28 | */ | ||
29 | #include "platform.h" | ||
30 | #include "gnunet_util_lib.h" | ||
31 | #include "gnunet_reclaim_plugin.h" | ||
32 | #include <inttypes.h> | ||
33 | |||
34 | |||
35 | /** | ||
36 | * Convert the 'value' of an attribute to a string. | ||
37 | * | ||
38 | * @param cls closure, unused | ||
39 | * @param type type of the attribute | ||
40 | * @param data value in binary encoding | ||
41 | * @param data_size number of bytes in @a data | ||
42 | * @return NULL on error, otherwise human-readable representation of the value | ||
43 | */ | ||
44 | static char * | ||
45 | basic_value_to_string (void *cls, | ||
46 | uint32_t type, | ||
47 | const void *data, | ||
48 | size_t data_size) | ||
49 | { | ||
50 | switch (type) | ||
51 | { | ||
52 | case GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING: | ||
53 | return GNUNET_strndup (data, data_size); | ||
54 | |||
55 | default: | ||
56 | return NULL; | ||
57 | } | ||
58 | } | ||
59 | |||
60 | |||
61 | /** | ||
62 | * Convert human-readable version of a 'value' of an attribute to the binary | ||
63 | * representation. | ||
64 | * | ||
65 | * @param cls closure, unused | ||
66 | * @param type type of the attribute | ||
67 | * @param s human-readable string | ||
68 | * @param data set to value in binary encoding (will be allocated) | ||
69 | * @param data_size set to number of bytes in @a data | ||
70 | * @return #GNUNET_OK on success | ||
71 | */ | ||
72 | static int | ||
73 | basic_string_to_value (void *cls, | ||
74 | uint32_t type, | ||
75 | const char *s, | ||
76 | void **data, | ||
77 | size_t *data_size) | ||
78 | { | ||
79 | if (NULL == s) | ||
80 | return GNUNET_SYSERR; | ||
81 | switch (type) | ||
82 | { | ||
83 | case GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING: | ||
84 | *data = GNUNET_strdup (s); | ||
85 | *data_size = strlen (s); | ||
86 | return GNUNET_OK; | ||
87 | |||
88 | default: | ||
89 | return GNUNET_SYSERR; | ||
90 | } | ||
91 | } | ||
92 | |||
93 | /** | ||
94 | * Mapping of attribute type numbers to human-readable | ||
95 | * attribute type names. | ||
96 | */ | ||
97 | static struct | ||
98 | { | ||
99 | const char *name; | ||
100 | uint32_t number; | ||
101 | } basic_name_map[] = { { "STRING", GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING }, | ||
102 | { NULL, UINT32_MAX } }; | ||
103 | |||
104 | |||
105 | /** | ||
106 | * Convert a type name to the corresponding number. | ||
107 | * | ||
108 | * @param cls closure, unused | ||
109 | * @param basic_typename name to convert | ||
110 | * @return corresponding number, UINT32_MAX on error | ||
111 | */ | ||
112 | static uint32_t | ||
113 | basic_typename_to_number (void *cls, const char *basic_typename) | ||
114 | { | ||
115 | unsigned int i; | ||
116 | |||
117 | i = 0; | ||
118 | while ((NULL != basic_name_map[i].name) && | ||
119 | (0 != strcasecmp (basic_typename, basic_name_map[i].name))) | ||
120 | i++; | ||
121 | return basic_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 | */ | ||
132 | static const char * | ||
133 | basic_number_to_typename (void *cls, uint32_t type) | ||
134 | { | ||
135 | unsigned int i; | ||
136 | |||
137 | i = 0; | ||
138 | while ((NULL != basic_name_map[i].name) && (type != basic_name_map[i].number)) | ||
139 | i++; | ||
140 | return basic_name_map[i].name; | ||
141 | } | ||
142 | |||
143 | |||
144 | /** | ||
145 | * Entry point for the plugin. | ||
146 | * | ||
147 | * @param cls NULL | ||
148 | * @return the exported block API | ||
149 | */ | ||
150 | void * | ||
151 | libgnunet_plugin_reclaim_attribute_basic_init (void *cls) | ||
152 | { | ||
153 | struct GNUNET_RECLAIM_AttributePluginFunctions *api; | ||
154 | |||
155 | api = GNUNET_new (struct GNUNET_RECLAIM_AttributePluginFunctions); | ||
156 | api->value_to_string = &basic_value_to_string; | ||
157 | api->string_to_value = &basic_string_to_value; | ||
158 | api->typename_to_number = &basic_typename_to_number; | ||
159 | api->number_to_typename = &basic_number_to_typename; | ||
160 | return api; | ||
161 | } | ||
162 | |||
163 | |||
164 | /** | ||
165 | * Exit point from the plugin. | ||
166 | * | ||
167 | * @param cls the return value from #libgnunet_plugin_block_test_init() | ||
168 | * @return NULL | ||
169 | */ | ||
170 | void * | ||
171 | libgnunet_plugin_reclaim_attribute_basic_done (void *cls) | ||
172 | { | ||
173 | struct GNUNET_RECLAIM_AttributePluginFunctions *api = cls; | ||
174 | |||
175 | GNUNET_free (api); | ||
176 | return NULL; | ||
177 | } | ||
178 | |||
179 | |||
180 | /* end of plugin_reclaim_attribute_type_gnuid.c */ | ||
diff --git a/src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c b/src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c deleted file mode 100644 index ade2a27bb..000000000 --- a/src/reclaim-attribute/plugin_reclaim_attribute_gnuid.c +++ /dev/null | |||
@@ -1,290 +0,0 @@ | |||
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 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file reclaim-attribute/plugin_reclaim_attribute_gnuid.c | ||
23 | * @brief reclaim-attribute-plugin-gnuid attribute plugin to provide the API for | ||
24 | * fundamental | ||
25 | * attribute types. | ||
26 | * | ||
27 | * @author Martin Schanzenbach | ||
28 | */ | ||
29 | #include "platform.h" | ||
30 | #include "gnunet_util_lib.h" | ||
31 | #include "gnunet_reclaim_attribute_plugin.h" | ||
32 | #include <inttypes.h> | ||
33 | |||
34 | |||
35 | /** | ||
36 | * Convert the 'value' of an attribute to a string. | ||
37 | * | ||
38 | * @param cls closure, unused | ||
39 | * @param type type of the attribute | ||
40 | * @param data value in binary encoding | ||
41 | * @param data_size number of bytes in @a data | ||
42 | * @return NULL on error, otherwise human-readable representation of the value | ||
43 | */ | ||
44 | static char * | ||
45 | gnuid_value_to_string (void *cls, | ||
46 | uint32_t type, | ||
47 | const void *data, | ||
48 | size_t data_size) | ||
49 | { | ||
50 | switch (type) | ||
51 | { | ||
52 | case GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING: | ||
53 | return GNUNET_strndup (data, data_size); | ||
54 | |||
55 | default: | ||
56 | return NULL; | ||
57 | } | ||
58 | } | ||
59 | |||
60 | |||
61 | /** | ||
62 | * Convert human-readable version of a 'value' of an attribute to the binary | ||
63 | * representation. | ||
64 | * | ||
65 | * @param cls closure, unused | ||
66 | * @param type type of the attribute | ||
67 | * @param s human-readable string | ||
68 | * @param data set to value in binary encoding (will be allocated) | ||
69 | * @param data_size set to number of bytes in @a data | ||
70 | * @return #GNUNET_OK on success | ||
71 | */ | ||
72 | static int | ||
73 | gnuid_string_to_value (void *cls, | ||
74 | uint32_t type, | ||
75 | const char *s, | ||
76 | void **data, | ||
77 | size_t *data_size) | ||
78 | { | ||
79 | if (NULL == s) | ||
80 | return GNUNET_SYSERR; | ||
81 | switch (type) | ||
82 | { | ||
83 | case GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING: | ||
84 | *data = GNUNET_strdup (s); | ||
85 | *data_size = strlen (s); | ||
86 | return GNUNET_OK; | ||
87 | |||
88 | default: | ||
89 | return GNUNET_SYSERR; | ||
90 | } | ||
91 | } | ||
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 | */ | ||
102 | static char * | ||
103 | gnuid_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 | */ | ||
130 | static int | ||
131 | gnuid_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 | } | ||
150 | |||
151 | /** | ||
152 | * Mapping of attribute type numbers to human-readable | ||
153 | * attribute type names. | ||
154 | */ | ||
155 | static struct | ||
156 | { | ||
157 | const char *name; | ||
158 | uint32_t number; | ||
159 | } gnuid_name_map[] = { { "STRING", GNUNET_RECLAIM_ATTRIBUTE_TYPE_STRING }, | ||
160 | { NULL, UINT32_MAX } }; | ||
161 | |||
162 | /** | ||
163 | * Mapping of attestation type numbers to human-readable | ||
164 | * attestation type names. | ||
165 | */ | ||
166 | static 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 } }; | ||
172 | |||
173 | /** | ||
174 | * Convert a type name to the corresponding number. | ||
175 | * | ||
176 | * @param cls closure, unused | ||
177 | * @param gnuid_typename name to convert | ||
178 | * @return corresponding number, UINT32_MAX on error | ||
179 | */ | ||
180 | static uint32_t | ||
181 | gnuid_typename_to_number (void *cls, const char *gnuid_typename) | ||
182 | { | ||
183 | unsigned int i; | ||
184 | |||
185 | i = 0; | ||
186 | while ((NULL != gnuid_name_map[i].name) && | ||
187 | (0 != strcasecmp (gnuid_typename, gnuid_name_map[i].name))) | ||
188 | i++; | ||
189 | return gnuid_name_map[i].number; | ||
190 | } | ||
191 | |||
192 | |||
193 | /** | ||
194 | * Convert a type number (i.e. 1) to the corresponding type string | ||
195 | * | ||
196 | * @param cls closure, unused | ||
197 | * @param type number of a type to convert | ||
198 | * @return corresponding typestring, NULL on error | ||
199 | */ | ||
200 | static const char * | ||
201 | gnuid_number_to_typename (void *cls, uint32_t type) | ||
202 | { | ||
203 | unsigned int i; | ||
204 | |||
205 | i = 0; | ||
206 | while ((NULL != gnuid_name_map[i].name) && (type != gnuid_name_map[i].number)) | ||
207 | i++; | ||
208 | return gnuid_name_map[i].name; | ||
209 | } | ||
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 | */ | ||
218 | static uint32_t | ||
219 | gnuid_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 | */ | ||
237 | static const char * | ||
238 | gnuid_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 | } | ||
249 | |||
250 | /** | ||
251 | * Entry point for the plugin. | ||
252 | * | ||
253 | * @param cls NULL | ||
254 | * @return the exported block API | ||
255 | */ | ||
256 | void * | ||
257 | libgnunet_plugin_reclaim_attribute_gnuid_init (void *cls) | ||
258 | { | ||
259 | struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions *api; | ||
260 | |||
261 | api = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions); | ||
262 | api->value_to_string = &gnuid_value_to_string; | ||
263 | api->string_to_value = &gnuid_string_to_value; | ||
264 | api->typename_to_number = &gnuid_typename_to_number; | ||
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; | ||
270 | return api; | ||
271 | } | ||
272 | |||
273 | |||
274 | /** | ||
275 | * Exit point from the plugin. | ||
276 | * | ||
277 | * @param cls the return value from #libgnunet_plugin_block_test_init() | ||
278 | * @return NULL | ||
279 | */ | ||
280 | void * | ||
281 | libgnunet_plugin_reclaim_attribute_gnuid_done (void *cls) | ||
282 | { | ||
283 | struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions *api = cls; | ||
284 | |||
285 | GNUNET_free (api); | ||
286 | return NULL; | ||
287 | } | ||
288 | |||
289 | |||
290 | /* end of plugin_reclaim_attribute_type_gnuid.c */ | ||
diff --git a/src/reclaim-attribute/reclaim_attestation.c b/src/reclaim-attribute/reclaim_attestation.c new file mode 100644 index 000000000..1a7776719 --- /dev/null +++ b/src/reclaim-attribute/reclaim_attestation.c | |||
@@ -0,0 +1,502 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet | ||
3 | Copyright (C) 2010-2015 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 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | |||
21 | /** | ||
22 | * @file reclaim-attribute/reclaim_attestation.c | ||
23 | * @brief helper library to manage identity attribute attestations | ||
24 | * @author Martin Schanzenbach | ||
25 | */ | ||
26 | #include "platform.h" | ||
27 | #include "gnunet_util_lib.h" | ||
28 | #include "gnunet_reclaim_plugin.h" | ||
29 | #include "reclaim_attestation.h" | ||
30 | |||
31 | |||
32 | /** | ||
33 | * Handle for a plugin | ||
34 | */ | ||
35 | struct Plugin | ||
36 | { | ||
37 | /** | ||
38 | * Name of the plugin | ||
39 | */ | ||
40 | char *library_name; | ||
41 | |||
42 | /** | ||
43 | * Plugin API | ||
44 | */ | ||
45 | struct GNUNET_RECLAIM_AttestationPluginFunctions *api; | ||
46 | }; | ||
47 | |||
48 | |||
49 | /** | ||
50 | * Plugins | ||
51 | */ | ||
52 | static struct Plugin **attest_plugins; | ||
53 | |||
54 | |||
55 | /** | ||
56 | * Number of plugins | ||
57 | */ | ||
58 | static unsigned int num_plugins; | ||
59 | |||
60 | |||
61 | /** | ||
62 | * Init canary | ||
63 | */ | ||
64 | static int initialized; | ||
65 | |||
66 | |||
67 | /** | ||
68 | * Add a plugin | ||
69 | * | ||
70 | * @param cls closure | ||
71 | * @param library_name name of the API library | ||
72 | * @param lib_ret the plugin API pointer | ||
73 | */ | ||
74 | static void | ||
75 | add_plugin (void *cls, const char *library_name, void *lib_ret) | ||
76 | { | ||
77 | struct GNUNET_RECLAIM_AttestationPluginFunctions *api = lib_ret; | ||
78 | struct Plugin *plugin; | ||
79 | |||
80 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
81 | "Loading attestation plugin `%s'\n", | ||
82 | library_name); | ||
83 | plugin = GNUNET_new (struct Plugin); | ||
84 | plugin->api = api; | ||
85 | plugin->library_name = GNUNET_strdup (library_name); | ||
86 | GNUNET_array_append (attest_plugins, num_plugins, plugin); | ||
87 | } | ||
88 | |||
89 | |||
90 | /** | ||
91 | * Load plugins | ||
92 | */ | ||
93 | static void | ||
94 | init () | ||
95 | { | ||
96 | if (GNUNET_YES == initialized) | ||
97 | return; | ||
98 | initialized = GNUNET_YES; | ||
99 | GNUNET_PLUGIN_load_all ("libgnunet_plugin_reclaim_attestation_", | ||
100 | NULL, | ||
101 | &add_plugin, | ||
102 | NULL); | ||
103 | } | ||
104 | |||
105 | |||
106 | /** | ||
107 | * Convert an attestation type name to the corresponding number | ||
108 | * | ||
109 | * @param typename name to convert | ||
110 | * @return corresponding number, UINT32_MAX on error | ||
111 | */ | ||
112 | uint32_t | ||
113 | GNUNET_RECLAIM_attestation_typename_to_number (const char *typename) | ||
114 | { | ||
115 | unsigned int i; | ||
116 | struct Plugin *plugin; | ||
117 | uint32_t ret; | ||
118 | init (); | ||
119 | for (i = 0; i < num_plugins; i++) | ||
120 | { | ||
121 | plugin = attest_plugins[i]; | ||
122 | if (UINT32_MAX != | ||
123 | (ret = plugin->api->typename_to_number (plugin->api->cls, | ||
124 | typename))) | ||
125 | return ret; | ||
126 | } | ||
127 | return UINT32_MAX; | ||
128 | } | ||
129 | |||
130 | |||
131 | /** | ||
132 | * Convert an attestation type number to the corresponding attestation type string | ||
133 | * | ||
134 | * @param type number of a type | ||
135 | * @return corresponding typestring, NULL on error | ||
136 | */ | ||
137 | const char * | ||
138 | GNUNET_RECLAIM_attestation_number_to_typename (uint32_t type) | ||
139 | { | ||
140 | unsigned int i; | ||
141 | struct Plugin *plugin; | ||
142 | const char *ret; | ||
143 | |||
144 | init (); | ||
145 | for (i = 0; i < num_plugins; i++) | ||
146 | { | ||
147 | plugin = attest_plugins[i]; | ||
148 | if (NULL != | ||
149 | (ret = plugin->api->number_to_typename (plugin->api->cls, type))) | ||
150 | return ret; | ||
151 | } | ||
152 | return NULL; | ||
153 | } | ||
154 | |||
155 | |||
156 | /** | ||
157 | * Convert human-readable version of a 'claim' of an attestation to the binary | ||
158 | * representation | ||
159 | * | ||
160 | * @param type type of the claim | ||
161 | * @param s human-readable string | ||
162 | * @param data set to value in binary encoding (will be allocated) | ||
163 | * @param data_size set to number of bytes in @a data | ||
164 | * @return #GNUNET_OK on success | ||
165 | */ | ||
166 | int | ||
167 | GNUNET_RECLAIM_attestation_string_to_value (uint32_t type, | ||
168 | const char *s, | ||
169 | void **data, | ||
170 | size_t *data_size) | ||
171 | { | ||
172 | unsigned int i; | ||
173 | struct Plugin *plugin; | ||
174 | |||
175 | init (); | ||
176 | for (i = 0; i < num_plugins; i++) | ||
177 | { | ||
178 | plugin = attest_plugins[i]; | ||
179 | if (GNUNET_OK == plugin->api->string_to_value (plugin->api->cls, | ||
180 | type, | ||
181 | s, | ||
182 | data, | ||
183 | data_size)) | ||
184 | return GNUNET_OK; | ||
185 | } | ||
186 | return GNUNET_SYSERR; | ||
187 | } | ||
188 | |||
189 | |||
190 | /** | ||
191 | * Convert the 'claim' of an attestation to a string | ||
192 | * | ||
193 | * @param type the type of attestation | ||
194 | * @param data claim in binary encoding | ||
195 | * @param data_size number of bytes in @a data | ||
196 | * @return NULL on error, otherwise human-readable representation of the claim | ||
197 | */ | ||
198 | char * | ||
199 | GNUNET_RECLAIM_attestation_value_to_string (uint32_t type, | ||
200 | const void *data, | ||
201 | size_t data_size) | ||
202 | { | ||
203 | unsigned int i; | ||
204 | struct Plugin *plugin; | ||
205 | char *ret; | ||
206 | |||
207 | init (); | ||
208 | for (i = 0; i < num_plugins; i++) | ||
209 | { | ||
210 | plugin = attest_plugins[i]; | ||
211 | if (NULL != (ret = plugin->api->value_to_string (plugin->api->cls, | ||
212 | type, | ||
213 | data, | ||
214 | data_size))) | ||
215 | return ret; | ||
216 | } | ||
217 | return NULL; | ||
218 | } | ||
219 | |||
220 | |||
221 | /** | ||
222 | * Create a new attestation. | ||
223 | * | ||
224 | * @param attr_name the attestation name | ||
225 | * @param type the attestation type | ||
226 | * @param data the attestation value | ||
227 | * @param data_size the attestation value size | ||
228 | * @return the new attestation | ||
229 | */ | ||
230 | struct GNUNET_RECLAIM_Attestation * | ||
231 | GNUNET_RECLAIM_attestation_new (const char *attr_name, | ||
232 | uint32_t type, | ||
233 | const void *data, | ||
234 | size_t data_size) | ||
235 | { | ||
236 | struct GNUNET_RECLAIM_Attestation *attr; | ||
237 | char *write_ptr; | ||
238 | char *attr_name_tmp = GNUNET_strdup (attr_name); | ||
239 | |||
240 | GNUNET_STRINGS_utf8_tolower (attr_name, attr_name_tmp); | ||
241 | |||
242 | attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_Attestation) | ||
243 | + strlen (attr_name_tmp) + 1 + data_size); | ||
244 | attr->type = type; | ||
245 | attr->data_size = data_size; | ||
246 | attr->flag = 0; | ||
247 | write_ptr = (char *) &attr[1]; | ||
248 | GNUNET_memcpy (write_ptr, attr_name_tmp, strlen (attr_name_tmp) + 1); | ||
249 | attr->name = write_ptr; | ||
250 | write_ptr += strlen (attr->name) + 1; | ||
251 | GNUNET_memcpy (write_ptr, data, data_size); | ||
252 | attr->data = write_ptr; | ||
253 | GNUNET_free (attr_name_tmp); | ||
254 | return attr; | ||
255 | } | ||
256 | |||
257 | |||
258 | /** | ||
259 | * Get required size for serialization buffer | ||
260 | * | ||
261 | * @param attrs the attribute list to serialize | ||
262 | * @return the required buffer size | ||
263 | */ | ||
264 | size_t | ||
265 | GNUNET_RECLAIM_attestation_list_serialize_get_size ( | ||
266 | const struct GNUNET_RECLAIM_AttestationList *attestations) | ||
267 | { | ||
268 | struct GNUNET_RECLAIM_AttestationListEntry *le; | ||
269 | size_t len = 0; | ||
270 | |||
271 | for (le = attestations->list_head; NULL != le; le = le->next) | ||
272 | { | ||
273 | GNUNET_assert (NULL != le->attestation); | ||
274 | len += GNUNET_RECLAIM_attestation_serialize_get_size (le->attestation); | ||
275 | len += sizeof(struct GNUNET_RECLAIM_AttestationListEntry); | ||
276 | } | ||
277 | return len; | ||
278 | } | ||
279 | |||
280 | |||
281 | /** | ||
282 | * Serialize an attribute list | ||
283 | * | ||
284 | * @param attrs the attribute list to serialize | ||
285 | * @param result the serialized attribute | ||
286 | * @return length of serialized data | ||
287 | */ | ||
288 | size_t | ||
289 | GNUNET_RECLAIM_attestation_list_serialize ( | ||
290 | const struct GNUNET_RECLAIM_AttestationList *attestations, | ||
291 | char *result) | ||
292 | { | ||
293 | struct GNUNET_RECLAIM_AttestationListEntry *le; | ||
294 | size_t len; | ||
295 | size_t total_len; | ||
296 | char *write_ptr; | ||
297 | write_ptr = result; | ||
298 | total_len = 0; | ||
299 | for (le = attestations->list_head; NULL != le; le = le->next) | ||
300 | { | ||
301 | GNUNET_assert (NULL != le->attestation); | ||
302 | len = GNUNET_RECLAIM_attestation_serialize (le->attestation, write_ptr); | ||
303 | total_len += len; | ||
304 | write_ptr += len; | ||
305 | } | ||
306 | return total_len; | ||
307 | } | ||
308 | |||
309 | |||
310 | /** | ||
311 | * Deserialize an attestation list | ||
312 | * | ||
313 | * @param data the serialized attribute list | ||
314 | * @param data_size the length of the serialized data | ||
315 | * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller | ||
316 | */ | ||
317 | struct GNUNET_RECLAIM_AttestationList * | ||
318 | GNUNET_RECLAIM_attestation_list_deserialize (const char *data, size_t data_size) | ||
319 | { | ||
320 | struct GNUNET_RECLAIM_AttestationList *al; | ||
321 | struct GNUNET_RECLAIM_AttestationListEntry *ale; | ||
322 | size_t att_len; | ||
323 | const char *read_ptr; | ||
324 | |||
325 | al = GNUNET_new (struct GNUNET_RECLAIM_AttestationList); | ||
326 | |||
327 | if ((data_size < sizeof(struct | ||
328 | Attestation) | ||
329 | + sizeof(struct GNUNET_RECLAIM_AttestationListEntry))) | ||
330 | return al; | ||
331 | |||
332 | read_ptr = data; | ||
333 | while (((data + data_size) - read_ptr) >= sizeof(struct Attestation)) | ||
334 | { | ||
335 | ale = GNUNET_new (struct GNUNET_RECLAIM_AttestationListEntry); | ||
336 | ale->attestation = | ||
337 | GNUNET_RECLAIM_attestation_deserialize (read_ptr, | ||
338 | data_size - (read_ptr - data)); | ||
339 | GNUNET_CONTAINER_DLL_insert (al->list_head, al->list_tail, ale); | ||
340 | att_len = GNUNET_RECLAIM_attestation_serialize_get_size (ale->attestation); | ||
341 | read_ptr += att_len; | ||
342 | } | ||
343 | return al; | ||
344 | } | ||
345 | |||
346 | |||
347 | /** | ||
348 | * Make a (deep) copy of the attestation list | ||
349 | * @param attrs claim list to copy | ||
350 | * @return copied claim list | ||
351 | */ | ||
352 | struct GNUNET_RECLAIM_AttestationList * | ||
353 | GNUNET_RECLAIM_attestation_list_dup ( | ||
354 | const struct GNUNET_RECLAIM_AttestationList *al) | ||
355 | { | ||
356 | struct GNUNET_RECLAIM_AttestationListEntry *ale; | ||
357 | struct GNUNET_RECLAIM_AttestationListEntry *result_ale; | ||
358 | struct GNUNET_RECLAIM_AttestationList *result; | ||
359 | |||
360 | result = GNUNET_new (struct GNUNET_RECLAIM_AttestationList); | ||
361 | for (ale = al->list_head; NULL != ale; ale = ale->next) | ||
362 | { | ||
363 | result_ale = GNUNET_new (struct GNUNET_RECLAIM_AttestationListEntry); | ||
364 | GNUNET_assert (NULL != ale->attestation); | ||
365 | result_ale->attestation = | ||
366 | GNUNET_RECLAIM_attestation_new (ale->attestation->name, | ||
367 | ale->attestation->type, | ||
368 | ale->attestation->data, | ||
369 | ale->attestation->data_size); | ||
370 | result_ale->attestation->id = ale->attestation->id; | ||
371 | GNUNET_CONTAINER_DLL_insert (result->list_head, | ||
372 | result->list_tail, | ||
373 | result_ale); | ||
374 | } | ||
375 | return result; | ||
376 | } | ||
377 | |||
378 | |||
379 | /** | ||
380 | * Destroy attestation list | ||
381 | * | ||
382 | * @param attrs list to destroy | ||
383 | */ | ||
384 | void | ||
385 | GNUNET_RECLAIM_attestation_list_destroy ( | ||
386 | struct GNUNET_RECLAIM_AttestationList *al) | ||
387 | { | ||
388 | struct GNUNET_RECLAIM_AttestationListEntry *ale; | ||
389 | struct GNUNET_RECLAIM_AttestationListEntry *tmp_ale; | ||
390 | |||
391 | for (ale = al->list_head; NULL != ale; ale = ale->next) | ||
392 | { | ||
393 | if (NULL != ale->attestation) | ||
394 | GNUNET_free (ale->attestation); | ||
395 | tmp_ale = ale; | ||
396 | ale = ale->next; | ||
397 | GNUNET_free (tmp_ale); | ||
398 | } | ||
399 | GNUNET_free (al); | ||
400 | } | ||
401 | |||
402 | |||
403 | /** | ||
404 | * Get required size for serialization buffer | ||
405 | * | ||
406 | * @param attr the attestation to serialize | ||
407 | * @return the required buffer size | ||
408 | */ | ||
409 | size_t | ||
410 | GNUNET_RECLAIM_attestation_serialize_get_size ( | ||
411 | const struct GNUNET_RECLAIM_Attestation *attestation) | ||
412 | { | ||
413 | return sizeof(struct Attestation) + strlen (attestation->name) | ||
414 | + attestation->data_size; | ||
415 | } | ||
416 | |||
417 | |||
418 | /** | ||
419 | * Serialize an attestation | ||
420 | * | ||
421 | * @param attr the attestation to serialize | ||
422 | * @param result the serialized attestation | ||
423 | * @return length of serialized data | ||
424 | */ | ||
425 | size_t | ||
426 | GNUNET_RECLAIM_attestation_serialize ( | ||
427 | const struct GNUNET_RECLAIM_Attestation *attestation, | ||
428 | char *result) | ||
429 | { | ||
430 | size_t data_len_ser; | ||
431 | size_t name_len; | ||
432 | struct Attestation *atts; | ||
433 | char *write_ptr; | ||
434 | |||
435 | atts = (struct Attestation *) result; | ||
436 | atts->attestation_type = htons (attestation->type); | ||
437 | atts->attestation_flag = htonl (attestation->flag); | ||
438 | atts->attestation_id = attestation->id; | ||
439 | name_len = strlen (attestation->name); | ||
440 | atts->name_len = htons (name_len); | ||
441 | write_ptr = (char *) &atts[1]; | ||
442 | GNUNET_memcpy (write_ptr, attestation->name, name_len); | ||
443 | write_ptr += name_len; | ||
444 | // TODO plugin-ize | ||
445 | // data_len_ser = plugin->serialize_attribute_value (attr, | ||
446 | // &attr_ser[1]); | ||
447 | data_len_ser = attestation->data_size; | ||
448 | GNUNET_memcpy (write_ptr, attestation->data, attestation->data_size); | ||
449 | atts->data_size = htons (data_len_ser); | ||
450 | |||
451 | return sizeof(struct Attestation) + strlen (attestation->name) | ||
452 | + attestation->data_size; | ||
453 | } | ||
454 | |||
455 | |||
456 | /** | ||
457 | * Deserialize an attestation | ||
458 | * | ||
459 | * @param data the serialized attestation | ||
460 | * @param data_size the length of the serialized data | ||
461 | * | ||
462 | * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller | ||
463 | */ | ||
464 | struct GNUNET_RECLAIM_Attestation * | ||
465 | GNUNET_RECLAIM_attestation_deserialize (const char *data, size_t data_size) | ||
466 | { | ||
467 | struct GNUNET_RECLAIM_Attestation *attestation; | ||
468 | struct Attestation *atts; | ||
469 | size_t data_len; | ||
470 | size_t name_len; | ||
471 | char *write_ptr; | ||
472 | |||
473 | if (data_size < sizeof(struct Attestation)) | ||
474 | return NULL; | ||
475 | |||
476 | atts = (struct Attestation *) data; | ||
477 | data_len = ntohs (atts->data_size); | ||
478 | name_len = ntohs (atts->name_len); | ||
479 | if (data_size < sizeof(struct Attestation) + data_len + name_len) | ||
480 | { | ||
481 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
482 | "Buffer too small to deserialize\n"); | ||
483 | return NULL; | ||
484 | } | ||
485 | attestation = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_Attestation) | ||
486 | + data_len + name_len + 1); | ||
487 | attestation->type = ntohs (atts->attestation_type); | ||
488 | attestation->flag = ntohl (atts->attestation_flag); | ||
489 | attestation->id = atts->attestation_id; | ||
490 | attestation->data_size = data_len; | ||
491 | |||
492 | write_ptr = (char *) &attestation[1]; | ||
493 | GNUNET_memcpy (write_ptr, &atts[1], name_len); | ||
494 | write_ptr[name_len] = '\0'; | ||
495 | attestation->name = write_ptr; | ||
496 | |||
497 | write_ptr += name_len + 1; | ||
498 | GNUNET_memcpy (write_ptr, (char *) &atts[1] + name_len, | ||
499 | attestation->data_size); | ||
500 | attestation->data = write_ptr; | ||
501 | return attestation; | ||
502 | } | ||
diff --git a/src/reclaim-attribute/reclaim_attestation.h b/src/reclaim-attribute/reclaim_attestation.h new file mode 100644 index 000000000..5747d8896 --- /dev/null +++ b/src/reclaim-attribute/reclaim_attestation.h | |||
@@ -0,0 +1,64 @@ | |||
1 | /* | ||
2 | This file is part of GNUnet. | ||
3 | Copyright (C) 2012-2015 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 | SPDX-License-Identifier: AGPL3.0-or-later | ||
19 | */ | ||
20 | /** | ||
21 | * @author Martin Schanzenbach | ||
22 | * @file reclaim-attribute/reclaim_attestation.h | ||
23 | * @brief GNUnet reclaim identity attribute attestations | ||
24 | * | ||
25 | */ | ||
26 | #ifndef RECLAIM_ATTESTATION_H | ||
27 | #define RECLAIM_ATTESTATION_H | ||
28 | |||
29 | #include "gnunet_reclaim_service.h" | ||
30 | |||
31 | /** | ||
32 | * Serialized attestation claim | ||
33 | */ | ||
34 | struct Attestation | ||
35 | { | ||
36 | /** | ||
37 | * Attestation type | ||
38 | */ | ||
39 | uint32_t attestation_type; | ||
40 | |||
41 | /** | ||
42 | * Attestation flag | ||
43 | */ | ||
44 | uint32_t attestation_flag; | ||
45 | |||
46 | /** | ||
47 | * Attestation ID | ||
48 | */ | ||
49 | struct GNUNET_RECLAIM_Identifier attestation_id; | ||
50 | |||
51 | /** | ||
52 | * Name length | ||
53 | */ | ||
54 | uint32_t name_len; | ||
55 | |||
56 | /** | ||
57 | * Data size | ||
58 | */ | ||
59 | uint32_t data_size; | ||
60 | |||
61 | // followed by data_size Attestation value data | ||
62 | }; | ||
63 | |||
64 | #endif | ||
diff --git a/src/reclaim-attribute/reclaim_attribute.c b/src/reclaim-attribute/reclaim_attribute.c index 07d8200c6..936f9cb75 100644 --- a/src/reclaim-attribute/reclaim_attribute.c +++ b/src/reclaim-attribute/reclaim_attribute.c | |||
@@ -25,7 +25,7 @@ | |||
25 | */ | 25 | */ |
26 | #include "platform.h" | 26 | #include "platform.h" |
27 | #include "gnunet_util_lib.h" | 27 | #include "gnunet_util_lib.h" |
28 | #include "gnunet_reclaim_attribute_plugin.h" | 28 | #include "gnunet_reclaim_plugin.h" |
29 | #include "reclaim_attribute.h" | 29 | #include "reclaim_attribute.h" |
30 | 30 | ||
31 | 31 | ||
@@ -42,7 +42,7 @@ struct Plugin | |||
42 | /** | 42 | /** |
43 | * Plugin API | 43 | * Plugin API |
44 | */ | 44 | */ |
45 | struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions *api; | 45 | struct GNUNET_RECLAIM_AttributePluginFunctions *api; |
46 | }; | 46 | }; |
47 | 47 | ||
48 | 48 | ||
@@ -74,7 +74,7 @@ static int initialized; | |||
74 | static void | 74 | static void |
75 | add_plugin (void *cls, const char *library_name, void *lib_ret) | 75 | add_plugin (void *cls, const char *library_name, void *lib_ret) |
76 | { | 76 | { |
77 | struct GNUNET_RECLAIM_ATTRIBUTE_PluginFunctions *api = lib_ret; | 77 | struct GNUNET_RECLAIM_AttributePluginFunctions *api = lib_ret; |
78 | struct Plugin *plugin; | 78 | struct Plugin *plugin; |
79 | 79 | ||
80 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 80 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
@@ -110,7 +110,7 @@ init () | |||
110 | * @return corresponding number, UINT32_MAX on error | 110 | * @return corresponding number, UINT32_MAX on error |
111 | */ | 111 | */ |
112 | uint32_t | 112 | uint32_t |
113 | GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (const char *typename) | 113 | GNUNET_RECLAIM_attribute_typename_to_number (const char *typename) |
114 | { | 114 | { |
115 | unsigned int i; | 115 | unsigned int i; |
116 | struct Plugin *plugin; | 116 | struct Plugin *plugin; |
@@ -135,7 +135,7 @@ GNUNET_RECLAIM_ATTRIBUTE_typename_to_number (const char *typename) | |||
135 | * @return corresponding typestring, NULL on error | 135 | * @return corresponding typestring, NULL on error |
136 | */ | 136 | */ |
137 | const char * | 137 | const char * |
138 | GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type) | 138 | GNUNET_RECLAIM_attribute_number_to_typename (uint32_t type) |
139 | { | 139 | { |
140 | unsigned int i; | 140 | unsigned int i; |
141 | struct Plugin *plugin; | 141 | struct Plugin *plugin; |
@@ -164,7 +164,7 @@ GNUNET_RECLAIM_ATTRIBUTE_number_to_typename (uint32_t type) | |||
164 | * @return #GNUNET_OK on success | 164 | * @return #GNUNET_OK on success |
165 | */ | 165 | */ |
166 | int | 166 | int |
167 | GNUNET_RECLAIM_ATTRIBUTE_string_to_value (uint32_t type, | 167 | GNUNET_RECLAIM_attribute_string_to_value (uint32_t type, |
168 | const char *s, | 168 | const char *s, |
169 | void **data, | 169 | void **data, |
170 | size_t *data_size) | 170 | size_t *data_size) |
@@ -196,7 +196,7 @@ GNUNET_RECLAIM_ATTRIBUTE_string_to_value (uint32_t type, | |||
196 | * @return NULL on error, otherwise human-readable representation of the claim | 196 | * @return NULL on error, otherwise human-readable representation of the claim |
197 | */ | 197 | */ |
198 | char * | 198 | char * |
199 | GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type, | 199 | GNUNET_RECLAIM_attribute_value_to_string (uint32_t type, |
200 | const void *data, | 200 | const void *data, |
201 | size_t data_size) | 201 | size_t data_size) |
202 | { | 202 | { |
@@ -217,140 +217,34 @@ GNUNET_RECLAIM_ATTRIBUTE_value_to_string (uint32_t type, | |||
217 | return NULL; | 217 | return NULL; |
218 | } | 218 | } |
219 | 219 | ||
220 | /** | ||
221 | * Convert an attestation type name to the corresponding number | ||
222 | * | ||
223 | * @param typename name to convert | ||
224 | * @return corresponding number, UINT32_MAX on error | ||
225 | */ | ||
226 | uint32_t | ||
227 | GNUNET_RECLAIM_ATTESTATION_typename_to_number (const char *typename) | ||
228 | { | ||
229 | unsigned int i; | ||
230 | struct Plugin *plugin; | ||
231 | uint32_t ret; | ||
232 | init (); | ||
233 | for (i = 0; i < num_plugins; i++) | ||
234 | { | ||
235 | plugin = attr_plugins[i]; | ||
236 | if (UINT32_MAX != | ||
237 | (ret = plugin->api->typename_to_number_attest (plugin->api->cls, | ||
238 | typename))) | ||
239 | return ret; | ||
240 | } | ||
241 | return UINT32_MAX; | ||
242 | } | ||
243 | |||
244 | /** | ||
245 | * Convert an attestation type number to the corresponding attestation type string | ||
246 | * | ||
247 | * @param type number of a type | ||
248 | * @return corresponding typestring, NULL on error | ||
249 | */ | ||
250 | const char * | ||
251 | GNUNET_RECLAIM_ATTESTATION_number_to_typename (uint32_t type) | ||
252 | { | ||
253 | unsigned int i; | ||
254 | struct Plugin *plugin; | ||
255 | const char *ret; | ||
256 | |||
257 | init (); | ||
258 | for (i = 0; i < num_plugins; i++) | ||
259 | { | ||
260 | plugin = attr_plugins[i]; | ||
261 | if (NULL != | ||
262 | (ret = plugin->api->number_to_typename_attest (plugin->api->cls, type))) | ||
263 | return ret; | ||
264 | } | ||
265 | return NULL; | ||
266 | } | ||
267 | /** | ||
268 | * Convert human-readable version of a 'claim' of an attestation to the binary | ||
269 | * representation | ||
270 | * | ||
271 | * @param type type of the claim | ||
272 | * @param s human-readable string | ||
273 | * @param data set to value in binary encoding (will be allocated) | ||
274 | * @param data_size set to number of bytes in @a data | ||
275 | * @return #GNUNET_OK on success | ||
276 | */ | ||
277 | int | ||
278 | GNUNET_RECLAIM_ATTESTATION_string_to_value (uint32_t type, | ||
279 | const char *s, | ||
280 | void **data, | ||
281 | size_t *data_size) | ||
282 | { | ||
283 | unsigned int i; | ||
284 | struct Plugin *plugin; | ||
285 | |||
286 | init (); | ||
287 | for (i = 0; i < num_plugins; i++) | ||
288 | { | ||
289 | plugin = attr_plugins[i]; | ||
290 | if (GNUNET_OK == plugin->api->string_to_value_attest (plugin->api->cls, | ||
291 | type, | ||
292 | s, | ||
293 | data, | ||
294 | data_size)) | ||
295 | return GNUNET_OK; | ||
296 | } | ||
297 | return GNUNET_SYSERR; | ||
298 | } | ||
299 | |||
300 | |||
301 | /** | ||
302 | * Convert the 'claim' of an attestation to a string | ||
303 | * | ||
304 | * @param type the type of attestation | ||
305 | * @param data claim in binary encoding | ||
306 | * @param data_size number of bytes in @a data | ||
307 | * @return NULL on error, otherwise human-readable representation of the claim | ||
308 | */ | ||
309 | char * | ||
310 | GNUNET_RECLAIM_ATTESTATION_value_to_string (uint32_t type, | ||
311 | const void *data, | ||
312 | size_t data_size) | ||
313 | { | ||
314 | unsigned int i; | ||
315 | struct Plugin *plugin; | ||
316 | char *ret; | ||
317 | |||
318 | init (); | ||
319 | for (i = 0; i < num_plugins; i++) | ||
320 | { | ||
321 | plugin = attr_plugins[i]; | ||
322 | if (NULL != (ret = plugin->api->value_to_string_attest (plugin->api->cls, | ||
323 | type, | ||
324 | data, | ||
325 | data_size))) | ||
326 | return ret; | ||
327 | } | ||
328 | return NULL; | ||
329 | } | ||
330 | 220 | ||
331 | /** | 221 | /** |
332 | * Create a new attribute. | 222 | * Create a new attribute. |
333 | * | 223 | * |
334 | * @param attr_name the attribute name | 224 | * @param attr_name the attribute name |
225 | * @param attestation attestation ID of the attribute (maybe NULL) | ||
335 | * @param type the attribute type | 226 | * @param type the attribute type |
336 | * @param data the attribute value | 227 | * @param data the attribute value |
337 | * @param data_size the attribute value size | 228 | * @param data_size the attribute value size |
338 | * @return the new attribute | 229 | * @return the new attribute |
339 | */ | 230 | */ |
340 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim * | 231 | struct GNUNET_RECLAIM_Attribute * |
341 | GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char *attr_name, | 232 | GNUNET_RECLAIM_attribute_new (const char *attr_name, |
342 | uint32_t type, | 233 | const struct GNUNET_RECLAIM_Identifier *attestation, |
343 | const void *data, | 234 | uint32_t type, |
344 | size_t data_size) | 235 | const void *data, |
236 | size_t data_size) | ||
345 | { | 237 | { |
346 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; | 238 | struct GNUNET_RECLAIM_Attribute *attr; |
347 | char *write_ptr; | 239 | char *write_ptr; |
348 | char *attr_name_tmp = GNUNET_strdup (attr_name); | 240 | char *attr_name_tmp = GNUNET_strdup (attr_name); |
349 | 241 | ||
350 | GNUNET_STRINGS_utf8_tolower (attr_name, attr_name_tmp); | 242 | GNUNET_STRINGS_utf8_tolower (attr_name, attr_name_tmp); |
351 | 243 | ||
352 | attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_Claim) | 244 | attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_Attribute) |
353 | + strlen (attr_name_tmp) + 1 + data_size); | 245 | + strlen (attr_name_tmp) + 1 + data_size); |
246 | if (NULL != attestation) | ||
247 | attr->attestation = *attestation; | ||
354 | attr->type = type; | 248 | attr->type = type; |
355 | attr->data_size = data_size; | 249 | attr->data_size = data_size; |
356 | attr->flag = 0; | 250 | attr->flag = 0; |
@@ -364,76 +258,6 @@ GNUNET_RECLAIM_ATTRIBUTE_claim_new (const char *attr_name, | |||
364 | return attr; | 258 | return attr; |
365 | } | 259 | } |
366 | 260 | ||
367 | /** | ||
368 | * Create a new attestation. | ||
369 | * | ||
370 | * @param attr_name the attestation name | ||
371 | * @param type the attestation type | ||
372 | * @param data the attestation value | ||
373 | * @param data_size the attestation value size | ||
374 | * @return the new attestation | ||
375 | */ | ||
376 | struct GNUNET_RECLAIM_ATTESTATION_Claim * | ||
377 | GNUNET_RECLAIM_ATTESTATION_claim_new (const char *attr_name, | ||
378 | uint32_t type, | ||
379 | const void *data, | ||
380 | size_t data_size) | ||
381 | { | ||
382 | struct GNUNET_RECLAIM_ATTESTATION_Claim *attr; | ||
383 | char *write_ptr; | ||
384 | char *attr_name_tmp = GNUNET_strdup (attr_name); | ||
385 | |||
386 | GNUNET_STRINGS_utf8_tolower (attr_name, attr_name_tmp); | ||
387 | |||
388 | attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_ATTESTATION_Claim) | ||
389 | + strlen (attr_name_tmp) + 1 + data_size); | ||
390 | attr->type = type; | ||
391 | attr->data_size = data_size; | ||
392 | attr->flag = 0; | ||
393 | write_ptr = (char *) &attr[1]; | ||
394 | GNUNET_memcpy (write_ptr, attr_name_tmp, strlen (attr_name_tmp) + 1); | ||
395 | attr->name = write_ptr; | ||
396 | write_ptr += strlen (attr->name) + 1; | ||
397 | GNUNET_memcpy (write_ptr, data, data_size); | ||
398 | attr->data = write_ptr; | ||
399 | GNUNET_free (attr_name_tmp); | ||
400 | return attr; | ||
401 | } | ||
402 | |||
403 | /** | ||
404 | * Create a new attestation reference. | ||
405 | * | ||
406 | * @param attr_name the referenced claim name | ||
407 | * @param ref_value the claim name in the attestation | ||
408 | * @return the new reference | ||
409 | */ | ||
410 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE * | ||
411 | GNUNET_RECLAIM_ATTESTATION_reference_new (const char *attr_name, | ||
412 | const char *ref_value) | ||
413 | { | ||
414 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr; | ||
415 | char *write_ptr; | ||
416 | char *attr_name_tmp = GNUNET_strdup (attr_name); | ||
417 | char *ref_value_tmp = GNUNET_strdup (ref_value); | ||
418 | |||
419 | GNUNET_STRINGS_utf8_tolower (attr_name, attr_name_tmp); | ||
420 | GNUNET_STRINGS_utf8_tolower (ref_value, ref_value_tmp); | ||
421 | |||
422 | attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_ATTESTATION_REFERENCE) | ||
423 | + strlen (attr_name_tmp) + strlen (ref_value_tmp) + 2); | ||
424 | |||
425 | write_ptr = (char *) &attr[1]; | ||
426 | GNUNET_memcpy (write_ptr, attr_name_tmp, strlen (attr_name_tmp) + 1); | ||
427 | attr->name = write_ptr; | ||
428 | |||
429 | write_ptr += strlen (attr_name) + 1; | ||
430 | GNUNET_memcpy (write_ptr, ref_value_tmp, strlen (ref_value_tmp) + 1); | ||
431 | attr->reference_value = write_ptr; | ||
432 | |||
433 | GNUNET_free (attr_name_tmp); | ||
434 | GNUNET_free (ref_value_tmp); | ||
435 | return attr; | ||
436 | } | ||
437 | 261 | ||
438 | /** | 262 | /** |
439 | * Add a new attribute to a claim list | 263 | * Add a new attribute to a claim list |
@@ -444,21 +268,23 @@ GNUNET_RECLAIM_ATTESTATION_reference_new (const char *attr_name, | |||
444 | * @param data_size claim payload size | 268 | * @param data_size claim payload size |
445 | */ | 269 | */ |
446 | void | 270 | void |
447 | GNUNET_RECLAIM_ATTRIBUTE_list_add ( | 271 | GNUNET_RECLAIM_attribute_list_add ( |
448 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *claim_list, | 272 | struct GNUNET_RECLAIM_AttributeList *al, |
449 | const char *attr_name, | 273 | const char *attr_name, |
274 | const struct GNUNET_RECLAIM_Identifier *attestation, | ||
450 | uint32_t type, | 275 | uint32_t type, |
451 | const void *data, | 276 | const void *data, |
452 | size_t data_size) | 277 | size_t data_size) |
453 | { | 278 | { |
454 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 279 | struct GNUNET_RECLAIM_AttributeListEntry *ale; |
455 | 280 | ||
456 | le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | 281 | ale = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry); |
457 | le->claim = | 282 | ale->attribute = |
458 | GNUNET_RECLAIM_ATTRIBUTE_claim_new (attr_name, type, data, data_size); | 283 | GNUNET_RECLAIM_attribute_new (attr_name, attestation, |
459 | GNUNET_CONTAINER_DLL_insert (claim_list->list_head, | 284 | type, data, data_size); |
460 | claim_list->list_tail, | 285 | GNUNET_CONTAINER_DLL_insert (al->list_head, |
461 | le); | 286 | al->list_tail, |
287 | ale); | ||
462 | } | 288 | } |
463 | 289 | ||
464 | 290 | ||
@@ -469,36 +295,17 @@ GNUNET_RECLAIM_ATTRIBUTE_list_add ( | |||
469 | * @return the required buffer size | 295 | * @return the required buffer size |
470 | */ | 296 | */ |
471 | size_t | 297 | size_t |
472 | GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size ( | 298 | GNUNET_RECLAIM_attribute_list_serialize_get_size ( |
473 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) | 299 | const struct GNUNET_RECLAIM_AttributeList *al) |
474 | { | 300 | { |
475 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 301 | struct GNUNET_RECLAIM_AttributeListEntry *ale; |
476 | size_t len = 0; | 302 | size_t len = 0; |
477 | 303 | ||
478 | for (le = attrs->list_head; NULL != le; le = le->next) | 304 | for (ale = al->list_head; NULL != ale; ale = ale->next) |
479 | { | 305 | { |
480 | if (NULL != le->claim) | 306 | GNUNET_assert (NULL != ale->attribute); |
481 | { | 307 | len += GNUNET_RECLAIM_attribute_serialize_get_size (ale->attribute); |
482 | len += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | 308 | len += sizeof(struct GNUNET_RECLAIM_AttributeListEntry); |
483 | len += GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (le->claim); | ||
484 | } | ||
485 | else if (NULL != le->attest ) | ||
486 | { | ||
487 | len += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | ||
488 | len += GNUNET_RECLAIM_ATTESTATION_serialize_get_size (le->attest); | ||
489 | } | ||
490 | else if (NULL != le->reference) | ||
491 | { | ||
492 | len += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | ||
493 | len += GNUNET_RECLAIM_ATTESTATION_REF_serialize_get_size (le->reference); | ||
494 | } | ||
495 | else | ||
496 | { | ||
497 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
498 | "Unserialized Claim List Entry Type for size not known.\n"); | ||
499 | break; | ||
500 | } | ||
501 | len += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | ||
502 | } | 309 | } |
503 | return len; | 310 | return len; |
504 | } | 311 | } |
@@ -512,58 +319,22 @@ GNUNET_RECLAIM_ATTRIBUTE_list_serialize_get_size ( | |||
512 | * @return length of serialized data | 319 | * @return length of serialized data |
513 | */ | 320 | */ |
514 | size_t | 321 | size_t |
515 | GNUNET_RECLAIM_ATTRIBUTE_list_serialize ( | 322 | GNUNET_RECLAIM_attribute_list_serialize ( |
516 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs, | 323 | const struct GNUNET_RECLAIM_AttributeList *al, |
517 | char *result) | 324 | char *result) |
518 | { | 325 | { |
519 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 326 | struct GNUNET_RECLAIM_AttributeListEntry *ale; |
520 | size_t len; | 327 | size_t len; |
521 | size_t total_len; | 328 | size_t total_len; |
522 | char *write_ptr; | 329 | char *write_ptr; |
523 | write_ptr = result; | 330 | write_ptr = result; |
524 | total_len = 0; | 331 | total_len = 0; |
525 | for (le = attrs->list_head; NULL != le; le = le->next) | 332 | for (ale = al->list_head; NULL != ale; ale = ale->next) |
526 | { | 333 | { |
527 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType *list_type; | 334 | GNUNET_assert (NULL != ale->attribute); |
528 | if (NULL != le->claim) | 335 | len = GNUNET_RECLAIM_attribute_serialize (ale->attribute, write_ptr); |
529 | { | 336 | total_len += len; |
530 | list_type = (struct | 337 | write_ptr += len; |
531 | GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType *) write_ptr; | ||
532 | list_type->type = htons (1); | ||
533 | total_len += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | ||
534 | write_ptr += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | ||
535 | len = GNUNET_RECLAIM_ATTRIBUTE_serialize (le->claim, write_ptr); | ||
536 | total_len += len; | ||
537 | write_ptr += len; | ||
538 | } | ||
539 | else if (NULL != le->attest ) | ||
540 | { | ||
541 | list_type = (struct | ||
542 | GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType *) write_ptr; | ||
543 | list_type->type = htons (2); | ||
544 | total_len += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | ||
545 | write_ptr += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | ||
546 | len = GNUNET_RECLAIM_ATTESTATION_serialize (le->attest, write_ptr); | ||
547 | total_len += len; | ||
548 | write_ptr += len; | ||
549 | } | ||
550 | else if (NULL != le->reference) | ||
551 | { | ||
552 | list_type = (struct | ||
553 | GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType *) write_ptr; | ||
554 | list_type->type = htons (3); | ||
555 | total_len += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | ||
556 | write_ptr += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | ||
557 | len = GNUNET_RECLAIM_ATTESTATION_REF_serialize (le->reference, write_ptr); | ||
558 | total_len += len; | ||
559 | write_ptr += len; | ||
560 | } | ||
561 | else | ||
562 | { | ||
563 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
564 | "Unserialized Claim List Entry Type not known.\n"); | ||
565 | continue; | ||
566 | } | ||
567 | } | 338 | } |
568 | return total_len; | 339 | return total_len; |
569 | } | 340 | } |
@@ -576,85 +347,30 @@ GNUNET_RECLAIM_ATTRIBUTE_list_serialize ( | |||
576 | * @param data_size the length of the serialized data | 347 | * @param data_size the length of the serialized data |
577 | * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller | 348 | * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller |
578 | */ | 349 | */ |
579 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList * | 350 | struct GNUNET_RECLAIM_AttributeList * |
580 | GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char *data, size_t data_size) | 351 | GNUNET_RECLAIM_attribute_list_deserialize (const char *data, size_t data_size) |
581 | { | 352 | { |
582 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs; | 353 | struct GNUNET_RECLAIM_AttributeList *al; |
583 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 354 | struct GNUNET_RECLAIM_AttributeListEntry *ale; |
584 | size_t attr_len; | 355 | size_t attr_len; |
585 | const char *read_ptr; | 356 | const char *read_ptr; |
586 | 357 | ||
587 | if ((data_size < sizeof(struct Attribute) + sizeof(struct | 358 | al = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); |
588 | GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry)) | 359 | if (data_size < sizeof(struct Attribute) + sizeof(struct |
589 | && (data_size < sizeof(struct | 360 | GNUNET_RECLAIM_AttributeListEntry)) |
590 | Attestation) | 361 | return al; |
591 | + sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry)) && | ||
592 | (data_size < sizeof(struct Attestation_Reference) + sizeof(struct | ||
593 | GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry)) ) | ||
594 | return NULL; | ||
595 | |||
596 | attrs = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); | ||
597 | read_ptr = data; | 362 | read_ptr = data; |
598 | while (((data + data_size) - read_ptr) >= sizeof(struct Attribute)) | 363 | while (((data + data_size) - read_ptr) >= sizeof(struct Attribute)) |
599 | { | 364 | { |
600 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType *list_type; | 365 | ale = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry); |
601 | list_type = (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType *) read_ptr; | 366 | ale->attribute = |
602 | if (1 == ntohs (list_type->type)) | 367 | GNUNET_RECLAIM_attribute_deserialize (read_ptr, |
603 | { | 368 | data_size - (read_ptr - data)); |
604 | le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | 369 | GNUNET_CONTAINER_DLL_insert (al->list_head, al->list_tail, ale); |
605 | read_ptr += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | 370 | attr_len = GNUNET_RECLAIM_attribute_serialize_get_size (ale->attribute); |
606 | if (((data + data_size) - read_ptr) < sizeof(struct Attribute)) | 371 | read_ptr += attr_len; |
607 | break; | ||
608 | le->attest = NULL; | ||
609 | le->reference = NULL; | ||
610 | le->claim = | ||
611 | GNUNET_RECLAIM_ATTRIBUTE_deserialize (read_ptr, | ||
612 | data_size - (read_ptr - data)); | ||
613 | GNUNET_CONTAINER_DLL_insert (attrs->list_head, attrs->list_tail, le); | ||
614 | attr_len = GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size (le->claim); | ||
615 | read_ptr += attr_len; | ||
616 | } | ||
617 | else if (2 == ntohs (list_type->type)) | ||
618 | { | ||
619 | le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | ||
620 | read_ptr += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | ||
621 | if (((data + data_size) - read_ptr) < sizeof(struct Attestation)) | ||
622 | break; | ||
623 | le->claim = NULL; | ||
624 | le->reference = NULL; | ||
625 | le->attest = | ||
626 | GNUNET_RECLAIM_ATTESTATION_deserialize (read_ptr, | ||
627 | data_size - (read_ptr - data)); | ||
628 | GNUNET_CONTAINER_DLL_insert (attrs->list_head, attrs->list_tail, le); | ||
629 | attr_len = GNUNET_RECLAIM_ATTESTATION_serialize_get_size (le->attest); | ||
630 | read_ptr += attr_len; | ||
631 | } | ||
632 | else if (3 == ntohs (list_type->type)) | ||
633 | { | ||
634 | le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | ||
635 | read_ptr += sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntryType); | ||
636 | if (((data + data_size) - read_ptr) < sizeof(struct | ||
637 | Attestation_Reference)) | ||
638 | break; | ||
639 | le->claim = NULL; | ||
640 | le->attest = NULL; | ||
641 | le->reference = | ||
642 | GNUNET_RECLAIM_ATTESTATION_REF_deserialize (read_ptr, | ||
643 | data_size - (read_ptr | ||
644 | - data)); | ||
645 | GNUNET_CONTAINER_DLL_insert (attrs->list_head, attrs->list_tail, le); | ||
646 | attr_len = GNUNET_RECLAIM_ATTESTATION_REF_serialize_get_size ( | ||
647 | le->reference); | ||
648 | read_ptr += attr_len; | ||
649 | } | ||
650 | else | ||
651 | { | ||
652 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
653 | "Serialized Claim List Entry Type not known.\n"); | ||
654 | break; | ||
655 | } | ||
656 | } | 372 | } |
657 | return attrs; | 373 | return al; |
658 | } | 374 | } |
659 | 375 | ||
660 | 376 | ||
@@ -663,57 +379,33 @@ GNUNET_RECLAIM_ATTRIBUTE_list_deserialize (const char *data, size_t data_size) | |||
663 | * @param attrs claim list to copy | 379 | * @param attrs claim list to copy |
664 | * @return copied claim list | 380 | * @return copied claim list |
665 | */ | 381 | */ |
666 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList * | 382 | struct GNUNET_RECLAIM_AttributeList * |
667 | GNUNET_RECLAIM_ATTRIBUTE_list_dup ( | 383 | GNUNET_RECLAIM_attribute_list_dup ( |
668 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) | 384 | const struct GNUNET_RECLAIM_AttributeList *al) |
669 | { | 385 | { |
670 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 386 | struct GNUNET_RECLAIM_AttributeListEntry *ale; |
671 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *result_le; | 387 | struct GNUNET_RECLAIM_AttributeListEntry *result_ale; |
672 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *result; | 388 | struct GNUNET_RECLAIM_AttributeList *result; |
673 | 389 | ||
674 | result = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList); | 390 | result = GNUNET_new (struct GNUNET_RECLAIM_AttributeList); |
675 | if (NULL == attrs->list_head) | 391 | for (ale = al->list_head; NULL != ale; ale = ale->next) |
676 | { | 392 | { |
677 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,"Duplicating empty List\n"); | 393 | result_ale = GNUNET_new (struct GNUNET_RECLAIM_AttributeListEntry); |
678 | } | 394 | GNUNET_assert (NULL != ale->attribute); |
679 | for (le = attrs->list_head; NULL != le; le = le->next) | ||
680 | { | ||
681 | result_le = GNUNET_new (struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry); | ||
682 | result_le->claim = NULL; | ||
683 | result_le->attest = NULL; | ||
684 | result_le->reference = NULL; | ||
685 | if (NULL != le->claim) | ||
686 | { | ||
687 | result_le->claim = | ||
688 | GNUNET_RECLAIM_ATTRIBUTE_claim_new (le->claim->name, | ||
689 | le->claim->type, | ||
690 | le->claim->data, | ||
691 | le->claim->data_size); | ||
692 | |||
693 | result_le->claim->id = le->claim->id; | ||
694 | result_le->claim->flag = le->claim->flag; | ||
695 | } | ||
696 | if ( NULL != le->attest) | ||
697 | { | ||
698 | result_le->attest = GNUNET_RECLAIM_ATTESTATION_claim_new ( | ||
699 | le->attest->name, | ||
700 | le->attest->type, | ||
701 | le->attest->data, | ||
702 | le->attest-> | ||
703 | data_size); | ||
704 | result_le->attest->id = le->attest->id; | ||
705 | } | ||
706 | if (NULL !=le->reference) | ||
707 | { | 395 | { |
708 | result_le->reference = GNUNET_RECLAIM_ATTESTATION_reference_new ( | 396 | result_ale->attribute = |
709 | le->reference->name, | 397 | GNUNET_RECLAIM_attribute_new (ale->attribute->name, |
710 | le->reference->reference_value); | 398 | &ale->attribute->attestation, |
711 | result_le->reference->id = le->reference->id; | 399 | ale->attribute->type, |
712 | result_le->reference->id_attest = le->reference->id_attest; | 400 | ale->attribute->data, |
401 | ale->attribute->data_size); | ||
402 | |||
403 | result_ale->attribute->id = ale->attribute->id; | ||
404 | result_ale->attribute->flag = ale->attribute->flag; | ||
713 | } | 405 | } |
714 | GNUNET_CONTAINER_DLL_insert (result->list_head, | 406 | GNUNET_CONTAINER_DLL_insert (result->list_head, |
715 | result->list_tail, | 407 | result->list_tail, |
716 | result_le); | 408 | result_ale); |
717 | } | 409 | } |
718 | return result; | 410 | return result; |
719 | } | 411 | } |
@@ -725,45 +417,24 @@ GNUNET_RECLAIM_ATTRIBUTE_list_dup ( | |||
725 | * @param attrs list to destroy | 417 | * @param attrs list to destroy |
726 | */ | 418 | */ |
727 | void | 419 | void |
728 | GNUNET_RECLAIM_ATTRIBUTE_list_destroy ( | 420 | GNUNET_RECLAIM_attribute_list_destroy ( |
729 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) | 421 | struct GNUNET_RECLAIM_AttributeList *al) |
730 | { | 422 | { |
731 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | 423 | struct GNUNET_RECLAIM_AttributeListEntry *ale; |
732 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *tmp_le; | 424 | struct GNUNET_RECLAIM_AttributeListEntry *tmp_ale; |
733 | 425 | ||
734 | for (le = attrs->list_head; NULL != le; le = le->next) | 426 | for (ale = al->list_head; NULL != ale; ale = ale->next) |
735 | { | 427 | { |
736 | if (NULL != le->claim) | 428 | if (NULL != ale->attribute) |
737 | GNUNET_free (le->claim); | 429 | GNUNET_free (ale->attribute); |
738 | if (NULL != le->attest) | 430 | tmp_ale = ale; |
739 | GNUNET_free (le->attest); | 431 | ale = ale->next; |
740 | if (NULL != le->reference) | 432 | GNUNET_free (tmp_ale); |
741 | GNUNET_free (le->reference); | ||
742 | tmp_le = le; | ||
743 | le = le->next; | ||
744 | GNUNET_free (tmp_le); | ||
745 | } | 433 | } |
746 | GNUNET_free (attrs); | 434 | GNUNET_free (al); |
747 | } | 435 | } |
748 | 436 | ||
749 | /** | 437 | |
750 | * Count attestations in claim list | ||
751 | * | ||
752 | * @param attrs list | ||
753 | */ | ||
754 | int | ||
755 | GNUNET_RECLAIM_ATTRIBUTE_list_count_attest ( | ||
756 | const struct GNUNET_RECLAIM_ATTRIBUTE_ClaimList *attrs) | ||
757 | { | ||
758 | struct GNUNET_RECLAIM_ATTRIBUTE_ClaimListEntry *le; | ||
759 | int i = 0; | ||
760 | for (le = attrs->list_head; NULL != le; le = le->next) | ||
761 | { | ||
762 | if (NULL != le->attest) | ||
763 | i++; | ||
764 | } | ||
765 | return i; | ||
766 | } | ||
767 | /** | 438 | /** |
768 | * Get required size for serialization buffer | 439 | * Get required size for serialization buffer |
769 | * | 440 | * |
@@ -771,8 +442,8 @@ GNUNET_RECLAIM_ATTRIBUTE_list_count_attest ( | |||
771 | * @return the required buffer size | 442 | * @return the required buffer size |
772 | */ | 443 | */ |
773 | size_t | 444 | size_t |
774 | GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size ( | 445 | GNUNET_RECLAIM_attribute_serialize_get_size ( |
775 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr) | 446 | const struct GNUNET_RECLAIM_Attribute *attr) |
776 | { | 447 | { |
777 | return sizeof(struct Attribute) + strlen (attr->name) + attr->data_size; | 448 | return sizeof(struct Attribute) + strlen (attr->name) + attr->data_size; |
778 | } | 449 | } |
@@ -786,8 +457,8 @@ GNUNET_RECLAIM_ATTRIBUTE_serialize_get_size ( | |||
786 | * @return length of serialized data | 457 | * @return length of serialized data |
787 | */ | 458 | */ |
788 | size_t | 459 | size_t |
789 | GNUNET_RECLAIM_ATTRIBUTE_serialize ( | 460 | GNUNET_RECLAIM_attribute_serialize ( |
790 | const struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr, | 461 | const struct GNUNET_RECLAIM_Attribute *attr, |
791 | char *result) | 462 | char *result) |
792 | { | 463 | { |
793 | size_t data_len_ser; | 464 | size_t data_len_ser; |
@@ -823,10 +494,10 @@ GNUNET_RECLAIM_ATTRIBUTE_serialize ( | |||
823 | * | 494 | * |
824 | * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller | 495 | * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller |
825 | */ | 496 | */ |
826 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim * | 497 | struct GNUNET_RECLAIM_Attribute * |
827 | GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char *data, size_t data_size) | 498 | GNUNET_RECLAIM_attribute_deserialize (const char *data, size_t data_size) |
828 | { | 499 | { |
829 | struct GNUNET_RECLAIM_ATTRIBUTE_Claim *attr; | 500 | struct GNUNET_RECLAIM_Attribute *attr; |
830 | struct Attribute *attr_ser; | 501 | struct Attribute *attr_ser; |
831 | size_t data_len; | 502 | size_t data_len; |
832 | size_t name_len; | 503 | size_t name_len; |
@@ -844,7 +515,7 @@ GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char *data, size_t data_size) | |||
844 | "Buffer too small to deserialize\n"); | 515 | "Buffer too small to deserialize\n"); |
845 | return NULL; | 516 | return NULL; |
846 | } | 517 | } |
847 | attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_ATTRIBUTE_Claim) | 518 | attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_Attribute) |
848 | + data_len + name_len + 1); | 519 | + data_len + name_len + 1); |
849 | attr->type = ntohs (attr_ser->attribute_type); | 520 | attr->type = ntohs (attr_ser->attribute_type); |
850 | attr->flag = ntohl (attr_ser->attribute_flag); | 521 | attr->flag = ntohl (attr_ser->attribute_flag); |
@@ -863,193 +534,4 @@ GNUNET_RECLAIM_ATTRIBUTE_deserialize (const char *data, size_t data_size) | |||
863 | } | 534 | } |
864 | 535 | ||
865 | 536 | ||
866 | /** | ||
867 | * Get required size for serialization buffer | ||
868 | * | ||
869 | * @param attr the attestation to serialize | ||
870 | * @return the required buffer size | ||
871 | */ | ||
872 | size_t | ||
873 | GNUNET_RECLAIM_ATTESTATION_serialize_get_size ( | ||
874 | const struct GNUNET_RECLAIM_ATTESTATION_Claim *attr) | ||
875 | { | ||
876 | return sizeof(struct Attestation) + strlen (attr->name) + attr->data_size; | ||
877 | } | ||
878 | |||
879 | /** | ||
880 | * Serialize an attestation | ||
881 | * | ||
882 | * @param attr the attestation to serialize | ||
883 | * @param result the serialized attestation | ||
884 | * @return length of serialized data | ||
885 | */ | ||
886 | size_t | ||
887 | GNUNET_RECLAIM_ATTESTATION_serialize ( | ||
888 | const struct GNUNET_RECLAIM_ATTESTATION_Claim *attr, | ||
889 | char *result) | ||
890 | { | ||
891 | size_t data_len_ser; | ||
892 | size_t name_len; | ||
893 | struct Attestation *attr_ser; | ||
894 | char *write_ptr; | ||
895 | |||
896 | attr_ser = (struct Attestation *) result; | ||
897 | attr_ser->attestation_type = htons (attr->type); | ||
898 | attr_ser->attestation_flag = htonl (attr->flag); | ||
899 | attr_ser->attestation_id = attr->id; | ||
900 | name_len = strlen (attr->name); | ||
901 | attr_ser->name_len = htons (name_len); | ||
902 | write_ptr = (char *) &attr_ser[1]; | ||
903 | GNUNET_memcpy (write_ptr, attr->name, name_len); | ||
904 | write_ptr += name_len; | ||
905 | // TODO plugin-ize | ||
906 | // data_len_ser = plugin->serialize_attribute_value (attr, | ||
907 | // &attr_ser[1]); | ||
908 | data_len_ser = attr->data_size; | ||
909 | GNUNET_memcpy (write_ptr, attr->data, attr->data_size); | ||
910 | attr_ser->data_size = htons (data_len_ser); | ||
911 | |||
912 | return sizeof(struct Attestation) + strlen (attr->name) + attr->data_size; | ||
913 | } | ||
914 | |||
915 | /** | ||
916 | * Deserialize an attestation | ||
917 | * | ||
918 | * @param data the serialized attestation | ||
919 | * @param data_size the length of the serialized data | ||
920 | * | ||
921 | * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller | ||
922 | */ | ||
923 | struct GNUNET_RECLAIM_ATTESTATION_Claim * | ||
924 | GNUNET_RECLAIM_ATTESTATION_deserialize (const char *data, size_t data_size) | ||
925 | { | ||
926 | struct GNUNET_RECLAIM_ATTESTATION_Claim *attr; | ||
927 | struct Attestation *attr_ser; | ||
928 | size_t data_len; | ||
929 | size_t name_len; | ||
930 | char *write_ptr; | ||
931 | |||
932 | if (data_size < sizeof(struct Attestation)) | ||
933 | return NULL; | ||
934 | |||
935 | attr_ser = (struct Attestation *) data; | ||
936 | data_len = ntohs (attr_ser->data_size); | ||
937 | name_len = ntohs (attr_ser->name_len); | ||
938 | if (data_size < sizeof(struct Attestation) + data_len + name_len) | ||
939 | { | ||
940 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
941 | "Buffer too small to deserialize\n"); | ||
942 | return NULL; | ||
943 | } | ||
944 | attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_ATTESTATION_Claim) | ||
945 | + data_len + name_len + 1); | ||
946 | attr->type = ntohs (attr_ser->attestation_type); | ||
947 | attr->flag = ntohl (attr_ser->attestation_flag); | ||
948 | attr->id = attr_ser->attestation_id; | ||
949 | attr->data_size = data_len; | ||
950 | |||
951 | write_ptr = (char *) &attr[1]; | ||
952 | GNUNET_memcpy (write_ptr, &attr_ser[1], name_len); | ||
953 | write_ptr[name_len] = '\0'; | ||
954 | attr->name = write_ptr; | ||
955 | |||
956 | write_ptr += name_len + 1; | ||
957 | GNUNET_memcpy (write_ptr, (char *) &attr_ser[1] + name_len, attr->data_size); | ||
958 | attr->data = write_ptr; | ||
959 | return attr; | ||
960 | } | ||
961 | |||
962 | /** | ||
963 | * Get required size for serialization buffer | ||
964 | * | ||
965 | * @param attr the reference to serialize | ||
966 | * @return the required buffer size | ||
967 | */ | ||
968 | size_t | ||
969 | GNUNET_RECLAIM_ATTESTATION_REF_serialize_get_size ( | ||
970 | const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr) | ||
971 | { | ||
972 | return sizeof(struct Attestation_Reference) + strlen (attr->name) + strlen ( | ||
973 | attr->reference_value); | ||
974 | } | ||
975 | |||
976 | |||
977 | /** | ||
978 | * Serialize a reference | ||
979 | * | ||
980 | * @param attr the reference to serialize | ||
981 | * @param result the serialized reference | ||
982 | * @return length of serialized data | ||
983 | */ | ||
984 | size_t | ||
985 | GNUNET_RECLAIM_ATTESTATION_REF_serialize ( | ||
986 | const struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr, | ||
987 | char *result) | ||
988 | { | ||
989 | size_t name_len; | ||
990 | size_t refval_len; | ||
991 | struct Attestation_Reference *attr_ser; | ||
992 | char *write_ptr; | ||
993 | attr_ser = (struct Attestation_Reference *) result; | ||
994 | attr_ser->reference_id = attr->id; | ||
995 | attr_ser->attestation_id = attr->id_attest; | ||
996 | name_len = strlen (attr->name); | ||
997 | refval_len = strlen (attr->reference_value); | ||
998 | attr_ser->name_len = htons (name_len); | ||
999 | attr_ser->ref_value_len = htons (refval_len); | ||
1000 | write_ptr = (char *) &attr_ser[1]; | ||
1001 | GNUNET_memcpy (write_ptr, attr->name, name_len); | ||
1002 | write_ptr += name_len; | ||
1003 | GNUNET_memcpy (write_ptr, attr->reference_value, refval_len); | ||
1004 | |||
1005 | return sizeof(struct Attestation_Reference) + strlen (attr->name) + strlen ( | ||
1006 | attr->reference_value); | ||
1007 | } | ||
1008 | |||
1009 | |||
1010 | /** | ||
1011 | * Deserialize a reference | ||
1012 | * | ||
1013 | * @param data the serialized reference | ||
1014 | * @param data_size the length of the serialized data | ||
1015 | * | ||
1016 | * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller | ||
1017 | */ | ||
1018 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE * | ||
1019 | GNUNET_RECLAIM_ATTESTATION_REF_deserialize (const char *data, size_t data_size) | ||
1020 | { | ||
1021 | struct GNUNET_RECLAIM_ATTESTATION_REFERENCE *attr; | ||
1022 | struct Attestation_Reference *attr_ser; | ||
1023 | size_t name_len; | ||
1024 | size_t refval_len; | ||
1025 | char *write_ptr; | ||
1026 | |||
1027 | if (data_size < sizeof(struct Attestation_Reference)) | ||
1028 | return NULL; | ||
1029 | attr_ser = (struct Attestation_Reference *) data; | ||
1030 | name_len = ntohs (attr_ser->name_len); | ||
1031 | refval_len = ntohs (attr_ser->ref_value_len); | ||
1032 | if (data_size < sizeof(struct Attestation_Reference) + refval_len + name_len) | ||
1033 | { | ||
1034 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | ||
1035 | "Buffer too small to deserialize\n"); | ||
1036 | return NULL; | ||
1037 | } | ||
1038 | attr = GNUNET_malloc (sizeof(struct GNUNET_RECLAIM_ATTESTATION_REFERENCE) | ||
1039 | + refval_len + name_len + 2); | ||
1040 | |||
1041 | attr->id = attr_ser->reference_id; | ||
1042 | attr->id_attest = attr_ser->attestation_id; | ||
1043 | |||
1044 | write_ptr = (char *) &attr[1]; | ||
1045 | GNUNET_memcpy (write_ptr, &attr_ser[1], name_len); | ||
1046 | write_ptr[name_len] = '\0'; | ||
1047 | attr->name = write_ptr; | ||
1048 | |||
1049 | write_ptr += name_len + 1; | ||
1050 | GNUNET_memcpy (write_ptr, (char *) &attr_ser[1] + name_len, refval_len); | ||
1051 | write_ptr[refval_len] = '\0'; | ||
1052 | attr->reference_value = write_ptr; | ||
1053 | return attr; | ||
1054 | } | ||
1055 | /* end of reclaim_attribute.c */ | 537 | /* end of reclaim_attribute.c */ |
diff --git a/src/reclaim-attribute/reclaim_attribute.h b/src/reclaim-attribute/reclaim_attribute.h index 0746df48e..e54b210b9 100644 --- a/src/reclaim-attribute/reclaim_attribute.h +++ b/src/reclaim-attribute/reclaim_attribute.h | |||
@@ -49,6 +49,11 @@ struct Attribute | |||
49 | struct GNUNET_RECLAIM_Identifier attribute_id; | 49 | struct GNUNET_RECLAIM_Identifier attribute_id; |
50 | 50 | ||
51 | /** | 51 | /** |
52 | * Attestation ID | ||
53 | */ | ||
54 | struct GNUNET_RECLAIM_Identifier attestation_id; | ||
55 | |||
56 | /** | ||
52 | * Name length | 57 | * Name length |
53 | */ | 58 | */ |
54 | uint32_t name_len; | 59 | uint32_t name_len; |
@@ -94,33 +99,4 @@ struct Attestation | |||
94 | // followed by data_size Attestation value data | 99 | // followed by data_size Attestation value data |
95 | }; | 100 | }; |
96 | 101 | ||
97 | /** | ||
98 | * Serialized attestation reference | ||
99 | */ | ||
100 | struct Attestation_Reference | ||
101 | { | ||
102 | /** | ||
103 | * Reference ID | ||
104 | */ | ||
105 | struct GNUNET_RECLAIM_Identifier reference_id; | ||
106 | |||
107 | /** | ||
108 | * The ID of the referenced attestation | ||
109 | */ | ||
110 | struct GNUNET_RECLAIM_Identifier attestation_id; | ||
111 | |||
112 | /** | ||
113 | * Claim Name length | ||
114 | */ | ||
115 | uint32_t name_len; | ||
116 | |||
117 | /** | ||
118 | * Length of the referenced value | ||
119 | */ | ||
120 | uint32_t ref_value_len; | ||
121 | |||
122 | |||
123 | // followed by the name and referenced value | ||
124 | }; | ||
125 | |||
126 | #endif | 102 | #endif |