aboutsummaryrefslogtreecommitdiff
path: root/src/service/reclaim/did_misc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/service/reclaim/did_misc.c')
-rw-r--r--src/service/reclaim/did_misc.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/src/service/reclaim/did_misc.c b/src/service/reclaim/did_misc.c
new file mode 100644
index 000000000..32b127b2b
--- /dev/null
+++ b/src/service/reclaim/did_misc.c
@@ -0,0 +1,70 @@
1/*
2 This file is part of GNUnet.
3 Copyright (C) 2012-2022 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 * @author Martin Schanzenbach
23 * @file src/reclaim/did_misc.c
24 * @brief Helper functions for DIDs
25 *
26 */
27#include "platform.h"
28#include "gnunet_util_lib.h"
29#include "gnunet_identity_service.h"
30#include "jansson.h"
31#include "did.h"
32
33char*
34DID_ego_to_did (struct GNUNET_IDENTITY_Ego *ego)
35{
36 struct GNUNET_CRYPTO_PublicKey pkey; // Get Public key
37 char *pkey_str;
38 char *did_str;
39 size_t pkey_len;
40
41 GNUNET_IDENTITY_ego_get_public_key (ego, &pkey);
42
43 pkey_str = GNUNET_CRYPTO_public_key_to_string (&pkey);
44 GNUNET_asprintf (&did_str, "%s%s",
45 GNUNET_RECLAIM_DID_METHOD_PREFIX,
46 pkey_str);
47
48 GNUNET_free (pkey_str);
49 return did_str;
50}
51
52enum GNUNET_GenericReturnValue
53DID_public_key_from_did (const char* did,
54 struct GNUNET_CRYPTO_PublicKey *pk)
55{
56 /* FIXME-MSC: I suggest introducing a
57 * #define MAX_DID_LENGTH <something>
58 * here and use it for parsing
59 */
60 char pkey_str[59];
61
62 if ((1 != (sscanf (did, GNUNET_RECLAIM_DID_METHOD_PREFIX"%58s", pkey_str))) ||
63 (GNUNET_OK != GNUNET_CRYPTO_public_key_from_string (pkey_str, pk)))
64 {
65 return GNUNET_SYSERR;
66 }
67 return GNUNET_OK;
68}
69
70