1 /*
2  * Copyright (c) 2014 Jerry Lundström <lundstrom.jerry@gmail.com>
3  * Copyright (c) 2014 .SE (The Internet Infrastructure Foundation).
4  * Copyright (c) 2014 OpenDNSSEC AB (svb)
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
22  * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
24  * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
25  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
26  * IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  */
29 
30 #ifndef __key_data_h
31 #define __key_data_h
32 
33 #include "db_object.h"
34 
35 struct key_data;
36 struct key_data_list;
37 typedef struct key_data key_data_t;
38 typedef struct key_data_list key_data_list_t;
39 
40 typedef enum key_data_role {
41     KEY_DATA_ROLE_INVALID = -1,
42     KEY_DATA_ROLE_KSK = 1,
43     KEY_DATA_ROLE_ZSK = 2,
44     KEY_DATA_ROLE_CSK = 3
45 } key_data_role_t;
46 extern const db_enum_t key_data_enum_set_role[];
47 
48 #define KEY_DATA_ROLE_SEP(role) ((role) == KEY_DATA_ROLE_KSK || (role) == KEY_DATA_ROLE_CSK)
49 
50 typedef enum key_data_ds_at_parent {
51     KEY_DATA_DS_AT_PARENT_INVALID = -1,
52     KEY_DATA_DS_AT_PARENT_UNSUBMITTED = 0,
53     KEY_DATA_DS_AT_PARENT_SUBMIT = 1,
54     KEY_DATA_DS_AT_PARENT_SUBMITTED = 2,
55     KEY_DATA_DS_AT_PARENT_SEEN = 3,
56     KEY_DATA_DS_AT_PARENT_RETRACT = 4,
57     KEY_DATA_DS_AT_PARENT_RETRACTED = 5
58 } key_data_ds_at_parent_t;
59 extern const db_enum_t key_data_enum_set_ds_at_parent[];
60 
61 #include "key_data_ext.h"
62 #include "zone_db.h"
63 #include "hsm_key.h"
64 
65 /**
66  * A key data object.
67  */
68 struct key_data {
69     db_object_t* dbo;
70     db_value_t id;
71     db_value_t rev;
72     db_value_t zone_id;
73     const zone_db_t* associated_zone_id;
74     zone_db_t* private_zone_id;
75     db_value_t hsm_key_id;
76     const hsm_key_t* associated_hsm_key_id;
77     hsm_key_t* private_hsm_key_id;
78     unsigned int algorithm;
79     unsigned int inception;
80     key_data_role_t role;
81     unsigned int introducing;
82     unsigned int should_revoke;
83     unsigned int standby;
84     unsigned int active_zsk;
85     unsigned int publish;
86     unsigned int active_ksk;
87     key_data_ds_at_parent_t ds_at_parent;
88     unsigned int keytag;
89     unsigned int minimize;
90     key_state_list_t* key_state_list;
91 };
92 
93 /**
94  * Create a new key data object.
95  * \param[in] connection a db_connection_t pointer.
96  * \return a key_data_t pointer or NULL on error.
97  */
98 extern key_data_t* key_data_new(const db_connection_t* connection);
99 
100 /**
101  * Create a new key data object that is a copy of another key data object.
102  * \param[in] key_data a key_data_t pointer.
103  * \return a key_data_t pointer or NULL on error.
104  */
105 extern key_data_t* key_data_new_copy(const key_data_t* key_data);
106 
107 /**
108  * Delete a key data object, this does not delete it from the database.
109  * \param[in] key_data a key_data_t pointer.
110  */
111 extern void key_data_free(key_data_t* key_data);
112 
113 /**
114  * Copy the content of a key data object.
115  * \param[in] key_data a key_data_t pointer.
116  * \param[in] key_data_copy a key_data_t pointer.
117  * \return DB_ERROR_* on failure, otherwise DB_OK.
118  */
119 extern int key_data_copy(key_data_t* key_data, const key_data_t* key_data_copy);
120 
121 /**
122  * Compare two key data objects and return less than, equal to,
123  * or greater than zero if A is found, respectively, to be less than, to match,
124  * or be greater than B.
125  * \param[in] key_data_a a key_data_t pointer.
126  * \param[in] key_data_b a key_data_t pointer.
127  * \return less than, equal to, or greater than zero if A is found, respectively,
128  * to be less than, to match, or be greater than B.
129  */
130 extern int key_data_cmp(const key_data_t* key_data_a, const key_data_t* key_data_b);
131 
132 /**
133  * Set the content of a key data object based on a database result.
134  * \param[in] key_data a key_data_t pointer.
135  * \param[in] result a db_result_t pointer.
136  * \return DB_ERROR_* on failure, otherwise DB_OK.
137  */
138 extern int key_data_from_result(key_data_t* key_data, const db_result_t* result);
139 
140 /**
141  * Get the id of a key data object.
142  * \param[in] key_data a key_data_t pointer.
143  * \return a db_value_t pointer or NULL on error.
144  */
145 extern const db_value_t* key_data_id(const key_data_t* key_data);
146 
147 /**
148  * Get the zone_id of a key data object.
149  * \param[in] key_data a key_data_t pointer.
150  * \return a db_value_t pointer or NULL on error.
151  */
152 extern const db_value_t* key_data_zone_id(const key_data_t* key_data);
153 
154 /**
155  * Get the zone_id object related to a key data object.
156  * The caller will be given ownership of this object and is responsible for freeing it.
157  * \param[in] key_data a key_data_t pointer.
158  * \return a zone_db_t pointer or NULL on error or if no object could be found.
159  */
160 extern zone_db_t* key_data_get_zone(const key_data_t* key_data);
161 
162 /**
163  * Get the hsm_key_id of a key data object.
164  * \param[in] key_data a key_data_t pointer.
165  * \return a db_value_t pointer or NULL on error.
166  */
167 extern const db_value_t* key_data_hsm_key_id(const key_data_t* key_data);
168 
169 /**
170  * Cache the hsm_key_id object related to a key data object.
171  * \param[in] key_data a key_data_t pointer.
172  * \return DB_ERROR_* on failure, otherwise DB_OK.
173  */
174 extern int key_data_cache_hsm_key(key_data_t* key_data);
175 
176 /**
177  * Get the hsm_key_id object related to a key data object.
178  * \param[in] key_data a key_data_t pointer.
179  * \return a hsm_key_t pointer or NULL on error or if no object could be found.
180  */
181 extern const hsm_key_t* key_data_hsm_key(const key_data_t* key_data);
182 
183 /**
184  * Get the hsm_key_id object related to a key data object.
185  * The caller will be given ownership of this object and is responsible for freeing it.
186  * \param[in] key_data a key_data_t pointer.
187  * \return a hsm_key_t pointer or NULL on error or if no object could be found.
188  */
189 extern hsm_key_t* key_data_get_hsm_key(const key_data_t* key_data);
190 
191 /**
192  * Get the algorithm of a key data object. Undefined behavior if `key_data` is NULL.
193  * \param[in] key_data a key_data_t pointer.
194  * \return an unsigned integer.
195  */
196 extern unsigned int key_data_algorithm(const key_data_t* key_data);
197 
198 /**
199  * Get the inception of a key data object. Undefined behavior if `key_data` is NULL.
200  * \param[in] key_data a key_data_t pointer.
201  * \return an unsigned integer.
202  */
203 extern unsigned int key_data_inception(const key_data_t* key_data);
204 
205 /**
206  * Get the role of a key data object.
207  * \param[in] key_data a key_data_t pointer.
208  * \return a key_data_role_t which may be KEY_DATA_ROLE_INVALID on error or if no role has been set.
209  */
210 extern key_data_role_t key_data_role(const key_data_t* key_data);
211 
212 /**
213  * Get the role as text of a key data object.
214  * \param[in] key_data a key_data_t pointer.
215  * \return a character pointer or NULL on error or if no role has been set.
216  */
217 extern const char* key_data_role_text(const key_data_t* key_data);
218 
219 /**
220  * Get the introducing of a key data object. Undefined behavior if `key_data` is NULL.
221  * \param[in] key_data a key_data_t pointer.
222  * \return an unsigned integer.
223  */
224 extern unsigned int key_data_introducing(const key_data_t* key_data);
225 
226 /**
227  * Get the active_zsk of a key data object. Undefined behavior if `key_data` is NULL.
228  * \param[in] key_data a key_data_t pointer.
229  * \return an unsigned integer.
230  */
231 extern unsigned int key_data_active_zsk(const key_data_t* key_data);
232 
233 /**
234  * Get the publish of a key data object. Undefined behavior if `key_data` is NULL.
235  * \param[in] key_data a key_data_t pointer.
236  * \return an unsigned integer.
237  */
238 extern unsigned int key_data_publish(const key_data_t* key_data);
239 
240 /**
241  * Get the active_ksk of a key data object. Undefined behavior if `key_data` is NULL.
242  * \param[in] key_data a key_data_t pointer.
243  * \return an unsigned integer.
244  */
245 extern unsigned int key_data_active_ksk(const key_data_t* key_data);
246 
247 /**
248  * Get the ds_at_parent of a key data object.
249  * \param[in] key_data a key_data_t pointer.
250  * \return a key_data_ds_at_parent_t which may be KEY_DATA_DS_AT_PARENT_INVALID on error or if no ds_at_parent has been set.
251  */
252 extern key_data_ds_at_parent_t key_data_ds_at_parent(const key_data_t* key_data);
253 
254 /**
255  * Get the keytag of a key data object. Undefined behavior if `key_data` is NULL.
256  * \param[in] key_data a key_data_t pointer.
257  * \return an unsigned integer.
258  */
259 extern unsigned int key_data_keytag(const key_data_t* key_data);
260 
261 /**
262  * Get the minimize of a key data object. Undefined behavior if `key_data` is NULL.
263  * \param[in] key_data a key_data_t pointer.
264  * \return an unsigned integer.
265  */
266 extern unsigned int key_data_minimize(const key_data_t* key_data);
267 
268 /**
269  * Get the key_state objects related to a key data object.
270  * \param[in] key_data a key_data_t pointer.
271  * \return a key_state_list_t pointer or NULL on error.
272  */
273 extern key_state_list_t* key_data_key_state_list(key_data_t* key_data);
274 
275 /**
276  * Retrieve key_state objects related to a key data object.
277  * Use key_data_key_state_list() to get the list afterwards.
278  * This will refetch objects if already retrieved.
279  * \param[in] key_data a key_data_t pointer.
280  * \return DB_ERROR_* on failure, otherwise DB_OK.
281  */
282 extern int key_data_retrieve_key_state_list(key_data_t* key_data);
283 
284 /**
285  * Set the zone_id of a key data object. If this fails the original value may have been lost.
286  * \param[in] key_data a key_data_t pointer.
287  * \param[in] zone_id a db_value_t pointer.
288  * \return DB_ERROR_* on failure, otherwise DB_OK.
289  */
290 extern int key_data_set_zone_id(key_data_t* key_data, const db_value_t* zone_id);
291 
292 /**
293  * Set the hsm_key_id of a key data object. If this fails the original value may have been lost.
294  * \param[in] key_data a key_data_t pointer.
295  * \param[in] hsm_key_id a db_value_t pointer.
296  * \return DB_ERROR_* on failure, otherwise DB_OK.
297  */
298 extern int key_data_set_hsm_key_id(key_data_t* key_data, const db_value_t* hsm_key_id);
299 
300 /**
301  * Set the algorithm of a key data object.
302  * \param[in] key_data a key_data_t pointer.
303  * \param[in] algorithm an unsigned integer.
304  * \return DB_ERROR_* on failure, otherwise DB_OK.
305  */
306 extern int key_data_set_algorithm(key_data_t* key_data, unsigned int algorithm);
307 
308 /**
309  * Set the inception of a key data object.
310  * \param[in] key_data a key_data_t pointer.
311  * \param[in] inception an unsigned integer.
312  * \return DB_ERROR_* on failure, otherwise DB_OK.
313  */
314 extern int key_data_set_inception(key_data_t* key_data, unsigned int inception);
315 
316 /**
317  * Set the role of a key data object.
318  * \param[in] key_data a key_data_t pointer.
319  * \param[in] role a key_data_role_t.
320  * \return DB_ERROR_* on failure, otherwise DB_OK.
321  */
322 extern int key_data_set_role(key_data_t* key_data, key_data_role_t role);
323 
324 /**
325  * Set the introducing of a key data object.
326  * \param[in] key_data a key_data_t pointer.
327  * \param[in] introducing an unsigned integer.
328  * \return DB_ERROR_* on failure, otherwise DB_OK.
329  */
330 extern int key_data_set_introducing(key_data_t* key_data, unsigned int introducing);
331 
332 /**
333  * Set the active_zsk of a key data object.
334  * \param[in] key_data a key_data_t pointer.
335  * \param[in] active_zsk an unsigned integer.
336  * \return DB_ERROR_* on failure, otherwise DB_OK.
337  */
338 extern int key_data_set_active_zsk(key_data_t* key_data, unsigned int active_zsk);
339 
340 /**
341  * Set the publish of a key data object.
342  * \param[in] key_data a key_data_t pointer.
343  * \param[in] publish an unsigned integer.
344  * \return DB_ERROR_* on failure, otherwise DB_OK.
345  */
346 extern int key_data_set_publish(key_data_t* key_data, unsigned int publish);
347 
348 /**
349  * Set the active_ksk of a key data object.
350  * \param[in] key_data a key_data_t pointer.
351  * \param[in] active_ksk an unsigned integer.
352  * \return DB_ERROR_* on failure, otherwise DB_OK.
353  */
354 extern int key_data_set_active_ksk(key_data_t* key_data, unsigned int active_ksk);
355 
356 /**
357  * Set the ds_at_parent of a key data object.
358  * \param[in] key_data a key_data_t pointer.
359  * \param[in] ds_at_parent a key_data_ds_at_parent_t.
360  * \return DB_ERROR_* on failure, otherwise DB_OK.
361  */
362 extern int key_data_set_ds_at_parent(key_data_t* key_data, key_data_ds_at_parent_t ds_at_parent);
363 
364 /**
365  * Set the keytag of a key data object.
366  * \param[in] key_data a key_data_t pointer.
367  * \param[in] keytag an unsigned integer.
368  * \return DB_ERROR_* on failure, otherwise DB_OK.
369  */
370 extern int key_data_set_keytag(key_data_t* key_data, unsigned int keytag);
371 
372 /**
373  * Set the minimize of a key data object.
374  * \param[in] key_data a key_data_t pointer.
375  * \param[in] minimize an unsigned integer.
376  * \return DB_ERROR_* on failure, otherwise DB_OK.
377  */
378 extern int key_data_set_minimize(key_data_t* key_data, unsigned int minimize);
379 
380 /**
381  * Create a clause for zone_id of a key data object and add it to a database clause list.
382  * The clause operator is set to DB_CLAUSE_OPERATOR_AND and the clause type is
383  * set to DB_CLAUSE_EQUAL, if you want to change these you can do it with the
384  * returned db_clause_t pointer.
385  * \param[in] clause_list db_clause_list_t pointer.
386  * \param[in] zone_id a db_value_t pointer.
387  * \return a db_clause_t pointer to the added clause or NULL on error.
388  */
389 extern db_clause_t* key_data_zone_id_clause(db_clause_list_t* clause_list, const db_value_t* zone_id);
390 
391 /**
392  * Create a clause for hsm_key_id of a key data object and add it to a database clause list.
393  * The clause operator is set to DB_CLAUSE_OPERATOR_AND and the clause type is
394  * set to DB_CLAUSE_EQUAL, if you want to change these you can do it with the
395  * returned db_clause_t pointer.
396  * \param[in] clause_list db_clause_list_t pointer.
397  * \param[in] hsm_key_id a db_value_t pointer.
398  * \return a db_clause_t pointer to the added clause or NULL on error.
399  */
400 extern db_clause_t* key_data_hsm_key_id_clause(db_clause_list_t* clause_list, const db_value_t* hsm_key_id);
401 
402 /**
403  * Create a clause for role of a key data object and add it to a database clause list.
404  * The clause operator is set to DB_CLAUSE_OPERATOR_AND and the clause type is
405  * set to DB_CLAUSE_EQUAL, if you want to change these you can do it with the
406  * returned db_clause_t pointer.
407  * \param[in] clause_list db_clause_list_t pointer.
408  * \param[in] role a key_data_role_t.
409  * \return a db_clause_t pointer to the added clause or NULL on error.
410  */
411 extern db_clause_t* key_data_role_clause(db_clause_list_t* clause_list, key_data_role_t role);
412 
413 /**
414  * Create a clause for ds_at_parent of a key data object and add it to a database clause list.
415  * The clause operator is set to DB_CLAUSE_OPERATOR_AND and the clause type is
416  * set to DB_CLAUSE_EQUAL, if you want to change these you can do it with the
417  * returned db_clause_t pointer.
418  * \param[in] clause_list db_clause_list_t pointer.
419  * \param[in] ds_at_parent a key_data_ds_at_parent_t.
420  * \return a db_clause_t pointer to the added clause or NULL on error.
421  */
422 extern db_clause_t* key_data_ds_at_parent_clause(db_clause_list_t* clause_list, key_data_ds_at_parent_t ds_at_parent);
423 
424 /**
425  * Create a clause for keytag of a key data object and add it to a database clause list.
426  * The clause operator is set to DB_CLAUSE_OPERATOR_AND and the clause type is
427  * set to DB_CLAUSE_EQUAL, if you want to change these you can do it with the
428  * returned db_clause_t pointer.
429  * \param[in] clause_list db_clause_list_t pointer.
430  * \param[in] keytag an unsigned integer.
431  * \return a db_clause_t pointer to the added clause or NULL on error.
432  */
433 extern db_clause_t* key_data_keytag_clause(db_clause_list_t* clause_list, unsigned int keytag);
434 
435 /**
436  * Create a key data object in the database.
437  * \param[in] key_data a key_data_t pointer.
438  * \return DB_ERROR_* on failure, otherwise DB_OK.
439  */
440 extern int key_data_create(key_data_t* key_data);
441 
442 /**
443  * Get a key data object from the database by a id specified in `id`.
444  * \param[in] key_data a key_data_t pointer.
445  * \param[in] id a db_value_t pointer.
446  * \return DB_ERROR_* on failure, otherwise DB_OK.
447  */
448 extern int key_data_get_by_id(key_data_t* key_data, const db_value_t* id);
449 
450 /**
451  * Update a key data object in the database.
452  * \param[in] key_data a key_data_t pointer.
453  * \return DB_ERROR_* on failure, otherwise DB_OK.
454  */
455 extern int key_data_update(key_data_t* key_data);
456 
457 /**
458  * Delete a key data object from the database.
459  * \param[in] key_data a key_data_t pointer.
460  * \return DB_ERROR_* on failure, otherwise DB_OK.
461  */
462 extern int key_data_delete(key_data_t* key_data);
463 
464 /**
465  * Count the number of key data objects in the database, if a selection of
466  * objects should be counted then it can be limited by a database clause list
467  * otherwise all objects are counted.
468  * \param[in] key_data a key_data_t pointer.
469  * \param[in] clause_list a db_clause_list_t pointer or NULL if all objects.
470  * \param[out] count a size_t pointer to where the count should be stored.
471  * should be counted.
472  * \return DB_ERROR_* on failure, otherwise DB_OK.
473  */
474 extern int key_data_count(key_data_t* key_data, db_clause_list_t* clause_list, size_t* count);
475 
476 /**
477  * A list of key data objects.
478  */
479 struct key_data_list {
480     db_object_t* dbo;
481     db_result_list_t* result_list;
482     const db_result_t* result;
483     key_data_t* key_data;
484     int object_store;
485     key_data_t** object_list;
486     size_t object_list_size;
487     size_t object_list_position;
488     int object_list_first;
489     int associated_fetch;
490     zone_list_db_t* zone_id_list;
491     hsm_key_list_t* hsm_key_id_list;
492 };
493 
494 /**
495  * Create a new key data object list.
496  * \param[in] connection a db_connection_t pointer.
497  * \return a key_data_list_t pointer or NULL on error.
498  */
499 extern key_data_list_t* key_data_list_new(const db_connection_t* connection);
500 
501 /**
502  * Create a new key data object list that is a copy of another.
503  * \param[in] key_data_list a key_data_list_t pointer.
504  * \return a key_data_list_t pointer or NULL on error.
505  */
506 extern key_data_list_t* key_data_list_new_copy(const key_data_list_t* key_data_copy);
507 
508 /**
509  * Specify that objects should be stored within the list as they are fetch,
510  * this is optimal if the list is to be iterated over more then once.
511  * \param[in] key_data_list a key_data_list_t pointer.
512  * \return DB_ERROR_* on failure, otherwise DB_OK.
513  */
514 extern int key_data_list_object_store(key_data_list_t* key_data_list);
515 
516 /**
517  * Delete a key data object list.
518  * \param[in] key_data_list a key_data_list_t pointer.
519  */
520 extern void key_data_list_free(key_data_list_t* key_data_list);
521 
522 /**
523  * Copy the content of another key data object list.
524  * \param[in] key_data_list a key_data_list_t pointer.
525  * \param[in] from_key_data_list a key_data_list_t pointer.
526  * \return DB_ERROR_* on failure, otherwise DB_OK.
527  */
528 extern int key_data_list_copy(key_data_list_t* key_data_list, const key_data_list_t* from_key_data_list);
529 
530 /**
531  * Get all key data objects.
532  * \param[in] key_data_list a key_data_list_t pointer.
533  * \return DB_ERROR_* on failure, otherwise DB_OK.
534  */
535 extern int key_data_list_get(key_data_list_t* key_data_list);
536 
537 /**
538  * Get a new list with all key data objects.
539  * \param[in] connection a db_connection_t pointer.
540  * \return a key_data_list_t pointer or NULL on error.
541  */
542 extern key_data_list_t* key_data_list_new_get(const db_connection_t* connection);
543 
544 /**
545  * Get key data objects from the database by a clause list.
546  * \param[in] key_data_list a key_data_list_t pointer.
547  * \param[in] clause_list a db_clause_list_t pointer.
548  * \return DB_ERROR_* on failure, otherwise DB_OK.
549  */
550 extern int key_data_list_get_by_clauses(key_data_list_t* key_data_list, const db_clause_list_t* clause_list);
551 
552 /**
553  * Get a new list of key data objects from the database by a clause list.
554  * \param[in] connection a db_connection_t pointer.
555  * \param[in] clause_list a db_clause_list_t pointer.
556  * \return a key_data_list_t pointer or NULL on error.
557  */
558 extern key_data_list_t* key_data_list_new_get_by_clauses(const db_connection_t* connection, const db_clause_list_t* clause_list);
559 
560 /**
561  * Get key data objects from the database by a zone_id specified in `zone_id`.
562  * \param[in] key_data_list a key_data_list_t pointer.
563  * \param[in] zone_id a db_value_t pointer.
564  * \return DB_ERROR_* on failure, otherwise DB_OK.
565  */
566 extern int key_data_list_get_by_zone_id(key_data_list_t* key_data_list, const db_value_t* zone_id);
567 
568 /**
569  * Get a new list of key data objects from the database by a zone_id specified in `zone_id`.
570  * \param[in] connection a db_connection_t pointer.
571  * \param[in] zone_id a db_value_t pointer.
572  * \return a key_data_list_t pointer or NULL on error.
573  */
574 extern key_data_list_t* key_data_list_new_get_by_zone_id(const db_connection_t* connection, const db_value_t* zone_id);
575 
576 /**
577  * Get the first key data object in a key data object list and reset the
578  * position of the list.
579  * \param[in] key_data_list a key_data_list_t pointer.
580  * \return a key_data_t pointer or NULL on error or if there are no
581  * key data objects in the key data object list.
582  */
583 extern const key_data_t* key_data_list_begin(key_data_list_t* key_data_list);
584 
585 /**
586  * Get the first key data object in a key data object list and reset the
587  * position of the list. The caller will be given ownership of this object and
588  * is responsible for freeing it.
589  * \param[in] key_data_list a key_data_list_t pointer.
590  * \return a key_data_t pointer or NULL on error or if there are no
591  * key data objects in the key data object list.
592  */
593 extern key_data_t* key_data_list_get_begin(key_data_list_t* key_data_list);
594 
595 /**
596  * Get the next key data object in a key data object list.
597  * Ownership of this object is retained within the list and the object is only
598  * valid until the next call to this function.
599  * \param[in] key_data_list a key_data_list_t pointer.
600  * \return a key_data_t pointer or NULL on error or if there are no more
601  * key data objects in the key data object list.
602  */
603 extern const key_data_t* key_data_list_next(key_data_list_t* key_data_list);
604 
605 /**
606  * Get the next key data object in a key data object list.
607  * The caller will be given ownership of this object and is responsible for
608  * freeing it.
609  * \param[in] key_data_list a key_data_list_t pointer.
610  * \return a key_data_t pointer or NULL on error or if there are no more
611  * key data objects in the key data object list.
612  */
613 extern key_data_t* key_data_list_get_next(key_data_list_t* key_data_list);
614 
615 /**
616  * Get the size of a key data object list.
617  * \param[in] key_data_list a key_data_list_t pointer.
618  * \return a size_t with the size of the list or zero on error, if the list is
619  * empty or if the backend does not support returning the size.
620  */
621 extern size_t key_data_list_size(key_data_list_t* key_data_list);
622 
623 extern key_data_t* key_data_new_get_by_hsm_key_id (const db_connection_t* connection, const db_value_t* hsm_key_id);
624 
625 extern int key_data_get_by_hsm_key_id (key_data_t* key_data, const db_value_t* hsm_key_id);
626 #endif
627