glitch in the license text detected by hyazinthe, thank you!
[oweals/gnunet.git] / src / credential / credential_serialization.h
1 /*
2      This file is part of GNUnet.
3      Copyright (C) 2009-2013, 2016 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
16
17 /**
18  * @file credential/credential_serialization.h
19  * @brief API to serialize and deserialize delegation chains 
20  * and credentials
21  * @author Martin Schanzenbach
22  */
23 #ifndef CREDENTIAL_SERIALIZATION_H
24 #define CREDENTIAL_SERIALIZATION_H
25
26 #include "platform.h"
27 #include "gnunet_util_lib.h"
28 #include "gnunet_constants.h"
29 #include "gnunet_credential_service.h"
30
31 /**
32  * Calculate how many bytes we will need to serialize
33  * the given delegation record
34  *
35  * @param ds_count number of delegation chain entries
36  * @param dsr array of #GNUNET_CREDENTIAL_Delegation
37  * @return the required size to serialize
38  */
39 size_t
40 GNUNET_CREDENTIAL_delegation_set_get_size (unsigned int ds_count,
41                                            const struct GNUNET_CREDENTIAL_DelegationSet *dsr);
42
43 /**
44  * Serizalize the given delegation record entries
45  *
46  * @param d_count number of delegation chain entries
47  * @param dsr array of #GNUNET_CREDENTIAL_Delegation
48  * @param dest_size size of the destination
49  * @param dest where to store the result
50  * @return the size of the data, -1 on failure
51  */
52 ssize_t
53 GNUNET_CREDENTIAL_delegation_set_serialize (unsigned int d_count,
54                                             const struct GNUNET_CREDENTIAL_DelegationSet *dsr,
55                                             size_t dest_size,
56                                             char *dest);
57
58
59 /**
60  * Deserialize the given destination
61  *
62  * @param len size of the serialized delegation recird
63  * @param src the serialized data
64  * @param d_count the number of delegation chain entries
65  * @param dsr where to put the delegation chain entries
66  * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
67  */
68 int
69 GNUNET_CREDENTIAL_delegation_set_deserialize (size_t len,
70                                               const char *src,
71                                               unsigned int d_count,
72                                               struct GNUNET_CREDENTIAL_DelegationSet *dsr);
73
74   /**
75    * Calculate how many bytes we will need to serialize
76    * the given delegation chain and credential
77    *
78    * @param d_count number of delegation chain entries
79    * @param dd array of #GNUNET_CREDENTIAL_Delegation
80    * @param c_count number of credential entries
81    * @param cd a #GNUNET_CREDENTIAL_Credential
82    * @return the required size to serialize
83    */
84   size_t
85     GNUNET_CREDENTIAL_delegation_chain_get_size (unsigned int d_count,
86                                                  const struct GNUNET_CREDENTIAL_Delegation *dd,
87                                                  unsigned int c_count,
88                                                  const struct GNUNET_CREDENTIAL_Credential *cd);
89
90   /**
91    * Serizalize the given delegation chain entries and credential
92    *
93    * @param d_count number of delegation chain entries
94    * @param dd array of #GNUNET_CREDENTIAL_Delegation
95    * @param c_count number of credential entries
96    * @param cd a #GNUNET_CREDENTIAL_Credential
97    * @param dest_size size of the destination
98    * @param dest where to store the result
99    * @return the size of the data, -1 on failure
100    */
101   ssize_t
102     GNUNET_CREDENTIAL_delegation_chain_serialize (unsigned int d_count,
103                                                   const struct GNUNET_CREDENTIAL_Delegation *dd,
104                                                   unsigned int c_count,
105                                                   const struct GNUNET_CREDENTIAL_Credential *cd,
106                                                   size_t dest_size,
107                                                   char *dest);
108
109
110   /**
111    * Deserialize the given destination
112    *
113    * @param len size of the serialized delegation chain and cred
114    * @param src the serialized data
115    * @param d_count the number of delegation chain entries
116    * @param dd where to put the delegation chain entries
117    * @param c_count number of credential entries
118    * @param cd where to put the credential data
119    * @return #GNUNET_OK on success, #GNUNET_SYSERR on error
120    */
121   int
122     GNUNET_CREDENTIAL_delegation_chain_deserialize (size_t len,
123                                                     const char *src,
124                                                     unsigned int d_count,
125                                                     struct GNUNET_CREDENTIAL_Delegation *dd,
126                                                     unsigned int c_count,
127                                                     struct GNUNET_CREDENTIAL_Credential *cd);
128   size_t
129   GNUNET_CREDENTIAL_credentials_get_size (unsigned int c_count,
130                                           const struct GNUNET_CREDENTIAL_Credential *cd);
131
132 ssize_t
133 GNUNET_CREDENTIAL_credentials_serialize (unsigned int c_count,
134                                          const struct GNUNET_CREDENTIAL_Credential *cd,
135                                          size_t dest_size,
136                                          char *dest);
137
138
139 int
140 GNUNET_CREDENTIAL_credentials_deserialize (size_t len,
141                                            const char *src,
142                                            unsigned int c_count,
143                                            struct GNUNET_CREDENTIAL_Credential *cd);
144
145
146 int
147 GNUNET_CREDENTIAL_credential_serialize (struct GNUNET_CREDENTIAL_Credential *cred,
148                                         char **data);
149
150 struct GNUNET_CREDENTIAL_Credential*
151 GNUNET_CREDENTIAL_credential_deserialize (const char* data,
152                                           size_t data_size);
153 #endif
154 /* end of credential_serialization.h */