aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim/did_core.c
diff options
context:
space:
mode:
authorTristan Schwieren <tristan.schwieren@tum.de>2022-06-29 16:47:44 +0200
committerTristan Schwieren <tristan.schwieren@tum.de>2022-06-29 16:47:44 +0200
commitb50b97b20e986129f2da30eb0754a9921b80c4b3 (patch)
tree52aaa8b5fcc2ccb4c2d48322fafc65bdad1c3612 /src/reclaim/did_core.c
parentd3de2f84f551501f70851c8df4fbd8e5779f248e (diff)
downloadgnunet-b50b97b20e986129f2da30eb0754a9921b80c4b3.tar.gz
gnunet-b50b97b20e986129f2da30eb0754a9921b80c4b3.zip
- non working DID lib create func
Diffstat (limited to 'src/reclaim/did_core.c')
-rw-r--r--src/reclaim/did_core.c99
1 files changed, 66 insertions, 33 deletions
diff --git a/src/reclaim/did_core.c b/src/reclaim/did_core.c
index 0690a654b..dea1c82c3 100644
--- a/src/reclaim/did_core.c
+++ b/src/reclaim/did_core.c
@@ -113,9 +113,26 @@ DID_resolve (const char *did,
113// ------------------------------------------------ // 113// ------------------------------------------------ //
114 114
115static void 115static void
116DID_create_did_store_cb () 116DID_create_did_store_cb (void *cls,
117 int32_t success,
118 const char *emsg)
117{ 119{
118 return; 120 if (GNUNET_OK == success)
121 {
122 // TEST
123 struct GNUNET_IDENTITY_PublicKey *pkey_test;
124 GNUNET_IDENTITY_ego_get_public_key ((struct GNUNET_IDENTITY_Ego *) closure,
125 pkey_test);
126 printf ("pkey1: %s\n", GNUNET_IDENTITY_public_key_to_string (pkey_test));
127
128 printf ("cls3: %s\n", (char *) closure);
129 action_cb (GNUNET_OK, closure);
130 }
131 else
132 {
133 printf ("%s\n", emsg);
134 action_cb (GNUNET_NO, closure);
135 }
119} 136}
120 137
121/** 138/**
@@ -126,37 +143,43 @@ DID_create_did_store_cb ()
126 */ 143 */
127static enum GNUNET_GenericReturnValue 144static enum GNUNET_GenericReturnValue
128DID_create_did_store (struct GNUNET_NAMESTORE_Handle *namestore_handle, 145DID_create_did_store (struct GNUNET_NAMESTORE_Handle *namestore_handle,
129 char *didd_str, struct GNUNET_IDENTITY_Ego *ego) 146 char *didd_str, struct GNUNET_IDENTITY_Ego *ego)
130{ 147{
131 148
132 struct GNUNET_TIME_Relative expire_time; 149 struct GNUNET_TIME_Relative expire_time;
133 struct GNUNET_GNSRECORD_Data record_data; 150 struct GNUNET_GNSRECORD_Data record_data;
134 const struct GNUNET_IDENTITY_PrivateKey *skey; 151 const struct GNUNET_IDENTITY_PrivateKey *skey;
135 152
136 if (GNUNET_STRINGS_fancy_time_to_relative ((GNUNET_OK == 153 if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (
137 DID_DOCUMENT_DEFAULT_EXPIRATION_TIME), 154 DID_DOCUMENT_DEFAULT_EXPIRATION_TIME, &expire_time))
138 &expire_time))
139 { 155 {
140 record_data.data = didd_str;
141 record_data.expiration_time = expire_time.rel_value_us;
142 record_data.data_size = strlen (didd_str) + 1;
143 record_data.record_type = GNUNET_GNSRECORD_typename_to_number ("TXT"),
144 record_data.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
145
146 skey = GNUNET_IDENTITY_ego_get_private_key (ego);
147
148 GNUNET_NAMESTORE_records_store (namestore_handle,
149 skey,
150 GNUNET_GNS_EMPTY_LABEL_AT,
151 1, // FIXME what if GNUNET_GNS_EMPTY_LABEL_AT has records
152 &record_data,
153 &DID_create_did_store_cb,
154 NULL);
155 }
156 else {
157 printf ("Failed to read given expiration time\n"); 156 printf ("Failed to read given expiration time\n");
158 return GNUNET_NO; 157 return GNUNET_NO;
159 } 158 }
159
160 record_data.data = didd_str;
161 record_data.expiration_time = expire_time.rel_value_us;
162 record_data.data_size = strlen (didd_str) + 1;
163 record_data.record_type = GNUNET_GNSRECORD_typename_to_number ("TXT"),
164 record_data.flags = GNUNET_GNSRECORD_RF_RELATIVE_EXPIRATION;
165
166 skey = GNUNET_IDENTITY_ego_get_private_key (ego);
167
168 // TEST
169 struct GNUNET_IDENTITY_PublicKey *pkey_test;
170 GNUNET_IDENTITY_ego_get_public_key ((struct GNUNET_IDENTITY_Ego *) closure,
171 pkey_test);
172 printf ("pkey1: %s\n", GNUNET_IDENTITY_public_key_to_string (pkey_test));
173
174 GNUNET_NAMESTORE_records_store (namestore_handle,
175 skey,
176 DID_DOCUMENT_LABEL,
177 1, // FIXME what if GNUNET_GNS_EMPTY_LABEL_AT has records
178 &record_data,
179 &DID_create_did_store_cb,
180 NULL);
181
182 return GNUNET_OK;
160} 183}
161 184
162// TODO: Expiration time missing 185// TODO: Expiration time missing
@@ -165,10 +188,8 @@ DID_create_did_store (struct GNUNET_NAMESTORE_Handle *namestore_handle,
165 * @brief Creates a DID and saves DID Document in Namestore. 188 * @brief Creates a DID and saves DID Document in Namestore.
166 * 189 *
167 * @param ego ego for which the DID should be created. 190 * @param ego ego for which the DID should be created.
168 * If ego==NULL a new ego is created
169 * @param did_document did_document that should be saved in namestore. 191 * @param did_document did_document that should be saved in namestore.
170 * If ego==NULL did_document can also be NULL. 192 * If did_document==NULL -> Default DID document is created.
171 * Default DID document is created.
172 * @param cfg_handle pointer to configuration handle 193 * @param cfg_handle pointer to configuration handle
173 * @param identity_hanlde pointer to identity handle. Can be NULL if ego!=NULL 194 * @param identity_hanlde pointer to identity handle. Can be NULL if ego!=NULL
174 * @param namestore_handle 195 * @param namestore_handle
@@ -178,7 +199,7 @@ DID_create_did_store (struct GNUNET_NAMESTORE_Handle *namestore_handle,
178enum GNUNET_GenericReturnValue 199enum GNUNET_GenericReturnValue
179DID_create (const struct GNUNET_IDENTITY_Ego *ego, 200DID_create (const struct GNUNET_IDENTITY_Ego *ego,
180 const char *did_document, 201 const char *did_document,
181 struct GNUNET_CONFIGURATION_Handle *cfg_handle, 202 const struct GNUNET_CONFIGURATION_Handle *cfg_handle,
182 struct GNUNET_IDENTITY_Handle *identity_handle, 203 struct GNUNET_IDENTITY_Handle *identity_handle,
183 struct GNUNET_NAMESTORE_Handle *namestore_handle, 204 struct GNUNET_NAMESTORE_Handle *namestore_handle,
184 DID_action_callback *cont, 205 DID_action_callback *cont,
@@ -188,15 +209,27 @@ DID_create (const struct GNUNET_IDENTITY_Ego *ego,
188 209
189 GNUNET_IDENTITY_ego_get_public_key (ego, &pkey); 210 GNUNET_IDENTITY_ego_get_public_key (ego, &pkey);
190 211
191 if (did_document != NULL) 212 if (ntohl (pkey.type) != GNUNET_GNSRECORD_TYPE_EDKEY)
192 { 213 {
193 printf ( 214 printf ("The EGO has to have an EDDSA key pair\n");
194 "DID Docuement is read from \"did-document\" argument (EXPERIMENTAL)\n"); 215 return GNUNET_NO;
195 } 216 }
217
218 if (did_document != NULL)
219 printf (
220 "DID Docuement is read from \"DID-document\" argument (EXPERIMENTAL)\n");
196 else 221 else
197 {
198 did_document = DID_pkey_to_did_document (&pkey); 222 did_document = DID_pkey_to_did_document (&pkey);
199 }
200 223
201 return GNUNET_OK; 224
225 // TEST
226 struct GNUNET_IDENTITY_PublicKey *pkey_test;
227 GNUNET_IDENTITY_ego_get_public_key ((struct GNUNET_IDENTITY_Ego *) cls,
228 pkey_test);
229 printf ("pkey1: %s\n", GNUNET_IDENTITY_public_key_to_string (pkey_test));
230
231 action_cb = cont;
232 closure = cls;
233
234 return DID_create_did_store (namestore_handle, did_document, ego);
202} 235}