diff options
Diffstat (limited to 'src/include/gnunet_identity_service.h')
-rw-r--r-- | src/include/gnunet_identity_service.h | 160 |
1 files changed, 155 insertions, 5 deletions
diff --git a/src/include/gnunet_identity_service.h b/src/include/gnunet_identity_service.h index 94127248e..17714fec4 100644 --- a/src/include/gnunet_identity_service.h +++ b/src/include/gnunet_identity_service.h | |||
@@ -57,6 +57,21 @@ extern "C" { | |||
57 | */ | 57 | */ |
58 | #define GNUNET_IDENTITY_VERSION 0x00000100 | 58 | #define GNUNET_IDENTITY_VERSION 0x00000100 |
59 | 59 | ||
60 | enum GNUNET_IDENTITY_KeyType | ||
61 | { | ||
62 | /** | ||
63 | * The identity type. The value is the same as the | ||
64 | * PKEY record type. | ||
65 | */ | ||
66 | GNUNET_IDENTITY_TYPE_ECDSA = 65536, | ||
67 | |||
68 | /** | ||
69 | * EDDSA identity. The value is the same as the EDKEY | ||
70 | * record type. | ||
71 | */ | ||
72 | GNUNET_IDENTITY_TYPE_EDDSA = 65556 | ||
73 | }; | ||
74 | |||
60 | /** | 75 | /** |
61 | * Handle to access the identity service. | 76 | * Handle to access the identity service. |
62 | */ | 77 | */ |
@@ -67,6 +82,61 @@ struct GNUNET_IDENTITY_Handle; | |||
67 | */ | 82 | */ |
68 | struct GNUNET_IDENTITY_Ego; | 83 | struct GNUNET_IDENTITY_Ego; |
69 | 84 | ||
85 | |||
86 | /** | ||
87 | * A private key for an identity as per LSD0001. | ||
88 | */ | ||
89 | struct GNUNET_IDENTITY_PrivateKey | ||
90 | { | ||
91 | /** | ||
92 | * Type of public key. | ||
93 | * Defined by the GNS zone type value. | ||
94 | * In NBO. | ||
95 | */ | ||
96 | uint32_t type; | ||
97 | |||
98 | union | ||
99 | { | ||
100 | /** | ||
101 | * An ECDSA identity key. | ||
102 | */ | ||
103 | struct GNUNET_CRYPTO_EcdsaPrivateKey ecdsa_key; | ||
104 | |||
105 | /** | ||
106 | * AN EdDSA identtiy key | ||
107 | */ | ||
108 | struct GNUNET_CRYPTO_EddsaPrivateKey eddsa_key; | ||
109 | }; | ||
110 | }; | ||
111 | |||
112 | |||
113 | /** | ||
114 | * An identity key as per LSD0001. | ||
115 | */ | ||
116 | struct GNUNET_IDENTITY_PublicKey | ||
117 | { | ||
118 | /** | ||
119 | * Type of public key. | ||
120 | * Defined by the GNS zone type value. | ||
121 | * In NBO. | ||
122 | */ | ||
123 | uint32_t type; | ||
124 | |||
125 | union | ||
126 | { | ||
127 | /** | ||
128 | * An ECDSA identity key. | ||
129 | */ | ||
130 | struct GNUNET_CRYPTO_EcdsaPublicKey ecdsa_key; | ||
131 | |||
132 | /** | ||
133 | * AN EdDSA identtiy key | ||
134 | */ | ||
135 | struct GNUNET_CRYPTO_EddsaPublicKey eddsa_key; | ||
136 | }; | ||
137 | }; | ||
138 | |||
139 | |||
70 | /** | 140 | /** |
71 | * Handle for an operation with the identity service. | 141 | * Handle for an operation with the identity service. |
72 | */ | 142 | */ |
@@ -79,7 +149,7 @@ struct GNUNET_IDENTITY_Operation; | |||
79 | * @param ego the ego | 149 | * @param ego the ego |
80 | * @return associated ECC key, valid as long as the ego is valid | 150 | * @return associated ECC key, valid as long as the ego is valid |
81 | */ | 151 | */ |
82 | const struct GNUNET_CRYPTO_EcdsaPrivateKey * | 152 | const struct GNUNET_IDENTITY_PrivateKey * |
83 | GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego); | 153 | GNUNET_IDENTITY_ego_get_private_key (const struct GNUNET_IDENTITY_Ego *ego); |
84 | 154 | ||
85 | 155 | ||
@@ -100,7 +170,7 @@ GNUNET_IDENTITY_ego_get_anonymous (void); | |||
100 | */ | 170 | */ |
101 | void | 171 | void |
102 | GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego, | 172 | GNUNET_IDENTITY_ego_get_public_key (struct GNUNET_IDENTITY_Ego *ego, |
103 | struct GNUNET_CRYPTO_EcdsaPublicKey *pk); | 173 | struct GNUNET_IDENTITY_PublicKey *pk); |
104 | 174 | ||
105 | 175 | ||
106 | /** | 176 | /** |
@@ -224,7 +294,7 @@ GNUNET_IDENTITY_disconnect (struct GNUNET_IDENTITY_Handle *h); | |||
224 | typedef void | 294 | typedef void |
225 | (*GNUNET_IDENTITY_CreateContinuation) ( | 295 | (*GNUNET_IDENTITY_CreateContinuation) ( |
226 | void *cls, | 296 | void *cls, |
227 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *pk, | 297 | const struct GNUNET_IDENTITY_PrivateKey *pk, |
228 | const char *emsg); | 298 | const char *emsg); |
229 | 299 | ||
230 | 300 | ||
@@ -234,6 +304,7 @@ typedef void | |||
234 | * @param id identity service to use | 304 | * @param id identity service to use |
235 | * @param name desired name | 305 | * @param name desired name |
236 | * @param privkey desired private key or NULL to create one | 306 | * @param privkey desired private key or NULL to create one |
307 | * @param ktype the type of key to create. Ignored if privkey != NULL. | ||
237 | * @param cont function to call with the result (will only be called once) | 308 | * @param cont function to call with the result (will only be called once) |
238 | * @param cont_cls closure for @a cont | 309 | * @param cont_cls closure for @a cont |
239 | * @return handle to abort the operation | 310 | * @return handle to abort the operation |
@@ -241,7 +312,8 @@ typedef void | |||
241 | struct GNUNET_IDENTITY_Operation * | 312 | struct GNUNET_IDENTITY_Operation * |
242 | GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id, | 313 | GNUNET_IDENTITY_create (struct GNUNET_IDENTITY_Handle *id, |
243 | const char *name, | 314 | const char *name, |
244 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *privkey, | 315 | const struct GNUNET_IDENTITY_PrivateKey *privkey, |
316 | enum GNUNET_IDENTITY_KeyType ktype, | ||
245 | GNUNET_IDENTITY_CreateContinuation cont, | 317 | GNUNET_IDENTITY_CreateContinuation cont, |
246 | void *cont_cls); | 318 | void *cont_cls); |
247 | 319 | ||
@@ -292,6 +364,84 @@ void | |||
292 | GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op); | 364 | GNUNET_IDENTITY_cancel (struct GNUNET_IDENTITY_Operation *op); |
293 | 365 | ||
294 | 366 | ||
367 | /** | ||
368 | * Get the compacted length of a #GNUNET_IDENTITY_PublicKey. | ||
369 | * Compacted means that it returns the minimum number of bytes this | ||
370 | * key is long, as opposed to the union structure inside | ||
371 | * #GNUNET_IDENTITY_PublicKey. | ||
372 | * Useful for compact serializations. | ||
373 | * | ||
374 | * @param key the key. | ||
375 | * @return -1 on error, else the compacted length of the key. | ||
376 | */ | ||
377 | ssize_t | ||
378 | GNUNET_IDENTITY_key_get_length (const struct GNUNET_IDENTITY_PublicKey *key); | ||
379 | |||
380 | |||
381 | /** | ||
382 | * Creates a (Base32) string representation of the public key. | ||
383 | * The resulting string encodes a compacted representation of the key. | ||
384 | * See also #GNUNET_IDENTITY_key_get_length. | ||
385 | * | ||
386 | * @param key the key. | ||
387 | * @return the string representation of the key, or NULL on error. | ||
388 | */ | ||
389 | char * | ||
390 | GNUNET_IDENTITY_public_key_to_string (const struct | ||
391 | GNUNET_IDENTITY_PublicKey *key); | ||
392 | |||
393 | |||
394 | /** | ||
395 | * Creates a (Base32) string representation of the private key. | ||
396 | * The resulting string encodes a compacted representation of the key. | ||
397 | * See also #GNUNET_IDENTITY_key_get_length. | ||
398 | * | ||
399 | * @param key the key. | ||
400 | * @return the string representation of the key, or NULL on error. | ||
401 | */ | ||
402 | char * | ||
403 | GNUNET_IDENTITY_private_key_to_string (const struct | ||
404 | GNUNET_IDENTITY_PrivateKey *key); | ||
405 | |||
406 | |||
407 | /** | ||
408 | * Parses a (Base32) string representation of the public key. | ||
409 | * See also #GNUNET_IDENTITY_public_key_to_string. | ||
410 | * | ||
411 | * @param str the encoded key. | ||
412 | * @param key where to write the key. | ||
413 | * @return GNUNET_SYSERR on error. | ||
414 | */ | ||
415 | enum GNUNET_GenericReturnValue | ||
416 | GNUNET_IDENTITY_public_key_from_string (const char*str, | ||
417 | struct GNUNET_IDENTITY_PublicKey *key); | ||
418 | |||
419 | |||
420 | /** | ||
421 | * Parses a (Base32) string representation of the private key. | ||
422 | * See also #GNUNET_IDENTITY_private_key_to_string. | ||
423 | * | ||
424 | * @param str the encoded key. | ||
425 | * @param key where to write the key. | ||
426 | * @return GNUNET_SYSERR on error. | ||
427 | */ | ||
428 | enum GNUNET_GenericReturnValue | ||
429 | GNUNET_IDENTITY_private_key_from_string (const char*str, | ||
430 | struct GNUNET_IDENTITY_PrivateKey *key); | ||
431 | |||
432 | |||
433 | /** | ||
434 | * Retrieves the public key representation of a private key. | ||
435 | * | ||
436 | * @param privkey the private key. | ||
437 | * @param key the public key result. | ||
438 | * @return GNUNET_SYSERR on error. | ||
439 | */ | ||
440 | enum GNUNET_GenericReturnValue | ||
441 | GNUNET_IDENTITY_key_get_public (const struct GNUNET_IDENTITY_PrivateKey *privkey, | ||
442 | struct GNUNET_IDENTITY_PublicKey *key); | ||
443 | |||
444 | |||
295 | /* ************* convenience API to lookup an ego ***************** */ | 445 | /* ************* convenience API to lookup an ego ***************** */ |
296 | 446 | ||
297 | /** | 447 | /** |
@@ -344,7 +494,7 @@ GNUNET_IDENTITY_ego_lookup_cancel (struct GNUNET_IDENTITY_EgoLookup *el); | |||
344 | typedef void | 494 | typedef void |
345 | (*GNUNET_IDENTITY_EgoSuffixCallback) ( | 495 | (*GNUNET_IDENTITY_EgoSuffixCallback) ( |
346 | void *cls, | 496 | void *cls, |
347 | const struct GNUNET_CRYPTO_EcdsaPrivateKey *priv, | 497 | const struct GNUNET_IDENTITY_PrivateKey *priv, |
348 | const char *ego_name); | 498 | const char *ego_name); |
349 | 499 | ||
350 | 500 | ||