diff options
author | Martin Schanzenbach <mschanzenbach@posteo.de> | 2016-01-07 21:10:24 +0000 |
---|---|---|
committer | Martin Schanzenbach <mschanzenbach@posteo.de> | 2016-01-07 21:10:24 +0000 |
commit | 1b67c9c5424c96ff4e30d12b8d58cec315f000a1 (patch) | |
tree | 65a03cf96bd718d3e57bd2d7f0f0a648cb1986f4 /src/identity | |
parent | 4c2b05fe49e5ee49c69337e763a3572af59e78d5 (diff) | |
download | gnunet-1b67c9c5424c96ff4e30d12b8d58cec315f000a1.tar.gz gnunet-1b67c9c5424c96ff4e30d12b8d58cec315f000a1.zip |
- Finish refactoring
Diffstat (limited to 'src/identity')
-rw-r--r-- | src/identity/plugin_gnsrecord_identity.c | 83 |
1 files changed, 75 insertions, 8 deletions
diff --git a/src/identity/plugin_gnsrecord_identity.c b/src/identity/plugin_gnsrecord_identity.c index a23629b41..fd689490a 100644 --- a/src/identity/plugin_gnsrecord_identity.c +++ b/src/identity/plugin_gnsrecord_identity.c | |||
@@ -44,11 +44,31 @@ value_to_string (void *cls, | |||
44 | const void *data, | 44 | const void *data, |
45 | size_t data_size) | 45 | size_t data_size) |
46 | { | 46 | { |
47 | const struct GNUNET_CRYPTO_EcdhePrivateKey *ecdhe_privkey; | ||
48 | const struct GNUNET_CRYPTO_EcdsaPublicKey *audience_pubkey; | ||
49 | const char *scopes; | ||
50 | char *ecdhe_str; | ||
51 | char *aud_str; | ||
52 | char *result; | ||
53 | |||
47 | switch (type) | 54 | switch (type) |
48 | { | 55 | { |
49 | case GNUNET_GNSRECORD_TYPE_ID_ATTR: | 56 | case GNUNET_GNSRECORD_TYPE_ID_ATTR: |
50 | case GNUNET_GNSRECORD_TYPE_ID_TOKEN: | 57 | case GNUNET_GNSRECORD_TYPE_ID_TOKEN: |
51 | return GNUNET_strndup (data, data_size); | 58 | return GNUNET_strndup (data, data_size); |
59 | case GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA: | ||
60 | ecdhe_privkey = data; | ||
61 | audience_pubkey = data+sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey); | ||
62 | scopes = (char*) audience_pubkey+(sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | ||
63 | ecdhe_str = GNUNET_STRINGS_data_to_string_alloc (ecdhe_privkey, | ||
64 | sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey)); | ||
65 | aud_str = GNUNET_STRINGS_data_to_string_alloc (audience_pubkey, | ||
66 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | ||
67 | GNUNET_asprintf (&result, | ||
68 | "%s;%s;%s", | ||
69 | ecdhe_str, aud_str, scopes); | ||
70 | return result; | ||
71 | |||
52 | default: | 72 | default: |
53 | return NULL; | 73 | return NULL; |
54 | } | 74 | } |
@@ -73,6 +93,12 @@ string_to_value (void *cls, | |||
73 | void **data, | 93 | void **data, |
74 | size_t *data_size) | 94 | size_t *data_size) |
75 | { | 95 | { |
96 | char* ecdhe_str; | ||
97 | char* aud_keystr; | ||
98 | char* write_ptr; | ||
99 | char* tmp_tok; | ||
100 | char* str; | ||
101 | |||
76 | if (NULL == s) | 102 | if (NULL == s) |
77 | return GNUNET_SYSERR; | 103 | return GNUNET_SYSERR; |
78 | switch (type) | 104 | switch (type) |
@@ -82,6 +108,46 @@ string_to_value (void *cls, | |||
82 | *data = GNUNET_strdup (s); | 108 | *data = GNUNET_strdup (s); |
83 | *data_size = strlen (s); | 109 | *data_size = strlen (s); |
84 | return GNUNET_OK; | 110 | return GNUNET_OK; |
111 | case GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA: | ||
112 | tmp_tok = GNUNET_strdup (s); | ||
113 | ecdhe_str = strtok (tmp_tok, ";"); | ||
114 | if (NULL == ecdhe_str) | ||
115 | { | ||
116 | GNUNET_free (tmp_tok); | ||
117 | return GNUNET_SYSERR; | ||
118 | } | ||
119 | aud_keystr = strtok (NULL, ";"); | ||
120 | if (NULL == aud_keystr) | ||
121 | { | ||
122 | GNUNET_free (tmp_tok); | ||
123 | return GNUNET_SYSERR; | ||
124 | } | ||
125 | str = strtok (NULL, ";"); | ||
126 | if (NULL == str) | ||
127 | { | ||
128 | GNUNET_free (tmp_tok); | ||
129 | return GNUNET_SYSERR; | ||
130 | } | ||
131 | *data_size = strlen (str) + 1 | ||
132 | +sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey) | ||
133 | +sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey); | ||
134 | *data = GNUNET_malloc (*data_size); | ||
135 | |||
136 | write_ptr = *data; | ||
137 | GNUNET_STRINGS_string_to_data (ecdhe_str, | ||
138 | strlen (ecdhe_str), | ||
139 | write_ptr, | ||
140 | sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey)); | ||
141 | write_ptr += sizeof (struct GNUNET_CRYPTO_EcdhePrivateKey); | ||
142 | GNUNET_STRINGS_string_to_data (aud_keystr, | ||
143 | strlen (aud_keystr), | ||
144 | write_ptr, | ||
145 | sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey)); | ||
146 | write_ptr += sizeof (struct GNUNET_CRYPTO_EcdsaPublicKey); | ||
147 | memcpy (write_ptr, str, strlen (str) + 1); //with 0-Terminator | ||
148 | GNUNET_free (tmp_tok); | ||
149 | return GNUNET_OK; | ||
150 | |||
85 | default: | 151 | default: |
86 | return GNUNET_SYSERR; | 152 | return GNUNET_SYSERR; |
87 | } | 153 | } |
@@ -92,14 +158,15 @@ string_to_value (void *cls, | |||
92 | * Mapping of record type numbers to human-readable | 158 | * Mapping of record type numbers to human-readable |
93 | * record type names. | 159 | * record type names. |
94 | */ | 160 | */ |
95 | static struct { | 161 | static struct { |
96 | const char *name; | 162 | const char *name; |
97 | uint32_t number; | 163 | uint32_t number; |
98 | } name_map[] = { | 164 | } name_map[] = { |
99 | { "ID_ATTR", GNUNET_GNSRECORD_TYPE_ID_ATTR }, | 165 | { "ID_ATTR", GNUNET_GNSRECORD_TYPE_ID_ATTR }, |
100 | { "ID_TOKEN", GNUNET_GNSRECORD_TYPE_ID_TOKEN }, | 166 | { "ID_TOKEN", GNUNET_GNSRECORD_TYPE_ID_TOKEN }, |
101 | { NULL, UINT32_MAX } | 167 | { "ID_TOKEN_METADATA", GNUNET_GNSRECORD_TYPE_ID_TOKEN_METADATA }, |
102 | }; | 168 | { NULL, UINT32_MAX } |
169 | }; | ||
103 | 170 | ||
104 | 171 | ||
105 | /** | 172 | /** |