aboutsummaryrefslogtreecommitdiff
path: root/src/reclaim
diff options
context:
space:
mode:
authorTristan Schwieren <tristan.schwieren@tum.de>2022-06-29 12:48:26 +0200
committerTristan Schwieren <tristan.schwieren@tum.de>2022-06-29 12:48:26 +0200
commitd3de2f84f551501f70851c8df4fbd8e5779f248e (patch)
treea77fb1aa182df14774c1598a1d3169a7c1357ffa /src/reclaim
parentec36e49c337b336ed46b1e7d3f26aafce2be008b (diff)
downloadgnunet-d3de2f84f551501f70851c8df4fbd8e5779f248e.tar.gz
gnunet-d3de2f84f551501f70851c8df4fbd8e5779f248e.zip
- started with DID lib create func
Diffstat (limited to 'src/reclaim')
-rw-r--r--src/reclaim/did_core.c102
-rw-r--r--src/reclaim/did_core.h4
2 files changed, 103 insertions, 3 deletions
diff --git a/src/reclaim/did_core.c b/src/reclaim/did_core.c
index 5cecc2972..0690a654b 100644
--- a/src/reclaim/did_core.c
+++ b/src/reclaim/did_core.c
@@ -29,13 +29,18 @@
29 29
30// #define DID_DOCUMENT_LABEL GNUNET_GNS_EMPTY_LABEL_AT 30// #define DID_DOCUMENT_LABEL GNUNET_GNS_EMPTY_LABEL_AT
31#define DID_DOCUMENT_LABEL "didd" 31#define DID_DOCUMENT_LABEL "didd"
32#define DID_DOCUMENT_DEFAULT_EXPIRATION_TIME "1d"
32 33
33static DID_resolve_callback *resolve_cb; 34static DID_resolve_callback *resolve_cb;
34static DID_action_callback *action_cb; 35static DID_action_callback *action_cb;
35static void *closure; 36static void *closure;
36 37
38// ------------------------------------------------ //
39// -------------------- Resolve ------------------- //
40// ------------------------------------------------ //
41
37/** 42/**
38 * @brief GNS lookup callback. Calls the given callback function 43 * @brief GNS lookup callback. Calls the given callback function
39 * and gives it the DID Document. 44 * and gives it the DID Document.
40 * Fails if there is more than one DID record. 45 * Fails if there is more than one DID record.
41 * 46 *
@@ -101,4 +106,97 @@ DID_resolve (const char *did,
101 GNUNET_GNS_LO_DEFAULT, &DID_resolve_gns_lookup_cb, NULL); 106 GNUNET_GNS_LO_DEFAULT, &DID_resolve_gns_lookup_cb, NULL);
102 107
103 return GNUNET_OK; 108 return GNUNET_OK;
104} \ No newline at end of file 109}
110
111// ------------------------------------------------ //
112// -------------------- Create -------------------- //
113// ------------------------------------------------ //
114
115static void
116DID_create_did_store_cb ()
117{
118 return;
119}
120
121/**
122 * @brief Store DID Document in Namestore
123 *
124 * @param didd_str String endoced DID Docuement
125 * @param ego Identity whos DID Document is stored
126 */
127static enum GNUNET_GenericReturnValue
128DID_create_did_store (struct GNUNET_NAMESTORE_Handle *namestore_handle,
129 char *didd_str, struct GNUNET_IDENTITY_Ego *ego)
130{
131
132 struct GNUNET_TIME_Relative expire_time;
133 struct GNUNET_GNSRECORD_Data record_data;
134 const struct GNUNET_IDENTITY_PrivateKey *skey;
135
136 if (GNUNET_STRINGS_fancy_time_to_relative ((GNUNET_OK ==
137 DID_DOCUMENT_DEFAULT_EXPIRATION_TIME),
138 &expire_time))
139 {
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");
158 return GNUNET_NO;
159 }
160}
161
162// TODO: Expiration time missing
163
164/**
165 * @brief Creates a DID and saves DID Document in Namestore.
166 *
167 * @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.
170 * If ego==NULL did_document can also be NULL.
171 * Default DID document is created.
172 * @param cfg_handle pointer to configuration handle
173 * @param identity_hanlde pointer to identity handle. Can be NULL if ego!=NULL
174 * @param namestore_handle
175 * @param cont callback function
176 * @param cls closure
177 */
178enum GNUNET_GenericReturnValue
179DID_create (const struct GNUNET_IDENTITY_Ego *ego,
180 const char *did_document,
181 struct GNUNET_CONFIGURATION_Handle *cfg_handle,
182 struct GNUNET_IDENTITY_Handle *identity_handle,
183 struct GNUNET_NAMESTORE_Handle *namestore_handle,
184 DID_action_callback *cont,
185 void *cls)
186{
187 struct GNUNET_IDENTITY_PublicKey pkey;
188
189 GNUNET_IDENTITY_ego_get_public_key (ego, &pkey);
190
191 if (did_document != NULL)
192 {
193 printf (
194 "DID Docuement is read from \"did-document\" argument (EXPERIMENTAL)\n");
195 }
196 else
197 {
198 did_document = DID_pkey_to_did_document (&pkey);
199 }
200
201 return GNUNET_OK;
202}
diff --git a/src/reclaim/did_core.h b/src/reclaim/did_core.h
index 21a7cbd89..ba5aaf09c 100644
--- a/src/reclaim/did_core.h
+++ b/src/reclaim/did_core.h
@@ -101,7 +101,8 @@ DID_remove (const struct GNUNET_IDENTITY_Ego *ego,
101 * If ego==NULL did_document can also be NULL. 101 * If ego==NULL did_document can also be NULL.
102 * Default DID document is created. 102 * Default DID document is created.
103 * @param cfg_handle pointer to configuration handle 103 * @param cfg_handle pointer to configuration handle
104 * @param identity_hanlde pointer to configuration handle. Can be NULL if ego!=NULL 104 * @param identity_handle pointer to identity handle. Can be NULL if ego!=NULL
105 * @param namestore_handle
105 * @param cont callback function 106 * @param cont callback function
106 * @param cls closure 107 * @param cls closure
107 */ 108 */
@@ -110,6 +111,7 @@ DID_create (const struct GNUNET_IDENTITY_Ego *ego,
110 const char *did_document, 111 const char *did_document,
111 struct GNUNET_CONFIGURATION_Handle *cfg_handle, 112 struct GNUNET_CONFIGURATION_Handle *cfg_handle,
112 struct GNUNET_IDENTITY_Handle *identity_handle, 113 struct GNUNET_IDENTITY_Handle *identity_handle,
114 struct GNUNET_NAMESTORE_Handle *namestore_handle,
113 DID_action_callback *cont, 115 DID_action_callback *cont,
114 void *cls); 116 void *cls);
115 117