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