-fix records
[oweals/gnunet.git] / src / identity-provider / identity_attribute.h
1 /*
2    This file is part of GNUnet.
3    Copyright (C) 2012-2015 GNUnet e.V.
4
5    GNUnet is free software; you can redistribute it and/or modify
6    it under the terms of the GNU General Public License as published
7    by the Free Software Foundation; either version 3, or (at your
8    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    General Public License for more details.
14
15    You should have received a copy of the GNU General Public License
16    along with GNUnet; see the file COPYING.  If not, write to the
17    Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18    Boston, MA 02110-1301, USA.
19    */
20 /**
21  * @author Martin Schanzenbach
22  * @file identity-provider/identity_attribute.h
23  * @brief GNUnet Identity Provider library
24  *
25  */
26 #ifndef IDENTITY_ATTRIBUTE_H
27 #define IDENTITY_ATTRIBUTE_H
28
29 #include "gnunet_identity_provider_service.h"
30
31 struct Attribute
32 {
33   /**
34    * Attribute type
35    */
36   uint32_t attribute_type;
37
38   /**
39    * Name length
40    */
41   uint32_t name_len;
42   
43   /**
44    * Data size
45    */
46   uint32_t data_size;
47
48   //followed by data_size Attribute value data
49 };
50
51 /**
52  * Get required size for serialization buffer
53  *
54  * @param attrs the attribute list to serialize
55  *
56  * @return the required buffer size
57  */
58 size_t
59 attribute_list_serialize_get_size (const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs);
60
61 void
62 attribute_list_destroy (struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs);
63
64
65 /**
66  * Serialize an attribute list
67  *
68  * @param attrs the attribute list to serialize
69  * @param result the serialized attribute
70  *
71  * @return length of serialized data
72  */
73 size_t
74 attribute_list_serialize (const struct GNUNET_IDENTITY_PROVIDER_AttributeList *attrs,
75                      char *result);
76
77 /**
78  * Deserialize an attribute list
79  *
80  * @param data the serialized attribute list
81  * @param data_size the length of the serialized data
82  *
83  * @return a GNUNET_IDENTITY_PROVIDER_AttributeList, must be free'd by caller
84  */
85 struct GNUNET_IDENTITY_PROVIDER_AttributeList *
86 attribute_list_deserialize (const char* data,
87                             size_t data_size);
88
89
90 /**
91  * Get required size for serialization buffer
92  *
93  * @param attr the attribute to serialize
94  *
95  * @return the required buffer size
96  */
97 size_t
98 attribute_serialize_get_size (const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr);
99
100
101
102 /**
103  * Serialize an attribute
104  *
105  * @param attr the attribute to serialize
106  * @param result the serialized attribute
107  *
108  * @return length of serialized data
109  */
110 size_t
111 attribute_serialize (const struct GNUNET_IDENTITY_PROVIDER_Attribute *attr,
112                      char *result);
113
114 /**
115  * Deserialize an attribute
116  *
117  * @param data the serialized attribute
118  * @param data_size the length of the serialized data
119  *
120  * @return a GNUNET_IDENTITY_PROVIDER_Attribute, must be free'd by caller
121  */
122 struct GNUNET_IDENTITY_PROVIDER_Attribute *
123 attribute_deserialize (const char* data,
124                        size_t data_size);
125
126 /**
127  * Create a new attribute.
128  *
129  * @param name the attribute name
130  * @param type the attribute type
131  * @param data the attribute value
132  * @param data_size the attribute value size
133  * @return the new attribute
134  */
135 struct GNUNET_IDENTITY_PROVIDER_Attribute *
136 attribute_new (const char* attr_name,
137                uint32_t attr_type,
138                const void* data,
139                size_t data_size);
140
141
142 #endif