GNUnet  0.11.x
Functions
abd_serialization.c File Reference

API to serialize and deserialize delegation chains and abds. More...

#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_constants.h"
#include "gnunet_abd_service.h"
#include "gnunet_signatures.h"
#include "abd.h"
Include dependency graph for abd_serialization.c:

Go to the source code of this file.

Functions

size_t GNUNET_ABD_delegation_set_get_size (unsigned int ds_count, const struct GNUNET_ABD_DelegationSet *dsr)
 Calculate how many bytes we will need to serialize the given delegation chain. More...
 
ssize_t GNUNET_ABD_delegation_set_serialize (unsigned int d_count, const struct GNUNET_ABD_DelegationSet *dsr, size_t dest_size, char *dest)
 Serizalize the given delegation chain entries and abd. More...
 
int GNUNET_ABD_delegation_set_deserialize (size_t len, const char *src, unsigned int d_count, struct GNUNET_ABD_DelegationSet *dsr)
 Deserialize the given destination. More...
 
size_t GNUNET_ABD_delegates_get_size (unsigned int c_count, const struct GNUNET_ABD_Delegate *cd)
 Calculate how many bytes we will need to serialize the abds. More...
 
ssize_t GNUNET_ABD_delegates_serialize (unsigned int c_count, const struct GNUNET_ABD_Delegate *cd, size_t dest_size, char *dest)
 Serizalize the given abds. More...
 
int GNUNET_ABD_delegates_deserialize (size_t len, const char *src, unsigned int c_count, struct GNUNET_ABD_Delegate *cd)
 Deserialize the given destination. More...
 
size_t GNUNET_ABD_delegation_chain_get_size (unsigned int d_count, const struct GNUNET_ABD_Delegation *dd, unsigned int c_count, const struct GNUNET_ABD_Delegate *cd)
 Calculate how many bytes we will need to serialize the given delegation chain and abd. More...
 
ssize_t GNUNET_ABD_delegation_chain_serialize (unsigned int d_count, const struct GNUNET_ABD_Delegation *dd, unsigned int c_count, const struct GNUNET_ABD_Delegate *cd, size_t dest_size, char *dest)
 Serizalize the given delegation chain entries and abd. More...
 
int GNUNET_ABD_delegation_chain_deserialize (size_t len, const char *src, unsigned int d_count, struct GNUNET_ABD_Delegation *dd, unsigned int c_count, struct GNUNET_ABD_Delegate *cd)
 Deserialize the given destination. More...
 
int GNUNET_ABD_delegate_serialize (struct GNUNET_ABD_Delegate *dele, char **data)
 
struct GNUNET_ABD_DelegateGNUNET_ABD_delegate_deserialize (const char *data, size_t data_size)
 

Detailed Description

API to serialize and deserialize delegation chains and abds.

Author
Martin Schanzenbach

Definition in file abd_serialization.c.

Function Documentation

◆ GNUNET_ABD_delegation_set_get_size()

size_t GNUNET_ABD_delegation_set_get_size ( unsigned int  ds_count,
const struct GNUNET_ABD_DelegationSet dsr 
)

Calculate how many bytes we will need to serialize the given delegation chain.

Calculate how many bytes we will need to serialize the given delegation record.

Parameters
ds_countnumber of delegation chain entries
dsrarray of GNUNET_ABD_DelegationSet
Returns
the required size to serialize

Definition at line 44 of file abd_serialization.c.

References GNUNET_assert, ret, GNUNET_ABD_DelegationSet::subject_attribute_len, and DelegationRecordData::subject_attribute_len.

Referenced by abd_string_to_value().

47 {
48  unsigned int i;
49  size_t ret;
50 
51  ret = sizeof (struct DelegationRecordData) * (ds_count);
52 
53  for (i = 0; i < ds_count; i++)
54  {
55  GNUNET_assert ((ret + dsr[i].subject_attribute_len) >= ret);
56  ret += dsr[i].subject_attribute_len;
57  }
58  return ret;
59 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
uint32_t subject_attribute_len
Subject attributes.
Definition: abd.h:178
Here is the caller graph for this function:

◆ GNUNET_ABD_delegation_set_serialize()

ssize_t GNUNET_ABD_delegation_set_serialize ( unsigned int  d_count,
const struct GNUNET_ABD_DelegationSet dsr,
size_t  dest_size,
char *  dest 
)

Serizalize the given delegation chain entries and abd.

Serizalize the given delegation record entries.

Parameters
d_countnumber of delegation chain entries
dsrarray of GNUNET_ABD_DelegationSet
dest_sizesize of the destination
destwhere to store the result
Returns
the size of the data, -1 on failure

Definition at line 71 of file abd_serialization.c.

References GNUNET_memcpy, GNUNET_ABD_DelegationSet::subject_attribute_len, DelegationRecordData::subject_attribute_len, GNUNET_ABD_DelegationSet::subject_key, and DelegationRecordData::subject_key.

Referenced by abd_string_to_value().

76 {
77  struct DelegationRecordData rec;
78  unsigned int i;
79  size_t off;
80 
81  off = 0;
82  for (i = 0; i < d_count; i++)
83  {
84  rec.subject_attribute_len = htonl ((uint32_t) dsr[i].subject_attribute_len);
85  rec.subject_key = dsr[i].subject_key;
86  if (off + sizeof (rec) > dest_size)
87  return -1;
88  GNUNET_memcpy (&dest[off], &rec, sizeof (rec));
89  off += sizeof (rec);
90  if (0 == dsr[i].subject_attribute_len)
91  continue;
92  if (off + dsr[i].subject_attribute_len > dest_size)
93  return -1;
94  GNUNET_memcpy (&dest[off],
95  dsr[i].subject_attribute,
96  dsr[i].subject_attribute_len);
97  off += dsr[i].subject_attribute_len;
98  }
99  return off;
100 }
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this attribute was delegated to.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint32_t subject_attribute_len
Subject attributes.
Definition: abd.h:178
Here is the caller graph for this function:

◆ GNUNET_ABD_delegation_set_deserialize()

int GNUNET_ABD_delegation_set_deserialize ( size_t  len,
const char *  src,
unsigned int  d_count,
struct GNUNET_ABD_DelegationSet dsr 
)

Deserialize the given destination.

Parameters
lensize of the serialized delegation chain and cred
srcthe serialized data
d_countthe number of delegation chain entries
dsrwhere to put the delegation chain entries
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 113 of file abd_serialization.c.

References GNUNET_memcpy, GNUNET_OK, GNUNET_SYSERR, GNUNET_ABD_DelegationSet::subject_attribute, GNUNET_ABD_DelegationSet::subject_attribute_len, DelegationRecordData::subject_attribute_len, GNUNET_ABD_DelegationSet::subject_key, and DelegationRecordData::subject_key.

Referenced by abd_value_to_string(), and backward_resolution().

118 {
119  struct DelegationRecordData rec;
120  unsigned int i;
121  size_t off;
122 
123  off = 0;
124  for (i = 0; i < d_count; i++)
125  {
126  if (off + sizeof (rec) > len)
127  return GNUNET_SYSERR;
128  GNUNET_memcpy (&rec, &src[off], sizeof (rec));
129  dsr[i].subject_key = rec.subject_key;
130  off += sizeof (rec);
131  dsr[i].subject_attribute_len = ntohl ((uint32_t) rec.subject_attribute_len);
132  if (off + dsr[i].subject_attribute_len > len)
133  return GNUNET_SYSERR;
134  dsr[i].subject_attribute = (char *) &src[off];
135  off += dsr[i].subject_attribute_len;
136  }
137  return GNUNET_OK;
138 }
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this attribute was delegated to.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
const char * subject_attribute
The subject attribute.
uint32_t subject_attribute_len
Subject attributes.
Definition: abd.h:178
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the caller graph for this function:

◆ GNUNET_ABD_delegates_get_size()

size_t GNUNET_ABD_delegates_get_size ( unsigned int  c_count,
const struct GNUNET_ABD_Delegate cd 
)

Calculate how many bytes we will need to serialize the abds.

Parameters
c_countnumber of abd entries
cda #GNUNET_ABD_Credential
Returns
the required size to serialize

Definition at line 150 of file abd_serialization.c.

References GNUNET_assert, GNUNET_ABD_Delegate::issuer_attribute_len, DelegateEntry::issuer_attribute_len, ret, GNUNET_ABD_Delegate::subject_attribute_len, and DelegateEntry::subject_attribute_len.

Referenced by GNUNET_ABD_delegation_chain_get_size(), and GNUNET_ABD_verify().

153 {
154  unsigned int i;
155  size_t ret;
156 
157  ret = sizeof (struct DelegateEntry) * (c_count);
158 
159  for (i = 0; i < c_count; i++)
160  {
161  GNUNET_assert ((ret + cd[i].issuer_attribute_len + cd[i].subject_attribute_len) >= ret);
162  // subject_attribute_len should be 0
163  ret += cd[i].issuer_attribute_len + cd[i].subject_attribute_len;
164  }
165  return ret;
166 }
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
uint32_t subject_attribute_len
Length of the subject attribute.
uint32_t issuer_attribute_len
Length of the issuer attribute.
uint32_t subject_attribute_len
Issuer attribute length.
Definition: abd.h:280
uint32_t issuer_attribute_len
Issuer subject attribute length.
Definition: abd.h:275
Here is the caller graph for this function:

◆ GNUNET_ABD_delegates_serialize()

ssize_t GNUNET_ABD_delegates_serialize ( unsigned int  c_count,
const struct GNUNET_ABD_Delegate cd,
size_t  dest_size,
char *  dest 
)

Serizalize the given abds.

Parameters
c_countnumber of abd entries
cda #GNUNET_ABD_Credential
dest_sizesize of the destination
destwhere to store the result
Returns
the size of the data, -1 on failure

Definition at line 177 of file abd_serialization.c.

References expiration, DelegateEntry::expiration, GNUNET_htonll(), GNUNET_memcpy, GNUNET_SIGNATURE_PURPOSE_DELEGATE, GNUNET_ABD_Delegate::issuer_attribute_len, DelegateEntry::issuer_attribute_len, GNUNET_ABD_Delegate::issuer_key, DelegateEntry::issuer_key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, DelegateEntry::purpose, GNUNET_ABD_Delegate::signature, DelegateEntry::signature, GNUNET_CRYPTO_EccSignaturePurpose::size, GNUNET_ABD_Delegate::subject_key, and DelegateEntry::subject_key.

Referenced by GNUNET_ABD_delegation_chain_serialize(), and GNUNET_ABD_verify().

182 {
183  struct DelegateEntry c_rec;
184  unsigned int i;
185  size_t off;
186 
187  off = 0;
188  for (i = 0; i < c_count; i++)
189  {
190  //c_rec.subject_attribute_len = htonl ((uint32_t) cd[i].subject_attribute_len);
191  c_rec.issuer_attribute_len = htonl ((uint32_t) cd[i].issuer_attribute_len);
192  c_rec.issuer_key = cd[i].issuer_key;
193  c_rec.subject_key = cd[i].subject_key;
194  c_rec.signature = cd[i].signature;
195  c_rec.purpose.purpose = htonl (GNUNET_SIGNATURE_PURPOSE_DELEGATE);
196  c_rec.purpose.size =
197  htonl ((sizeof (struct DelegateEntry) + cd[i].issuer_attribute_len) -
198  sizeof (struct GNUNET_CRYPTO_EcdsaSignature));
199  c_rec.expiration = GNUNET_htonll (cd[i].expiration.abs_value_us);
200  if (off + sizeof (c_rec) > dest_size)
201  return -1;
202  GNUNET_memcpy (&dest[off], &c_rec, sizeof (c_rec));
203  off += sizeof (c_rec);
204  if (off + cd[i].issuer_attribute_len > dest_size)
205  return -1;
206  GNUNET_memcpy (&dest[off],
207  cd[i].issuer_attribute,
208  cd[i].issuer_attribute_len);
209  off += cd[i].issuer_attribute_len;
210  }
211 
212  return off;
213 }
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this credential was issued to.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature of this credential.
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
The issuer of the credential.
an ECC signature using ECDSA
static char * expiration
Credential TTL.
Definition: gnunet-abd.c:96
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:35
uint32_t issuer_attribute_len
Length of the issuer attribute.
uint32_t issuer_attribute_len
Issuer subject attribute length.
Definition: abd.h:275
#define GNUNET_SIGNATURE_PURPOSE_DELEGATE
Signature for a GNUnet credential.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_ABD_delegates_deserialize()

int GNUNET_ABD_delegates_deserialize ( size_t  len,
const char *  src,
unsigned int  c_count,
struct GNUNET_ABD_Delegate cd 
)

Deserialize the given destination.

Parameters
lensize of the serialized creds
srcthe serialized data
c_countthe number of abd entries
cdwhere to put the abd data
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 226 of file abd_serialization.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_ABD_Delegate::expiration, DelegateEntry::expiration, GNUNET_memcpy, GNUNET_ntohll(), GNUNET_OK, GNUNET_SYSERR, GNUNET_ABD_Delegate::issuer_attribute, GNUNET_ABD_Delegate::issuer_attribute_len, DelegateEntry::issuer_attribute_len, GNUNET_ABD_Delegate::issuer_key, DelegateEntry::issuer_key, GNUNET_ABD_Delegate::signature, DelegateEntry::signature, GNUNET_ABD_Delegate::subject_attribute_len, GNUNET_ABD_Delegate::subject_key, and DelegateEntry::subject_key.

Referenced by GNUNET_ABD_delegation_chain_deserialize(), and handle_verify().

230 {
231  struct DelegateEntry c_rec;
232  unsigned int i;
233  size_t off;
234 
235  off = 0;
236  for (i = 0; i < c_count; i++)
237  {
238  if (off + sizeof (c_rec) > len)
239  return GNUNET_SYSERR;
240  GNUNET_memcpy (&c_rec, &src[off], sizeof (c_rec));
241  cd[i].issuer_attribute_len = ntohl ((uint32_t) c_rec.issuer_attribute_len);
242  cd[i].issuer_key = c_rec.issuer_key;
243  cd[i].subject_key = c_rec.subject_key;
244  cd[i].signature = c_rec.signature;
245  cd[i].expiration.abs_value_us = GNUNET_ntohll (c_rec.expiration);
246  off += sizeof (c_rec);
247  if (off + cd[i].issuer_attribute_len > len)
248  return GNUNET_SYSERR;
249  cd[i].issuer_attribute = &src[off];
250  off += cd[i].issuer_attribute_len;
251  cd[i].subject_attribute_len = 0;
252  }
253  return GNUNET_OK;
254 }
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this credential was issued to.
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature of this credential.
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
The issuer of the credential.
uint64_t abs_value_us
The actual value.
uint32_t subject_attribute_len
Length of the subject attribute.
uint32_t issuer_attribute_len
Length of the issuer attribute.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
struct GNUNET_TIME_Absolute expiration
Expiration of this credential.
uint32_t issuer_attribute_len
Issuer subject attribute length.
Definition: abd.h:275
const char * issuer_attribute
The issuer attribute.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:48
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_ABD_delegation_chain_get_size()

size_t GNUNET_ABD_delegation_chain_get_size ( unsigned int  d_count,
const struct GNUNET_ABD_Delegation dd,
unsigned int  c_count,
const struct GNUNET_ABD_Delegate cd 
)

Calculate how many bytes we will need to serialize the given delegation chain and abd.

Parameters
d_countnumber of delegation chain entries
ddarray of GNUNET_ABD_Delegation
c_countnumber of abd entries
cda #GNUNET_ABD_Credential
Returns
the required size to serialize

Definition at line 268 of file abd_serialization.c.

References GNUNET_ABD_delegates_get_size(), GNUNET_assert, GNUNET_ABD_Delegation::issuer_attribute_len, ChainEntry::issuer_attribute_len, ret, GNUNET_ABD_Delegation::subject_attribute_len, and ChainEntry::subject_attribute_len.

Referenced by send_intermediate_response(), and send_lookup_response().

273 {
274  unsigned int i;
275  size_t ret;
276 
277  ret = sizeof (struct ChainEntry) * (d_count);
278 
279  for (i = 0; i < d_count; i++)
280  {
281  GNUNET_assert (
282  (ret + dd[i].issuer_attribute_len + dd[i].subject_attribute_len) >= ret);
283  ret += dd[i].issuer_attribute_len + dd[i].subject_attribute_len;
284  }
285  return ret + GNUNET_ABD_delegates_get_size (c_count, cd);
286 }
uint32_t issuer_attribute_len
Length of the attribute.
#define GNUNET_assert(cond)
Use this for fatal errors that cannot be handled.
uint32_t issuer_attribute_len
Issuer attributes.
Definition: abd.h:197
static int ret
Return value of the commandline.
Definition: gnunet-abd.c:81
uint32_t subject_attribute_len
Subject attributes.
Definition: abd.h:202
size_t GNUNET_ABD_delegates_get_size(unsigned int c_count, const struct GNUNET_ABD_Delegate *cd)
Calculate how many bytes we will need to serialize the abds.
uint32_t subject_attribute_len
Length of the attribute.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_ABD_delegation_chain_serialize()

ssize_t GNUNET_ABD_delegation_chain_serialize ( unsigned int  d_count,
const struct GNUNET_ABD_Delegation dd,
unsigned int  c_count,
const struct GNUNET_ABD_Delegate cd,
size_t  dest_size,
char *  dest 
)

Serizalize the given delegation chain entries and abd.

Parameters
d_countnumber of delegation chain entries
ddarray of GNUNET_ABD_Delegation
c_countnumber of abd entries
cda #GNUNET_ABD_Credential
dest_sizesize of the destination
destwhere to store the result
Returns
the size of the data, -1 on failure

Definition at line 300 of file abd_serialization.c.

References GNUNET_ABD_delegates_serialize(), GNUNET_memcpy, GNUNET_ABD_Delegation::issuer_attribute_len, ChainEntry::issuer_attribute_len, GNUNET_ABD_Delegation::issuer_key, ChainEntry::issuer_key, GNUNET_ABD_Delegation::subject_attribute_len, ChainEntry::subject_attribute_len, GNUNET_ABD_Delegation::subject_key, and ChainEntry::subject_key.

Referenced by send_intermediate_response(), and send_lookup_response().

307 {
308  struct ChainEntry rec;
309  unsigned int i;
310  size_t off;
311 
312  off = 0;
313  for (i = 0; i < d_count; i++)
314  {
315  rec.issuer_attribute_len = htonl ((uint32_t) dd[i].issuer_attribute_len);
316  rec.subject_attribute_len = htonl ((uint32_t) dd[i].subject_attribute_len);
317  rec.issuer_key = dd[i].issuer_key;
318  rec.subject_key = dd[i].subject_key;
319  if (off + sizeof (rec) > dest_size)
320  return -1;
321  GNUNET_memcpy (&dest[off], &rec, sizeof (rec));
322  off += sizeof (rec);
323  if (off + dd[i].issuer_attribute_len > dest_size)
324  return -1;
325  GNUNET_memcpy (&dest[off],
326  dd[i].issuer_attribute,
327  dd[i].issuer_attribute_len);
328  off += dd[i].issuer_attribute_len;
329  if (0 == dd[i].subject_attribute_len)
330  continue;
331  if (off + dd[i].subject_attribute_len > dest_size)
332  return -1;
333  GNUNET_memcpy (&dest[off],
334  dd[i].subject_attribute,
335  dd[i].subject_attribute_len);
336  off += dd[i].subject_attribute_len;
337  }
338  return off + GNUNET_ABD_delegates_serialize (c_count,
339  cd,
340  dest_size - off,
341  &dest[off]);
342 }
uint32_t issuer_attribute_len
Length of the attribute.
uint32_t issuer_attribute_len
Issuer attributes.
Definition: abd.h:197
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
ssize_t GNUNET_ABD_delegates_serialize(unsigned int c_count, const struct GNUNET_ABD_Delegate *cd, size_t dest_size, char *dest)
Serizalize the given abds.
uint32_t subject_attribute_len
Subject attributes.
Definition: abd.h:202
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
The issuer of the delegation.
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this attribute was delegated to.
uint32_t subject_attribute_len
Length of the attribute.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_ABD_delegation_chain_deserialize()

int GNUNET_ABD_delegation_chain_deserialize ( size_t  len,
const char *  src,
unsigned int  d_count,
struct GNUNET_ABD_Delegation dd,
unsigned int  c_count,
struct GNUNET_ABD_Delegate cd 
)

Deserialize the given destination.

Parameters
lensize of the serialized delegation chain and cred
srcthe serialized data
d_countthe number of delegation chain entries
ddwhere to put the delegation chain entries
c_countthe number of abd entries
cdwhere to put the abd data
Returns
GNUNET_OK on success, GNUNET_SYSERR on error

Definition at line 357 of file abd_serialization.c.

References GNUNET_ABD_delegates_deserialize(), GNUNET_memcpy, GNUNET_SYSERR, GNUNET_ABD_Delegation::issuer_attribute, GNUNET_ABD_Delegation::issuer_attribute_len, ChainEntry::issuer_attribute_len, GNUNET_ABD_Delegation::issuer_key, ChainEntry::issuer_key, GNUNET_ABD_Delegation::subject_attribute, GNUNET_ABD_Delegation::subject_attribute_len, ChainEntry::subject_attribute_len, GNUNET_ABD_Delegation::subject_key, and ChainEntry::subject_key.

Referenced by handle_intermediate(), and handle_result().

364 {
365  struct ChainEntry rec;
366  unsigned int i;
367  size_t off;
368 
369  off = 0;
370  for (i = 0; i < d_count; i++)
371  {
372  if (off + sizeof (rec) > len)
373  return GNUNET_SYSERR;
374  GNUNET_memcpy (&rec, &src[off], sizeof (rec));
375  dd[i].issuer_attribute_len = ntohl ((uint32_t) rec.issuer_attribute_len);
376  dd[i].issuer_key = rec.issuer_key;
377  dd[i].subject_key = rec.subject_key;
378  off += sizeof (rec);
379  if (off + dd[i].issuer_attribute_len > len)
380  return GNUNET_SYSERR;
381  dd[i].issuer_attribute = &src[off];
382  off += dd[i].issuer_attribute_len;
383  dd[i].subject_attribute_len = ntohl ((uint32_t) rec.subject_attribute_len);
384  if (off + dd[i].subject_attribute_len > len)
385  return GNUNET_SYSERR;
386  dd[i].subject_attribute = &src[off];
387  off += dd[i].subject_attribute_len;
388  }
390  &src[off],
391  c_count,
392  cd);
393 }
uint32_t issuer_attribute_len
Length of the attribute.
int GNUNET_ABD_delegates_deserialize(size_t len, const char *src, unsigned int c_count, struct GNUNET_ABD_Delegate *cd)
Deserialize the given destination.
uint32_t issuer_attribute_len
Issuer attributes.
Definition: abd.h:197
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint32_t subject_attribute_len
Subject attributes.
Definition: abd.h:202
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
The issuer of the delegation.
#define GNUNET_SYSERR
Definition: gnunet_common.h:76
const char * subject_attribute
The attribute.
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this attribute was delegated to.
const char * issuer_attribute
The attribute.
uint32_t subject_attribute_len
Length of the attribute.
uint16_t len
length of data (which is always a uint32_t, but presumably this can be used to specify that fewer byt...
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_ABD_delegate_serialize()

int GNUNET_ABD_delegate_serialize ( struct GNUNET_ABD_Delegate dele,
char **  data 
)

Definition at line 396 of file abd_serialization.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_ABD_Delegate::expiration, DelegateEntry::expiration, GNUNET_CRYPTO_ecdsa_verify(), GNUNET_ERROR_TYPE_WARNING, GNUNET_htonll(), GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_OK, GNUNET_SIGNATURE_PURPOSE_DELEGATE, GNUNET_ABD_Delegate::issuer_attribute, GNUNET_ABD_Delegate::issuer_attribute_len, DelegateEntry::issuer_attribute_len, GNUNET_ABD_Delegate::issuer_key, DelegateEntry::issuer_key, GNUNET_CRYPTO_EccSignaturePurpose::purpose, DelegateEntry::purpose, GNUNET_ABD_Delegate::signature, DelegateEntry::signature, size, GNUNET_CRYPTO_EccSignaturePurpose::size, GNUNET_ABD_Delegate::subject_attribute, GNUNET_ABD_Delegate::subject_attribute_len, DelegateEntry::subject_attribute_len, GNUNET_ABD_Delegate::subject_key, and DelegateEntry::subject_key.

Referenced by abd_string_to_value(), and store_cb().

398 {
399  size_t size;
400  struct DelegateEntry *cdata;
401  int attr_len;
402 
403  // +1 for \0
404  if (0 == dele->subject_attribute_len)
405  {
406  attr_len = dele->issuer_attribute_len + 1;
407  }
408  else
409  {
410  attr_len = dele->issuer_attribute_len + dele->subject_attribute_len + 2;
411  }
412  size = sizeof (struct DelegateEntry) + attr_len;
413 
414  char tmp_str[attr_len];
415  GNUNET_memcpy (tmp_str, dele->issuer_attribute, dele->issuer_attribute_len);
416  if (0 != dele->subject_attribute_len)
417  {
418  tmp_str[dele->issuer_attribute_len] = '\0';
419  GNUNET_memcpy (tmp_str + dele->issuer_attribute_len + 1,
420  dele->subject_attribute,
421  dele->subject_attribute_len);
422  }
423  tmp_str[attr_len - 1] = '\0';
424 
425  *data = GNUNET_malloc (size);
426  cdata = (struct DelegateEntry *) *data;
427  cdata->subject_key = dele->subject_key;
428  cdata->issuer_key = dele->issuer_key;
430  cdata->signature = dele->signature;
431  cdata->issuer_attribute_len = htonl (dele->issuer_attribute_len + 1);
432  if (0 == dele->subject_attribute_len)
433  {
434  cdata->subject_attribute_len = htonl (0);
435  }
436  else
437  {
438  cdata->subject_attribute_len = htonl (dele->subject_attribute_len + 1);
439  }
441  cdata->purpose.size =
442  htonl (size - sizeof (struct GNUNET_CRYPTO_EcdsaSignature));
443 
444  GNUNET_memcpy (&cdata[1], tmp_str, attr_len);
445 
446  if (GNUNET_OK !=
448  &cdata->purpose,
449  &cdata->signature,
450  &cdata->issuer_key))
451  {
452  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Serialize: Invalid delegate\n");
453  return 0;
454  }
455  return size;
456 }
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this credential was issued to.
int GNUNET_CRYPTO_ecdsa_verify(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EcdsaSignature *sig, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Verify ECDSA signature.
Definition: crypto_ecc.c:1046
uint32_t purpose
What does this signature vouch for? This must contain a GNUNET_SIGNATURE_PURPOSE_XXX constant (from g...
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
Public key of the issuer.
Definition: abd.h:260
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint64_t expiration
Expiration time of this credential.
Definition: abd.h:270
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature of this credential.
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
The issuer of the credential.
uint64_t abs_value_us
The actual value.
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this credential was issued to.
Definition: abd.h:265
uint32_t subject_attribute_len
Length of the subject attribute.
an ECC signature using ECDSA
uint32_t size
How many bytes does this signature sign? (including this purpose header); in network byte order (!)...
struct GNUNET_CRYPTO_EcdsaSignature signature
The signature for this credential by the issuer.
Definition: abd.h:250
uint64_t GNUNET_htonll(uint64_t n)
Convert unsigned 64-bit integer to network byte order.
Definition: common_endian.c:35
uint32_t issuer_attribute_len
Length of the issuer attribute.
static unsigned int size
Size of the "table".
Definition: peer.c:67
const char * subject_attribute
The subject attribute.
uint32_t subject_attribute_len
Issuer attribute length.
Definition: abd.h:280
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Signature meta.
Definition: abd.h:255
#define GNUNET_log(kind,...)
struct GNUNET_TIME_Absolute expiration
Expiration of this credential.
uint32_t issuer_attribute_len
Issuer subject attribute length.
Definition: abd.h:275
const char * issuer_attribute
The issuer attribute.
uint32_t data
The data value.
#define GNUNET_malloc(size)
Wrapper around malloc.
#define GNUNET_SIGNATURE_PURPOSE_DELEGATE
Signature for a GNUnet credential.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ GNUNET_ABD_delegate_deserialize()

struct GNUNET_ABD_Delegate* GNUNET_ABD_delegate_deserialize ( const char *  data,
size_t  data_size 
)

Definition at line 459 of file abd_serialization.c.

References GNUNET_TIME_Absolute::abs_value_us, GNUNET_ABD_Delegate::expiration, DelegateEntry::expiration, GNUNET_CRYPTO_ecdsa_verify(), GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_malloc, GNUNET_memcpy, GNUNET_ntohll(), GNUNET_OK, GNUNET_SIGNATURE_PURPOSE_DELEGATE, GNUNET_ABD_Delegate::issuer_attribute, GNUNET_ABD_Delegate::issuer_attribute_len, DelegateEntry::issuer_attribute_len, GNUNET_ABD_Delegate::issuer_key, DelegateEntry::issuer_key, DelegateEntry::purpose, GNUNET_ABD_Delegate::signature, DelegateEntry::signature, GNUNET_ABD_Delegate::subject_attribute, GNUNET_ABD_Delegate::subject_attribute_len, DelegateEntry::subject_attribute_len, GNUNET_ABD_Delegate::subject_key, and DelegateEntry::subject_key.

Referenced by abd_value_to_string(), forward_resolution(), and handle_delegate_collection_cb().

460 {
461  struct GNUNET_ABD_Delegate *dele;
462  struct DelegateEntry *cdata;
463  char *attr_combo_str;
464 
465  if (data_size < sizeof (struct DelegateEntry))
466  return NULL;
467  cdata = (struct DelegateEntry *) data;
468  if (GNUNET_OK !=
470  &cdata->purpose,
471  &cdata->signature,
472  &cdata->issuer_key))
473  {
474  GNUNET_log (GNUNET_ERROR_TYPE_WARNING, "Deserialize: Invalid delegate\n");
475  return NULL;
476  }
477  attr_combo_str = (char *) &cdata[1];
478  int iss_len = ntohl (cdata->issuer_attribute_len);
479  int sub_len = ntohl (cdata->subject_attribute_len);
480  int attr_combo_len = iss_len + sub_len;
481 
482  dele =
483  GNUNET_malloc (sizeof (struct GNUNET_ABD_Delegate) + attr_combo_len);
484 
485  dele->issuer_key = cdata->issuer_key;
486  dele->subject_key = cdata->subject_key;
487  GNUNET_memcpy (&dele[1], attr_combo_str, attr_combo_len);
488  dele->signature = cdata->signature;
489 
490  // Set the pointers for the attributes
491  dele->issuer_attribute = (char *) &dele[1];
492  dele->issuer_attribute_len = iss_len;
493  dele->subject_attribute_len = sub_len;
494  if (0 == sub_len)
495  {
496  dele->subject_attribute = NULL;
497  }
498  else
499  {
500  dele->subject_attribute = (char *) &dele[1] + iss_len;
501  }
502 
504 
505  return dele;
506 }
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this credential was issued to.
int GNUNET_CRYPTO_ecdsa_verify(uint32_t purpose, const struct GNUNET_CRYPTO_EccSignaturePurpose *validate, const struct GNUNET_CRYPTO_EcdsaSignature *sig, const struct GNUNET_CRYPTO_EcdsaPublicKey *pub)
Verify ECDSA signature.
Definition: crypto_ecc.c:1046
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
Public key of the issuer.
Definition: abd.h:260
static size_t data_size
Number of bytes in data.
Definition: gnunet-abd.c:187
#define GNUNET_memcpy(dst, src, n)
Call memcpy() but check for n being 0 first.
uint64_t expiration
Expiration time of this credential.
Definition: abd.h:270
#define GNUNET_OK
Named constants for return values.
Definition: gnunet_common.h:75
struct GNUNET_CRYPTO_EcdsaSignature signature
Signature of this credential.
struct GNUNET_CRYPTO_EcdsaPublicKey issuer_key
The issuer of the credential.
uint64_t abs_value_us
The actual value.
struct GNUNET_CRYPTO_EcdsaPublicKey subject_key
Public key of the subject this credential was issued to.
Definition: abd.h:265
uint32_t subject_attribute_len
Length of the subject attribute.
struct GNUNET_CRYPTO_EcdsaSignature signature
The signature for this credential by the issuer.
Definition: abd.h:250
uint32_t issuer_attribute_len
Length of the issuer attribute.
const char * subject_attribute
The subject attribute.
uint32_t subject_attribute_len
Issuer attribute length.
Definition: abd.h:280
struct GNUNET_CRYPTO_EccSignaturePurpose purpose
Signature meta.
Definition: abd.h:255
#define GNUNET_log(kind,...)
struct GNUNET_TIME_Absolute expiration
Expiration of this credential.
uint32_t issuer_attribute_len
Issuer subject attribute length.
Definition: abd.h:275
const char * issuer_attribute
The issuer attribute.
uint32_t data
The data value.
#define GNUNET_malloc(size)
Wrapper around malloc.
uint64_t GNUNET_ntohll(uint64_t n)
Convert unsigned 64-bit integer to host byte order.
Definition: common_endian.c:48
#define GNUNET_SIGNATURE_PURPOSE_DELEGATE
Signature for a GNUnet credential.
Here is the call graph for this function:
Here is the caller graph for this function: