key_data.c
Go to the documentation of this file.
/*
* Copyright (c) 2014 Jerry Lundström <lundstrom.jerry@gmail.com>
* Copyright (c) 2014 .SE (The Internet Infrastructure Foundation).
* Copyright (c) 2014 OpenDNSSEC AB (svb)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
*/
#include "key_data.h"
#include "db_error.h"
#include <string.h>
const db_enum_t key_data_enum_set_role[] = {
{ "KSK", (key_data_role_t)KEY_DATA_ROLE_KSK },
{ "ZSK", (key_data_role_t)KEY_DATA_ROLE_ZSK },
{ "CSK", (key_data_role_t)KEY_DATA_ROLE_CSK },
{ NULL, 0 }
};
const db_enum_t key_data_enum_set_ds_at_parent[] = {
{ "unsubmitted", (key_data_ds_at_parent_t)KEY_DATA_DS_AT_PARENT_UNSUBMITTED },
{ "submit", (key_data_ds_at_parent_t)KEY_DATA_DS_AT_PARENT_SUBMIT },
{ "submitted", (key_data_ds_at_parent_t)KEY_DATA_DS_AT_PARENT_SUBMITTED },
{ "seen", (key_data_ds_at_parent_t)KEY_DATA_DS_AT_PARENT_SEEN },
{ "retract", (key_data_ds_at_parent_t)KEY_DATA_DS_AT_PARENT_RETRACT },
{ "retracted", (key_data_ds_at_parent_t)KEY_DATA_DS_AT_PARENT_RETRACTED },
{ NULL, 0 }
};
static db_object_t* __key_data_new_object(const db_connection_t* connection) {
db_object_field_list_t* object_field_list;
db_object_field_t* object_field;
db_object_t* object;
if (!(object = db_object_new())
|| db_object_set_connection(object, connection)
|| db_object_set_table(object, "keyData")
|| db_object_set_primary_key_name(object, "id")
|| !(object_field_list = db_object_field_list_new()))
{
db_object_free(object);
return NULL;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "id")
|| db_object_field_set_type(object_field, DB_TYPE_PRIMARY_KEY)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
db_object_free(object);
return NULL;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "rev")
|| db_object_field_set_type(object_field, DB_TYPE_REVISION)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
db_object_free(object);
return NULL;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "zoneId")
|| db_object_field_set_type(object_field, DB_TYPE_ANY)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
db_object_free(object);
return NULL;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "hsmKeyId")
|| db_object_field_set_type(object_field, DB_TYPE_ANY)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
db_object_free(object);
return NULL;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "algorithm")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
db_object_free(object);
return NULL;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "inception")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
db_object_free(object);
return NULL;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "role")
|| db_object_field_set_type(object_field, DB_TYPE_ENUM)
|| db_object_field_set_enum_set(object_field, key_data_enum_set_role)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
db_object_free(object);
return NULL;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "introducing")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
db_object_free(object);
return NULL;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "shouldRevoke")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
db_object_free(object);
return NULL;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "standby")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
db_object_free(object);
return NULL;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "activeZsk")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
db_object_free(object);
return NULL;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "publish")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
db_object_free(object);
return NULL;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "activeKsk")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
db_object_free(object);
return NULL;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "dsAtParent")
|| db_object_field_set_type(object_field, DB_TYPE_ENUM)
|| db_object_field_set_enum_set(object_field, key_data_enum_set_ds_at_parent)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
db_object_free(object);
return NULL;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "keytag")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
db_object_free(object);
return NULL;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "minimize")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
db_object_free(object);
return NULL;
}
if (db_object_set_object_field_list(object, object_field_list)) {
db_object_field_list_free(object_field_list);
db_object_free(object);
return NULL;
}
return object;
}
/* KEY DATA */
key_data_t* key_data_new(const db_connection_t* connection) {
key_data_t* key_data =
(key_data_t*)calloc(1, sizeof(key_data_t));
if (key_data) {
if (!(key_data->dbo = __key_data_new_object(connection))) {
free(key_data);
return NULL;
}
db_value_reset(&(key_data->id));
db_value_reset(&(key_data->rev));
db_value_reset(&(key_data->zone_id));
db_value_reset(&(key_data->hsm_key_id));
key_data->role = KEY_DATA_ROLE_INVALID;
key_data->introducing = 1;
key_data->ds_at_parent = KEY_DATA_DS_AT_PARENT_UNSUBMITTED;
}
return key_data;
}
key_data_t* key_data_new_copy(const key_data_t* key_data) {
key_data_t* new_key_data;
if (!key_data) {
return NULL;
}
if (!key_data->dbo) {
return NULL;
}
if (!(new_key_data = key_data_new(db_object_connection(key_data->dbo)))
|| key_data_copy(new_key_data, key_data))
{
key_data_free(new_key_data);
return NULL;
}
return new_key_data;
}
void key_data_free(key_data_t* key_data) {
if (key_data) {
if (key_data->dbo) {
db_object_free(key_data->dbo);
}
db_value_reset(&(key_data->id));
db_value_reset(&(key_data->rev));
db_value_reset(&(key_data->zone_id));
if (key_data->private_zone_id) {
zone_db_free(key_data->private_zone_id);
}
db_value_reset(&(key_data->hsm_key_id));
if (key_data->private_hsm_key_id) {
hsm_key_free(key_data->private_hsm_key_id);
}
if (key_data->key_state_list) {
key_state_list_free(key_data->key_state_list);
}
free(key_data);
}
}
int key_data_copy(key_data_t* key_data, const key_data_t* key_data_copy) {
if (!key_data) {
return DB_ERROR_UNKNOWN;
}
if (!key_data_copy) {
return DB_ERROR_UNKNOWN;
}
if (db_value_copy(&(key_data->id), &(key_data_copy->id))) {
return DB_ERROR_UNKNOWN;
}
if (db_value_copy(&(key_data->rev), &(key_data_copy->rev))) {
return DB_ERROR_UNKNOWN;
}
if (db_value_copy(&(key_data->zone_id), &(key_data_copy->zone_id))) {
return DB_ERROR_UNKNOWN;
}
if (key_data->private_zone_id) {
zone_db_free(key_data->private_zone_id);
key_data->private_zone_id = NULL;
}
if (key_data_copy->private_zone_id
&& !(key_data->private_zone_id = zone_db_new_copy(key_data_copy->private_zone_id)))
{
return DB_ERROR_UNKNOWN;
}
key_data->associated_zone_id = NULL;
if (!key_data_copy->private_zone_id
&& key_data_copy->associated_zone_id
&& !(key_data->private_zone_id = zone_db_new_copy(key_data_copy->associated_zone_id)))
{
return DB_ERROR_UNKNOWN;
}
if (db_value_copy(&(key_data->hsm_key_id), &(key_data_copy->hsm_key_id))) {
return DB_ERROR_UNKNOWN;
}
if (key_data->private_hsm_key_id) {
hsm_key_free(key_data->private_hsm_key_id);
key_data->private_hsm_key_id = NULL;
}
if (key_data_copy->private_hsm_key_id
&& !(key_data->private_hsm_key_id = hsm_key_new_copy(key_data_copy->private_hsm_key_id)))
{
return DB_ERROR_UNKNOWN;
}
key_data->associated_hsm_key_id = NULL;
if (!key_data_copy->private_hsm_key_id
&& key_data_copy->associated_hsm_key_id
&& !(key_data->private_hsm_key_id = hsm_key_new_copy(key_data_copy->associated_hsm_key_id)))
{
return DB_ERROR_UNKNOWN;
}
if (key_data->key_state_list) {
key_state_list_free(key_data->key_state_list);
key_data->key_state_list = NULL;
}
if (key_data_copy->key_state_list
&& !(key_data->key_state_list = key_state_list_new_copy(key_data_copy->key_state_list)))
{
return DB_ERROR_UNKNOWN;
}
key_data->algorithm = key_data_copy->algorithm;
key_data->inception = key_data_copy->inception;
key_data->role = key_data_copy->role;
key_data->introducing = key_data_copy->introducing;
key_data->should_revoke = key_data_copy->should_revoke;
key_data->standby = key_data_copy->standby;
key_data->active_zsk = key_data_copy->active_zsk;
key_data->publish = key_data_copy->publish;
key_data->active_ksk = key_data_copy->active_ksk;
key_data->ds_at_parent = key_data_copy->ds_at_parent;
key_data->keytag = key_data_copy->keytag;
key_data->minimize = key_data_copy->minimize;
return DB_OK;
}
int key_data_cmp(const key_data_t* key_data_a, const key_data_t* key_data_b) {
int ret;
if (!key_data_a && !key_data_b) {
return 0;
}
if (!key_data_a && key_data_b) {
return -1;
}
if (key_data_a && !key_data_b) {
return 1;
}
ret = 0;
db_value_cmp(&(key_data_a->zone_id), &(key_data_b->zone_id), &ret);
if (ret) {
return ret;
}
ret = 0;
db_value_cmp(&(key_data_a->hsm_key_id), &(key_data_b->hsm_key_id), &ret);
if (ret) {
return ret;
}
if (key_data_a->algorithm != key_data_b->algorithm) {
return key_data_a->algorithm < key_data_b->algorithm ? -1 : 1;
}
if (key_data_a->inception != key_data_b->inception) {
return key_data_a->inception < key_data_b->inception ? -1 : 1;
}
if (key_data_a->role != key_data_b->role) {
return key_data_a->role < key_data_b->role ? -1 : 1;
}
if (key_data_a->introducing != key_data_b->introducing) {
return key_data_a->introducing < key_data_b->introducing ? -1 : 1;
}
if (key_data_a->should_revoke != key_data_b->should_revoke) {
return key_data_a->should_revoke < key_data_b->should_revoke ? -1 : 1;
}
if (key_data_a->standby != key_data_b->standby) {
return key_data_a->standby < key_data_b->standby ? -1 : 1;
}
if (key_data_a->active_zsk != key_data_b->active_zsk) {
return key_data_a->active_zsk < key_data_b->active_zsk ? -1 : 1;
}
if (key_data_a->publish != key_data_b->publish) {
return key_data_a->publish < key_data_b->publish ? -1 : 1;
}
if (key_data_a->active_ksk != key_data_b->active_ksk) {
return key_data_a->active_ksk < key_data_b->active_ksk ? -1 : 1;
}
if (key_data_a->ds_at_parent != key_data_b->ds_at_parent) {
return key_data_a->ds_at_parent < key_data_b->ds_at_parent ? -1 : 1;
}
if (key_data_a->keytag != key_data_b->keytag) {
return key_data_a->keytag < key_data_b->keytag ? -1 : 1;
}
if (key_data_a->minimize != key_data_b->minimize) {
return key_data_a->minimize < key_data_b->minimize ? -1 : 1;
}
return 0;
}
int key_data_from_result(key_data_t* key_data, const db_result_t* result) {
const db_value_set_t* value_set;
int role;
int ds_at_parent;
if (!key_data) {
return DB_ERROR_UNKNOWN;
}
if (!result) {
return DB_ERROR_UNKNOWN;
}
db_value_reset(&(key_data->id));
db_value_reset(&(key_data->rev));
db_value_reset(&(key_data->zone_id));
db_value_reset(&(key_data->hsm_key_id));
if (!(value_set = db_result_value_set(result))
|| db_value_set_size(value_set) != 16
|| db_value_copy(&(key_data->id), db_value_set_at(value_set, 0))
|| db_value_copy(&(key_data->rev), db_value_set_at(value_set, 1))
|| db_value_copy(&(key_data->zone_id), db_value_set_at(value_set, 2))
|| db_value_copy(&(key_data->hsm_key_id), db_value_set_at(value_set, 3))
|| db_value_to_uint32(db_value_set_at(value_set, 4), &(key_data->algorithm))
|| db_value_to_uint32(db_value_set_at(value_set, 5), &(key_data->inception))
|| db_value_to_enum_value(db_value_set_at(value_set, 6), &role, key_data_enum_set_role)
|| db_value_to_uint32(db_value_set_at(value_set, 7), &(key_data->introducing))
|| db_value_to_uint32(db_value_set_at(value_set, 8), &(key_data->should_revoke))
|| db_value_to_uint32(db_value_set_at(value_set, 9), &(key_data->standby))
|| db_value_to_uint32(db_value_set_at(value_set, 10), &(key_data->active_zsk))
|| db_value_to_uint32(db_value_set_at(value_set, 11), &(key_data->publish))
|| db_value_to_uint32(db_value_set_at(value_set, 12), &(key_data->active_ksk))
|| db_value_to_enum_value(db_value_set_at(value_set, 13), &ds_at_parent, key_data_enum_set_ds_at_parent)
|| db_value_to_uint32(db_value_set_at(value_set, 14), &(key_data->keytag))
|| db_value_to_uint32(db_value_set_at(value_set, 15), &(key_data->minimize)))
{
return DB_ERROR_UNKNOWN;
}
if (role == (key_data_role_t)KEY_DATA_ROLE_KSK) {
key_data->role = KEY_DATA_ROLE_KSK;
}
else if (role == (key_data_role_t)KEY_DATA_ROLE_ZSK) {
key_data->role = KEY_DATA_ROLE_ZSK;
}
else if (role == (key_data_role_t)KEY_DATA_ROLE_CSK) {
key_data->role = KEY_DATA_ROLE_CSK;
}
else {
return DB_ERROR_UNKNOWN;
}
if (ds_at_parent == (key_data_ds_at_parent_t)KEY_DATA_DS_AT_PARENT_UNSUBMITTED) {
key_data->ds_at_parent = KEY_DATA_DS_AT_PARENT_UNSUBMITTED;
}
else if (ds_at_parent == (key_data_ds_at_parent_t)KEY_DATA_DS_AT_PARENT_SUBMIT) {
key_data->ds_at_parent = KEY_DATA_DS_AT_PARENT_SUBMIT;
}
else if (ds_at_parent == (key_data_ds_at_parent_t)KEY_DATA_DS_AT_PARENT_SUBMITTED) {
key_data->ds_at_parent = KEY_DATA_DS_AT_PARENT_SUBMITTED;
}
else if (ds_at_parent == (key_data_ds_at_parent_t)KEY_DATA_DS_AT_PARENT_SEEN) {
key_data->ds_at_parent = KEY_DATA_DS_AT_PARENT_SEEN;
}
else if (ds_at_parent == (key_data_ds_at_parent_t)KEY_DATA_DS_AT_PARENT_RETRACT) {
key_data->ds_at_parent = KEY_DATA_DS_AT_PARENT_RETRACT;
}
else if (ds_at_parent == (key_data_ds_at_parent_t)KEY_DATA_DS_AT_PARENT_RETRACTED) {
key_data->ds_at_parent = KEY_DATA_DS_AT_PARENT_RETRACTED;
}
else {
return DB_ERROR_UNKNOWN;
}
return DB_OK;
}
const db_value_t* key_data_id(const key_data_t* key_data) {
if (!key_data) {
return NULL;
}
return &(key_data->id);
}
const db_value_t* key_data_zone_id(const key_data_t* key_data) {
if (!key_data) {
return NULL;
}
return &(key_data->zone_id);
}
zone_db_t* key_data_get_zone(const key_data_t* key_data) {
zone_db_t* zone_id = NULL;
if (!key_data) {
return NULL;
}
if (!key_data->dbo) {
return NULL;
}
if (db_value_not_empty(&(key_data->zone_id))) {
return NULL;
}
if (!(zone_id = zone_db_new(db_object_connection(key_data->dbo)))) {
return NULL;
}
if (key_data->private_zone_id) {
if (zone_db_copy(zone_id, key_data->private_zone_id)) {
zone_db_free(zone_id);
return NULL;
}
}
else if (key_data->associated_zone_id) {
if (zone_db_copy(zone_id, key_data->associated_zone_id)) {
zone_db_free(zone_id);
return NULL;
}
}
else {
if (zone_db_get_by_id(zone_id, &(key_data->zone_id))) {
zone_db_free(zone_id);
return NULL;
}
}
return zone_id;
}
const db_value_t* key_data_hsm_key_id(const key_data_t* key_data) {
if (!key_data) {
return NULL;
}
return &(key_data->hsm_key_id);
}
int key_data_cache_hsm_key(key_data_t* key_data) {
if (!key_data) {
return DB_ERROR_UNKNOWN;
}
if (key_data->associated_hsm_key_id
|| key_data->private_hsm_key_id)
{
return DB_OK;
}
if (!(key_data->private_hsm_key_id = hsm_key_new(db_object_connection(key_data->dbo)))) {
return DB_ERROR_UNKNOWN;
}
if (hsm_key_get_by_id(key_data->private_hsm_key_id, &(key_data->hsm_key_id))) {
hsm_key_free(key_data->private_hsm_key_id);
key_data->private_hsm_key_id = NULL;
return DB_ERROR_UNKNOWN;
}
return DB_OK;
}
const hsm_key_t* key_data_hsm_key(const key_data_t* key_data) {
if (!key_data) {
return NULL;
}
if (key_data->private_hsm_key_id) {
return key_data->private_hsm_key_id;
}
return key_data->associated_hsm_key_id;
}
hsm_key_t* key_data_get_hsm_key(const key_data_t* key_data) {
hsm_key_t* hsm_key_id = NULL;
if (!key_data) {
return NULL;
}
if (!key_data->dbo) {
return NULL;
}
if (db_value_not_empty(&(key_data->hsm_key_id))) {
return NULL;
}
if (!(hsm_key_id = hsm_key_new(db_object_connection(key_data->dbo)))) {
return NULL;
}
if (key_data->private_hsm_key_id) {
if (hsm_key_copy(hsm_key_id, key_data->private_hsm_key_id)) {
hsm_key_free(hsm_key_id);
return NULL;
}
}
else if (key_data->associated_hsm_key_id) {
if (hsm_key_copy(hsm_key_id, key_data->associated_hsm_key_id)) {
hsm_key_free(hsm_key_id);
return NULL;
}
}
else {
if (hsm_key_get_by_id(hsm_key_id, &(key_data->hsm_key_id))) {
hsm_key_free(hsm_key_id);
return NULL;
}
}
return hsm_key_id;
}
unsigned int key_data_algorithm(const key_data_t* key_data) {
if (!key_data) {
return 0;
}
return key_data->algorithm;
}
unsigned int key_data_inception(const key_data_t* key_data) {
if (!key_data) {
return 0;
}
return key_data->inception;
}
key_data_role_t key_data_role(const key_data_t* key_data) {
if (!key_data) {
return KEY_DATA_ROLE_INVALID;
}
return key_data->role;
}
const char* key_data_role_text(const key_data_t* key_data) {
const db_enum_t* enum_set = key_data_enum_set_role;
if (!key_data) {
return NULL;
}
while (enum_set->text) {
if (enum_set->value == key_data->role) {
return enum_set->text;
}
enum_set++;
}
return NULL;
}
unsigned int key_data_introducing(const key_data_t* key_data) {
if (!key_data) {
return 0;
}
return key_data->introducing;
}
unsigned int key_data_active_zsk(const key_data_t* key_data) {
if (!key_data) {
return 0;
}
return key_data->active_zsk;
}
unsigned int key_data_publish(const key_data_t* key_data) {
if (!key_data) {
return 0;
}
return key_data->publish;
}
unsigned int key_data_active_ksk(const key_data_t* key_data) {
if (!key_data) {
return 0;
}
return key_data->active_ksk;
}
key_data_ds_at_parent_t key_data_ds_at_parent(const key_data_t* key_data) {
if (!key_data) {
return KEY_DATA_DS_AT_PARENT_INVALID;
}
return key_data->ds_at_parent;
}
unsigned int key_data_keytag(const key_data_t* key_data) {
if (!key_data) {
return 0;
}
return key_data->keytag;
}
unsigned int key_data_minimize(const key_data_t* key_data) {
if (!key_data) {
return 0;
}
return key_data->minimize;
}
key_state_list_t* key_data_key_state_list(key_data_t* key_data) {
if (!key_data) {
return NULL;
}
if (!key_data->dbo) {
return NULL;
}
if (!key_data->key_state_list
&& key_data_retrieve_key_state_list(key_data))
{
return NULL;
}
return key_data->key_state_list;
}
int key_data_retrieve_key_state_list(key_data_t* key_data) {
db_clause_list_t* clause_list;
if (!key_data) {
return DB_ERROR_UNKNOWN;
}
if (!key_data->dbo) {
return DB_ERROR_UNKNOWN;
}
if (key_data->key_state_list) {
key_state_list_free(key_data->key_state_list);
key_data->key_state_list = NULL;
}
if (!(clause_list = db_clause_list_new())
|| !key_state_key_data_id_clause(clause_list, key_data_id(key_data))
|| !(key_data->key_state_list = key_state_list_new(db_object_connection(key_data->dbo)))
|| key_state_list_object_store(key_data->key_state_list)
|| key_state_list_get_by_clauses(key_data->key_state_list, clause_list))
{
key_state_list_free(key_data->key_state_list);
key_data->key_state_list = NULL;
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
db_clause_list_free(clause_list);
return DB_OK;
}
int key_data_set_zone_id(key_data_t* key_data, const db_value_t* zone_id) {
if (!key_data) {
return DB_ERROR_UNKNOWN;
}
if (!zone_id) {
return DB_ERROR_UNKNOWN;
}
if (db_value_not_empty(zone_id)) {
return DB_ERROR_UNKNOWN;
}
db_value_reset(&(key_data->zone_id));
if (db_value_copy(&(key_data->zone_id), zone_id)) {
return DB_ERROR_UNKNOWN;
}
return DB_OK;
}
int key_data_set_hsm_key_id(key_data_t* key_data, const db_value_t* hsm_key_id) {
if (!key_data) {
return DB_ERROR_UNKNOWN;
}
if (!hsm_key_id) {
return DB_ERROR_UNKNOWN;
}
if (db_value_not_empty(hsm_key_id)) {
return DB_ERROR_UNKNOWN;
}
db_value_reset(&(key_data->hsm_key_id));
if (db_value_copy(&(key_data->hsm_key_id), hsm_key_id)) {
return DB_ERROR_UNKNOWN;
}
return DB_OK;
}
int key_data_set_algorithm(key_data_t* key_data, unsigned int algorithm) {
if (!key_data) {
return DB_ERROR_UNKNOWN;
}
key_data->algorithm = algorithm;
return DB_OK;
}
int key_data_set_inception(key_data_t* key_data, unsigned int inception) {
if (!key_data) {
return DB_ERROR_UNKNOWN;
}
key_data->inception = inception;
return DB_OK;
}
int key_data_set_role(key_data_t* key_data, key_data_role_t role) {
if (!key_data) {
return DB_ERROR_UNKNOWN;
}
if (role == KEY_DATA_ROLE_INVALID) {
return DB_ERROR_UNKNOWN;
}
key_data->role = role;
return DB_OK;
}
int key_data_set_introducing(key_data_t* key_data, unsigned int introducing) {
if (!key_data) {
return DB_ERROR_UNKNOWN;
}
key_data->introducing = introducing;
return DB_OK;
}
int key_data_set_active_zsk(key_data_t* key_data, unsigned int active_zsk) {
if (!key_data) {
return DB_ERROR_UNKNOWN;
}
key_data->active_zsk = active_zsk;
return DB_OK;
}
int key_data_set_publish(key_data_t* key_data, unsigned int publish) {
if (!key_data) {
return DB_ERROR_UNKNOWN;
}
key_data->publish = publish;
return DB_OK;
}
int key_data_set_active_ksk(key_data_t* key_data, unsigned int active_ksk) {
if (!key_data) {
return DB_ERROR_UNKNOWN;
}
key_data->active_ksk = active_ksk;
return DB_OK;
}
int key_data_set_ds_at_parent(key_data_t* key_data, key_data_ds_at_parent_t ds_at_parent) {
if (!key_data) {
return DB_ERROR_UNKNOWN;
}
if (ds_at_parent == KEY_DATA_DS_AT_PARENT_INVALID) {
return DB_ERROR_UNKNOWN;
}
key_data->ds_at_parent = ds_at_parent;
return DB_OK;
}
int key_data_set_keytag(key_data_t* key_data, unsigned int keytag) {
if (!key_data) {
return DB_ERROR_UNKNOWN;
}
key_data->keytag = keytag;
return DB_OK;
}
int key_data_set_minimize(key_data_t* key_data, unsigned int minimize) {
if (!key_data) {
return DB_ERROR_UNKNOWN;
}
key_data->minimize = minimize;
return DB_OK;
}
db_clause_t* key_data_zone_id_clause(db_clause_list_t* clause_list, const db_value_t* zone_id) {
db_clause_t* clause;
if (!clause_list) {
return NULL;
}
if (!zone_id) {
return NULL;
}
if (db_value_not_empty(zone_id)) {
return NULL;
}
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "zoneId")
|| db_clause_set_type(clause, DB_CLAUSE_EQUAL)
|| db_clause_set_operator(clause, DB_CLAUSE_OPERATOR_AND)
|| db_value_copy(db_clause_get_value(clause), zone_id)
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
return NULL;
}
return clause;
}
db_clause_t* key_data_hsm_key_id_clause(db_clause_list_t* clause_list, const db_value_t* hsm_key_id) {
db_clause_t* clause;
if (!clause_list) {
return NULL;
}
if (!hsm_key_id) {
return NULL;
}
if (db_value_not_empty(hsm_key_id)) {
return NULL;
}
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "hsmKeyId")
|| db_clause_set_type(clause, DB_CLAUSE_EQUAL)
|| db_clause_set_operator(clause, DB_CLAUSE_OPERATOR_AND)
|| db_value_copy(db_clause_get_value(clause), hsm_key_id)
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
return NULL;
}
return clause;
}
db_clause_t* key_data_role_clause(db_clause_list_t* clause_list, key_data_role_t role) {
db_clause_t* clause;
if (!clause_list) {
return NULL;
}
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "role")
|| db_clause_set_type(clause, DB_CLAUSE_EQUAL)
|| db_clause_set_operator(clause, DB_CLAUSE_OPERATOR_AND)
|| db_value_from_enum_value(db_clause_get_value(clause), role, key_data_enum_set_role)
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
return NULL;
}
return clause;
}
db_clause_t* key_data_ds_at_parent_clause(db_clause_list_t* clause_list, key_data_ds_at_parent_t ds_at_parent) {
db_clause_t* clause;
if (!clause_list) {
return NULL;
}
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "dsAtParent")
|| db_clause_set_type(clause, DB_CLAUSE_EQUAL)
|| db_clause_set_operator(clause, DB_CLAUSE_OPERATOR_AND)
|| db_value_from_enum_value(db_clause_get_value(clause), ds_at_parent, key_data_enum_set_ds_at_parent)
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
return NULL;
}
return clause;
}
db_clause_t* key_data_keytag_clause(db_clause_list_t* clause_list, unsigned int keytag) {
db_clause_t* clause;
if (!clause_list) {
return NULL;
}
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "keytag")
|| db_clause_set_type(clause, DB_CLAUSE_EQUAL)
|| db_clause_set_operator(clause, DB_CLAUSE_OPERATOR_AND)
|| db_value_from_uint32(db_clause_get_value(clause), keytag)
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
return NULL;
}
return clause;
}
int key_data_create(key_data_t* key_data) {
db_object_field_list_t* object_field_list;
db_object_field_t* object_field;
db_value_set_t* value_set;
int ret;
if (!key_data) {
return DB_ERROR_UNKNOWN;
}
if (!key_data->dbo) {
return DB_ERROR_UNKNOWN;
}
if (!db_value_not_empty(&(key_data->id))) {
return DB_ERROR_UNKNOWN;
}
if (!db_value_not_empty(&(key_data->rev))) {
return DB_ERROR_UNKNOWN;
}
if (db_value_not_empty(&(key_data->zone_id))) {
return DB_ERROR_UNKNOWN;
}
if (db_value_not_empty(&(key_data->hsm_key_id))) {
return DB_ERROR_UNKNOWN;
}
/* TODO: validate content more */
if (!(object_field_list = db_object_field_list_new())) {
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "zoneId")
|| db_object_field_set_type(object_field, DB_TYPE_ANY)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "hsmKeyId")
|| db_object_field_set_type(object_field, DB_TYPE_ANY)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "algorithm")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "inception")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "role")
|| db_object_field_set_type(object_field, DB_TYPE_ENUM)
|| db_object_field_set_enum_set(object_field, key_data_enum_set_role)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "introducing")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "shouldRevoke")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "standby")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "activeZsk")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "publish")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "activeKsk")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "dsAtParent")
|| db_object_field_set_type(object_field, DB_TYPE_ENUM)
|| db_object_field_set_enum_set(object_field, key_data_enum_set_ds_at_parent)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "keytag")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "minimize")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(value_set = db_value_set_new(14))) {
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (db_value_copy(db_value_set_get(value_set, 0), &(key_data->zone_id))
|| db_value_copy(db_value_set_get(value_set, 1), &(key_data->hsm_key_id))
|| db_value_from_uint32(db_value_set_get(value_set, 2), key_data->algorithm)
|| db_value_from_uint32(db_value_set_get(value_set, 3), key_data->inception)
|| db_value_from_enum_value(db_value_set_get(value_set, 4), key_data->role, key_data_enum_set_role)
|| db_value_from_uint32(db_value_set_get(value_set, 5), key_data->introducing)
|| db_value_from_uint32(db_value_set_get(value_set, 6), key_data->should_revoke)
|| db_value_from_uint32(db_value_set_get(value_set, 7), key_data->standby)
|| db_value_from_uint32(db_value_set_get(value_set, 8), key_data->active_zsk)
|| db_value_from_uint32(db_value_set_get(value_set, 9), key_data->publish)
|| db_value_from_uint32(db_value_set_get(value_set, 10), key_data->active_ksk)
|| db_value_from_enum_value(db_value_set_get(value_set, 11), key_data->ds_at_parent, key_data_enum_set_ds_at_parent)
|| db_value_from_uint32(db_value_set_get(value_set, 12), key_data->keytag)
|| db_value_from_uint32(db_value_set_get(value_set, 13), key_data->minimize))
{
db_value_set_free(value_set);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
ret = db_object_create(key_data->dbo, object_field_list, value_set);
db_value_set_free(value_set);
db_object_field_list_free(object_field_list);
return ret;
}
int key_data_get_by_id(key_data_t* key_data, const db_value_t* id) {
db_clause_list_t* clause_list;
db_clause_t* clause;
db_result_list_t* result_list;
const db_result_t* result;
if (!key_data) {
return DB_ERROR_UNKNOWN;
}
if (!key_data->dbo) {
return DB_ERROR_UNKNOWN;
}
if (!id) {
return DB_ERROR_UNKNOWN;
}
if (db_value_not_empty(id)) {
return DB_ERROR_UNKNOWN;
}
if (!(clause_list = db_clause_list_new())) {
return DB_ERROR_UNKNOWN;
}
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "id")
|| db_clause_set_type(clause, DB_CLAUSE_EQUAL)
|| db_value_copy(db_clause_get_value(clause), id)
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
result_list = db_object_read(key_data->dbo, NULL, clause_list);
db_clause_list_free(clause_list);
if (result_list) {
result = db_result_list_next(result_list);
if (result) {
if (key_data_from_result(key_data, result)) {
db_result_list_free(result_list);
return DB_ERROR_UNKNOWN;
}
db_result_list_free(result_list);
return DB_OK;
}
}
db_result_list_free(result_list);
return DB_ERROR_UNKNOWN;
}
int key_data_update(key_data_t* key_data) {
db_object_field_list_t* object_field_list;
db_object_field_t* object_field;
db_value_set_t* value_set;
db_clause_list_t* clause_list;
db_clause_t* clause;
int ret;
if (!key_data) {
return DB_ERROR_UNKNOWN;
}
if (!key_data->dbo) {
return DB_ERROR_UNKNOWN;
}
if (db_value_not_empty(&(key_data->id))) {
return DB_ERROR_UNKNOWN;
}
if (db_value_not_empty(&(key_data->rev))) {
return DB_ERROR_UNKNOWN;
}
if (db_value_not_empty(&(key_data->zone_id))) {
return DB_ERROR_UNKNOWN;
}
if (db_value_not_empty(&(key_data->hsm_key_id))) {
return DB_ERROR_UNKNOWN;
}
/* TODO: validate content more */
if (!(object_field_list = db_object_field_list_new())) {
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "zoneId")
|| db_object_field_set_type(object_field, DB_TYPE_ANY)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "hsmKeyId")
|| db_object_field_set_type(object_field, DB_TYPE_ANY)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "algorithm")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "inception")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "role")
|| db_object_field_set_type(object_field, DB_TYPE_ENUM)
|| db_object_field_set_enum_set(object_field, key_data_enum_set_role)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "introducing")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "shouldRevoke")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "standby")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "activeZsk")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "publish")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "activeKsk")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "dsAtParent")
|| db_object_field_set_type(object_field, DB_TYPE_ENUM)
|| db_object_field_set_enum_set(object_field, key_data_enum_set_ds_at_parent)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "keytag")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(object_field = db_object_field_new())
|| db_object_field_set_name(object_field, "minimize")
|| db_object_field_set_type(object_field, DB_TYPE_UINT32)
|| db_object_field_list_add(object_field_list, object_field))
{
db_object_field_free(object_field);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(value_set = db_value_set_new(14))) {
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (db_value_copy(db_value_set_get(value_set, 0), &(key_data->zone_id))
|| db_value_copy(db_value_set_get(value_set, 1), &(key_data->hsm_key_id))
|| db_value_from_uint32(db_value_set_get(value_set, 2), key_data->algorithm)
|| db_value_from_uint32(db_value_set_get(value_set, 3), key_data->inception)
|| db_value_from_enum_value(db_value_set_get(value_set, 4), key_data->role, key_data_enum_set_role)
|| db_value_from_uint32(db_value_set_get(value_set, 5), key_data->introducing)
|| db_value_from_uint32(db_value_set_get(value_set, 6), key_data->should_revoke)
|| db_value_from_uint32(db_value_set_get(value_set, 7), key_data->standby)
|| db_value_from_uint32(db_value_set_get(value_set, 8), key_data->active_zsk)
|| db_value_from_uint32(db_value_set_get(value_set, 9), key_data->publish)
|| db_value_from_uint32(db_value_set_get(value_set, 10), key_data->active_ksk)
|| db_value_from_enum_value(db_value_set_get(value_set, 11), key_data->ds_at_parent, key_data_enum_set_ds_at_parent)
|| db_value_from_uint32(db_value_set_get(value_set, 12), key_data->keytag)
|| db_value_from_uint32(db_value_set_get(value_set, 13), key_data->minimize))
{
db_value_set_free(value_set);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(clause_list = db_clause_list_new())) {
db_value_set_free(value_set);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "id")
|| db_clause_set_type(clause, DB_CLAUSE_EQUAL)
|| db_value_copy(db_clause_get_value(clause), &(key_data->id))
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
db_clause_list_free(clause_list);
db_value_set_free(value_set);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "rev")
|| db_clause_set_type(clause, DB_CLAUSE_EQUAL)
|| db_value_copy(db_clause_get_value(clause), &(key_data->rev))
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
db_clause_list_free(clause_list);
db_value_set_free(value_set);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
ret = db_object_update(key_data->dbo, object_field_list, value_set, clause_list);
db_value_set_free(value_set);
db_object_field_list_free(object_field_list);
db_clause_list_free(clause_list);
return ret;
}
int key_data_delete(key_data_t* key_data) {
db_clause_list_t* clause_list;
db_clause_t* clause;
int ret;
if (!key_data) {
return DB_ERROR_UNKNOWN;
}
if (!key_data->dbo) {
return DB_ERROR_UNKNOWN;
}
if (db_value_not_empty(&(key_data->id))) {
return DB_ERROR_UNKNOWN;
}
if (!(clause_list = db_clause_list_new())) {
return DB_ERROR_UNKNOWN;
}
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "id")
|| db_clause_set_type(clause, DB_CLAUSE_EQUAL)
|| db_value_copy(db_clause_get_value(clause), &(key_data->id))
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "rev")
|| db_clause_set_type(clause, DB_CLAUSE_EQUAL)
|| db_value_copy(db_clause_get_value(clause), &(key_data->rev))
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
ret = db_object_delete(key_data->dbo, clause_list);
db_clause_list_free(clause_list);
return ret;
}
int key_data_count(key_data_t* key_data, db_clause_list_t* clause_list, size_t* count) {
if (!key_data) {
return DB_ERROR_UNKNOWN;
}
if (!key_data->dbo) {
return DB_ERROR_UNKNOWN;
}
if (!count) {
return DB_ERROR_UNKNOWN;
}
return db_object_count(key_data->dbo, NULL, clause_list, count);
}
/* KEY DATA LIST */
key_data_list_t* key_data_list_new(const db_connection_t* connection) {
key_data_list_t* key_data_list =
(key_data_list_t*)calloc(1, sizeof(key_data_list_t));
if (key_data_list) {
if (!(key_data_list->dbo = __key_data_new_object(connection))) {
free(key_data_list);
return NULL;
}
}
return key_data_list;
}
key_data_list_t* key_data_list_new_copy(const key_data_list_t* from_key_data_list) {
key_data_list_t* key_data_list;
if (!from_key_data_list) {
return NULL;
}
if (!from_key_data_list->dbo) {
return NULL;
}
if (!(key_data_list = key_data_list_new(db_object_connection(from_key_data_list->dbo)))
|| key_data_list_copy(key_data_list, from_key_data_list))
{
key_data_list_free(key_data_list);
return NULL;
}
return key_data_list;
}
int key_data_list_object_store(key_data_list_t* key_data_list) {
if (!key_data_list) {
return DB_ERROR_UNKNOWN;
}
key_data_list->object_store = 1;
return DB_OK;
}
void key_data_list_free(key_data_list_t* key_data_list) {
size_t i;
if (key_data_list) {
if (key_data_list->dbo) {
db_object_free(key_data_list->dbo);
}
if (key_data_list->result_list) {
db_result_list_free(key_data_list->result_list);
}
if (key_data_list->key_data) {
key_data_free(key_data_list->key_data);
}
for (i = 0; i < key_data_list->object_list_size; i++) {
if (key_data_list->object_list[i]) {
key_data_free(key_data_list->object_list[i]);
}
}
if (key_data_list->object_list) {
free(key_data_list->object_list);
}
if (key_data_list->zone_id_list) {
zone_list_db_free(key_data_list->zone_id_list);
}
if (key_data_list->hsm_key_id_list) {
hsm_key_list_free(key_data_list->hsm_key_id_list);
}
free(key_data_list);
}
}
int key_data_list_copy(key_data_list_t* key_data_list, const key_data_list_t* from_key_data_list) {
size_t i;
if (!key_data_list) {
return DB_ERROR_UNKNOWN;
}
if (!from_key_data_list) {
return DB_ERROR_UNKNOWN;
}
if (from_key_data_list->object_list && !from_key_data_list->object_list_size) {
return DB_ERROR_UNKNOWN;
}
if (key_data_list->result_list) {
db_result_list_free(key_data_list->result_list);
key_data_list->result_list = NULL;
}
if (from_key_data_list->result_list
&& !(key_data_list->result_list = db_result_list_new_copy(from_key_data_list->result_list)))
{
return DB_ERROR_UNKNOWN;
}
key_data_list->object_store = from_key_data_list->object_store;
for (i = 0; i < key_data_list->object_list_size; i++) {
if (key_data_list->object_list[i]) {
key_data_free(key_data_list->object_list[i]);
}
}
key_data_list->object_list_size = 0;
if (key_data_list->object_list) {
free(key_data_list->object_list);
key_data_list->object_list = NULL;
}
if (from_key_data_list->object_list) {
if (!(key_data_list->object_list = (key_data_t**)calloc(from_key_data_list->object_list_size, sizeof(key_data_t*)))) {
return DB_ERROR_UNKNOWN;
}
key_data_list->object_list_size = from_key_data_list->object_list_size;
for (i = 0; i < from_key_data_list->object_list_size; i++) {
if (!from_key_data_list->object_list[i]) {
continue;
}
if (!(key_data_list->object_list[i] = key_data_new_copy(from_key_data_list->object_list[i]))) {
return DB_ERROR_UNKNOWN;
}
}
}
key_data_list->object_list_position = 0;;
key_data_list->object_list_first = 1;
key_data_list->associated_fetch = from_key_data_list->associated_fetch;
if (from_key_data_list->zone_id_list
&& !(key_data_list->zone_id_list = zone_list_db_new_copy(from_key_data_list->zone_id_list)))
{
return DB_ERROR_UNKNOWN;
}
if (from_key_data_list->hsm_key_id_list
&& !(key_data_list->hsm_key_id_list = hsm_key_list_new_copy(from_key_data_list->hsm_key_id_list)))
{
return DB_ERROR_UNKNOWN;
}
return DB_OK;
}
static int key_data_list_get_associated(key_data_list_t* key_data_list) {
const db_clause_t* clause_walk;
const zone_db_t* zone_zone_id;
const hsm_key_t* hsm_key_hsm_key_id;
size_t j, count;
int cmp;
size_t i;
db_clause_list_t* clause_list;
db_clause_t* clause;
const key_data_t* key_data;
key_state_list_t* key_state_list;
const key_state_t* key_state;
if (!key_data_list) {
return DB_ERROR_UNKNOWN;
}
if (!key_data_list->dbo) {
return DB_ERROR_UNKNOWN;
}
if (!key_data_list->associated_fetch) {
return DB_ERROR_UNKNOWN;
}
if (!key_data_list->result_list) {
return DB_ERROR_UNKNOWN;
}
if (key_data_list->object_list) {
return DB_ERROR_UNKNOWN;
}
if (key_data_list->zone_id_list) {
zone_list_db_free(key_data_list->zone_id_list);
key_data_list->zone_id_list = NULL;
}
if (key_data_list->hsm_key_id_list) {
hsm_key_list_free(key_data_list->hsm_key_id_list);
key_data_list->hsm_key_id_list = NULL;
}
if (!(clause_list = db_clause_list_new())) {
return DB_ERROR_UNKNOWN;
}
key_data = key_data_list_begin(key_data_list);
while (key_data) {
cmp = 1;
clause_walk = db_clause_list_begin(clause_list);
while (clause_walk) {
if (db_value_cmp(db_clause_value(clause_walk), key_data_zone_id(key_data), &cmp)) {
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
if (!cmp) {
break;
}
clause_walk = db_clause_next(clause_walk);
}
if (cmp) {
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "id")
|| db_clause_set_type(clause, DB_CLAUSE_EQUAL)
|| db_clause_set_operator(clause, DB_CLAUSE_OPERATOR_OR)
|| db_value_copy(db_clause_get_value(clause), key_data_zone_id(key_data))
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
}
key_data = key_data_list_next(key_data_list);
}
if (!(key_data_list->zone_id_list = zone_list_db_new(db_object_connection(key_data_list->dbo)))
|| zone_list_db_object_store(key_data_list->zone_id_list)
|| zone_list_db_get_by_clauses(key_data_list->zone_id_list, clause_list))
{
if (key_data_list->zone_id_list) {
zone_list_db_free(key_data_list->zone_id_list);
key_data_list->zone_id_list = NULL;
}
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
db_clause_list_free(clause_list);
for (i = 0; i < key_data_list->object_list_size; i++) {
if (!(key_data_list->object_list[i])) {
return DB_ERROR_UNKNOWN;
}
zone_zone_id = zone_list_db_begin(key_data_list->zone_id_list);
while (zone_zone_id) {
if (db_value_cmp(key_data_zone_id(key_data_list->object_list[i]), zone_db_id(zone_zone_id), &cmp)) {
return DB_ERROR_UNKNOWN;
}
if (!cmp) {
key_data_list->object_list[i]->associated_zone_id = zone_zone_id;
}
zone_zone_id = zone_list_db_next(key_data_list->zone_id_list);
}
}
if (!(clause_list = db_clause_list_new())) {
return DB_ERROR_UNKNOWN;
}
key_data = key_data_list_begin(key_data_list);
while (key_data) {
cmp = 1;
clause_walk = db_clause_list_begin(clause_list);
while (clause_walk) {
if (db_value_cmp(db_clause_value(clause_walk), key_data_hsm_key_id(key_data), &cmp)) {
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
if (!cmp) {
break;
}
clause_walk = db_clause_next(clause_walk);
}
if (cmp) {
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "id")
|| db_clause_set_type(clause, DB_CLAUSE_EQUAL)
|| db_clause_set_operator(clause, DB_CLAUSE_OPERATOR_OR)
|| db_value_copy(db_clause_get_value(clause), key_data_hsm_key_id(key_data))
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
}
key_data = key_data_list_next(key_data_list);
}
if (!(key_data_list->hsm_key_id_list = hsm_key_list_new(db_object_connection(key_data_list->dbo)))
|| hsm_key_list_object_store(key_data_list->hsm_key_id_list)
|| hsm_key_list_get_by_clauses(key_data_list->hsm_key_id_list, clause_list))
{
if (key_data_list->hsm_key_id_list) {
hsm_key_list_free(key_data_list->hsm_key_id_list);
key_data_list->hsm_key_id_list = NULL;
}
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
db_clause_list_free(clause_list);
for (i = 0; i < key_data_list->object_list_size; i++) {
if (!(key_data_list->object_list[i])) {
return DB_ERROR_UNKNOWN;
}
hsm_key_hsm_key_id = hsm_key_list_begin(key_data_list->hsm_key_id_list);
while (hsm_key_hsm_key_id) {
if (db_value_cmp(key_data_hsm_key_id(key_data_list->object_list[i]), hsm_key_id(hsm_key_hsm_key_id), &cmp)) {
return DB_ERROR_UNKNOWN;
}
if (!cmp) {
key_data_list->object_list[i]->associated_hsm_key_id = hsm_key_hsm_key_id;
}
hsm_key_hsm_key_id = hsm_key_list_next(key_data_list->hsm_key_id_list);
}
}
if (!(clause_list = db_clause_list_new())) {
return DB_ERROR_UNKNOWN;
}
key_data = key_data_list_begin(key_data_list);
while (key_data) {
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "keyDataId")
|| db_clause_set_type(clause, DB_CLAUSE_EQUAL)
|| db_clause_set_operator(clause, DB_CLAUSE_OPERATOR_OR)
|| db_value_copy(db_clause_get_value(clause), key_data_id(key_data))
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
key_data = key_data_list_next(key_data_list);
}
if (!(key_state_list = key_state_list_new(db_object_connection(key_data_list->dbo)))
|| key_state_list_object_store(key_state_list)
|| key_state_list_get_by_clauses(key_state_list, clause_list))
{
key_state_list_free(key_state_list);
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
for (i = 0; i < key_data_list->object_list_size; i++) {
if (!(key_data_list->object_list[i])) {
return DB_ERROR_UNKNOWN;
}
count = 0;
key_state = key_state_list_begin(key_state_list);
while (key_state) {
if (db_value_cmp(key_data_id(key_data_list->object_list[i]), key_state_key_data_id(key_state), &cmp)) {
key_state_list_free(key_state_list);
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
if (!cmp) {
count++;
}
key_state = key_state_list_next(key_state_list);
}
if (key_data_list->object_list[i]->key_state_list) {
key_state_list_free(key_data_list->object_list[i]->key_state_list);
key_data_list->object_list[i]->key_state_list = NULL;
}
if (!(key_data_list->object_list[i]->key_state_list = key_state_list_new(db_object_connection(key_data_list->dbo)))) {
key_state_list_free(key_state_list);
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
if (count) {
if (!(key_data_list->object_list[i]->key_state_list->object_list = (key_state_t**)calloc(count, sizeof(key_state_t*)))) {
key_state_list_free(key_state_list);
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
j = 0;
key_state = key_state_list_begin(key_state_list);
while (key_state) {
if (j >= count) {
key_state_list_free(key_state_list);
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
if (db_value_cmp(key_data_id(key_data_list->object_list[i]), key_state_key_data_id(key_state), &cmp)) {
key_state_list_free(key_state_list);
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
if (!cmp) {
if (!(key_data_list->object_list[i]->key_state_list->object_list[j] = key_state_new_copy(key_state))) {
key_state_list_free(key_state_list);
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
j++;
}
key_state = key_state_list_next(key_state_list);
}
if (j != count) {
key_state_list_free(key_state_list);
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
}
key_data_list->object_list[i]->key_state_list->object_store = 1;
key_data_list->object_list[i]->key_state_list->object_list_size = count;
key_data_list->object_list[i]->key_state_list->object_list_first = 1;
}
db_clause_list_free(clause_list);
key_state_list_free(key_state_list);
key_data_list->object_list_first = 1;
return DB_OK;
}
int key_data_list_get(key_data_list_t* key_data_list) {
size_t i;
if (!key_data_list) {
return DB_ERROR_UNKNOWN;
}
if (!key_data_list->dbo) {
return DB_ERROR_UNKNOWN;
}
if (key_data_list->result_list) {
db_result_list_free(key_data_list->result_list);
}
if (key_data_list->object_list_size) {
for (i = 0; i < key_data_list->object_list_size; i++) {
if (key_data_list->object_list[i]) {
key_data_free(key_data_list->object_list[i]);
}
}
key_data_list->object_list_size = 0;
key_data_list->object_list_first = 0;
}
if (key_data_list->object_list) {
free(key_data_list->object_list);
key_data_list->object_list = NULL;
}
if (!(key_data_list->result_list = db_object_read(key_data_list->dbo, NULL, NULL))
|| db_result_list_fetch_all(key_data_list->result_list))
{
return DB_ERROR_UNKNOWN;
}
if (key_data_list->associated_fetch
&& key_data_list_get_associated(key_data_list))
{
return DB_ERROR_UNKNOWN;
}
return DB_OK;
}
key_data_list_t* key_data_list_new_get(const db_connection_t* connection) {
key_data_list_t* key_data_list;
if (!connection) {
return NULL;
}
if (!(key_data_list = key_data_list_new(connection))
|| key_data_list_get(key_data_list))
{
key_data_list_free(key_data_list);
return NULL;
}
return key_data_list;
}
int key_data_list_get_by_clauses(key_data_list_t* key_data_list, const db_clause_list_t* clause_list) {
size_t i;
if (!key_data_list) {
return DB_ERROR_UNKNOWN;
}
if (!clause_list) {
return DB_ERROR_UNKNOWN;
}
if (!key_data_list->dbo) {
return DB_ERROR_UNKNOWN;
}
if (key_data_list->result_list) {
db_result_list_free(key_data_list->result_list);
}
if (key_data_list->object_list_size) {
for (i = 0; i < key_data_list->object_list_size; i++) {
if (key_data_list->object_list[i]) {
key_data_free(key_data_list->object_list[i]);
}
}
key_data_list->object_list_size = 0;
key_data_list->object_list_first = 0;
}
if (key_data_list->object_list) {
free(key_data_list->object_list);
key_data_list->object_list = NULL;
}
if (!(key_data_list->result_list = db_object_read(key_data_list->dbo, NULL, clause_list))
|| db_result_list_fetch_all(key_data_list->result_list))
{
return DB_ERROR_UNKNOWN;
}
if (key_data_list->associated_fetch
&& key_data_list_get_associated(key_data_list))
{
return DB_ERROR_UNKNOWN;
}
return DB_OK;
}
key_data_list_t* key_data_list_new_get_by_clauses(const db_connection_t* connection, const db_clause_list_t* clause_list) {
key_data_list_t* key_data_list;
if (!connection) {
return NULL;
}
if (!clause_list) {
return NULL;
}
if (!(key_data_list = key_data_list_new(connection))
|| key_data_list_get_by_clauses(key_data_list, clause_list))
{
key_data_list_free(key_data_list);
return NULL;
}
return key_data_list;
}
int key_data_list_get_by_zone_id(key_data_list_t* key_data_list, const db_value_t* zone_id) {
db_clause_list_t* clause_list;
db_clause_t* clause;
size_t i;
if (!key_data_list) {
return DB_ERROR_UNKNOWN;
}
if (!key_data_list->dbo) {
return DB_ERROR_UNKNOWN;
}
if (!zone_id) {
return DB_ERROR_UNKNOWN;
}
if (db_value_not_empty(zone_id)) {
return DB_ERROR_UNKNOWN;
}
if (!(clause_list = db_clause_list_new())) {
return DB_ERROR_UNKNOWN;
}
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "zoneId")
|| db_clause_set_type(clause, DB_CLAUSE_EQUAL)
|| db_value_copy(db_clause_get_value(clause), zone_id)
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
if (key_data_list->result_list) {
db_result_list_free(key_data_list->result_list);
}
if (key_data_list->object_list_size) {
for (i = 0; i < key_data_list->object_list_size; i++) {
if (key_data_list->object_list[i]) {
key_data_free(key_data_list->object_list[i]);
}
}
key_data_list->object_list_size = 0;
key_data_list->object_list_first = 0;
}
if (key_data_list->object_list) {
free(key_data_list->object_list);
key_data_list->object_list = NULL;
}
if (!(key_data_list->result_list = db_object_read(key_data_list->dbo, NULL, clause_list))
|| db_result_list_fetch_all(key_data_list->result_list))
{
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
db_clause_list_free(clause_list);
if (key_data_list->associated_fetch
&& key_data_list_get_associated(key_data_list))
{
return DB_ERROR_UNKNOWN;
}
return DB_OK;
}
key_data_list_t* key_data_list_new_get_by_zone_id(const db_connection_t* connection, const db_value_t* zone_id) {
key_data_list_t* key_data_list;
if (!connection) {
return NULL;
}
if (!zone_id) {
return NULL;
}
if (db_value_not_empty(zone_id)) {
return NULL;
}
if (!(key_data_list = key_data_list_new(connection))
|| key_data_list_get_by_zone_id(key_data_list, zone_id))
{
key_data_list_free(key_data_list);
return NULL;
}
return key_data_list;
}
const key_data_t* key_data_list_begin(key_data_list_t* key_data_list) {
const db_result_t* result;
if (!key_data_list) {
return NULL;
}
if (key_data_list->object_store) {
if (!key_data_list->object_list) {
if (!key_data_list->result_list) {
return NULL;
}
if (!db_result_list_size(key_data_list->result_list)) {
return NULL;
}
if (!(key_data_list->object_list = (key_data_t**)calloc(db_result_list_size(key_data_list->result_list), sizeof(key_data_t*)))) {
return NULL;
}
key_data_list->object_list_size = db_result_list_size(key_data_list->result_list);
}
if (!(key_data_list->object_list[0])) {
if (!key_data_list->result_list) {
return NULL;
}
if (!(result = db_result_list_begin(key_data_list->result_list))) {
return NULL;
}
if (!(key_data_list->object_list[0] = key_data_new(db_object_connection(key_data_list->dbo)))) {
return NULL;
}
if (key_data_from_result(key_data_list->object_list[0], result)) {
return NULL;
}
}
key_data_list->object_list_position = 0;
return key_data_list->object_list[0];
}
if (!key_data_list->result_list) {
return NULL;
}
if (!(result = db_result_list_begin(key_data_list->result_list))) {
return NULL;
}
if (!key_data_list->key_data) {
if (!(key_data_list->key_data = key_data_new(db_object_connection(key_data_list->dbo)))) {
return NULL;
}
}
if (key_data_from_result(key_data_list->key_data, result)) {
return NULL;
}
return key_data_list->key_data;
}
key_data_t* key_data_list_get_begin(key_data_list_t* key_data_list) {
const db_result_t* result;
key_data_t* key_data;
if (!key_data_list) {
return NULL;
}
if (key_data_list->object_store) {
if (!(key_data = key_data_new(db_object_connection(key_data_list->dbo)))) {
return NULL;
}
if (key_data_copy(key_data, key_data_list_begin(key_data_list))) {
key_data_free(key_data);
return NULL;
}
return key_data;
}
if (!key_data_list->result_list) {
return NULL;
}
if (!(result = db_result_list_begin(key_data_list->result_list))) {
return NULL;
}
if (!(key_data = key_data_new(db_object_connection(key_data_list->dbo)))) {
return NULL;
}
if (key_data_from_result(key_data, result)) {
key_data_free(key_data);
return NULL;
}
return key_data;
}
const key_data_t* key_data_list_next(key_data_list_t* key_data_list) {
const db_result_t* result;
if (!key_data_list) {
return NULL;
}
if (key_data_list->object_store) {
if (!key_data_list->object_list) {
if (!key_data_list->result_list) {
return NULL;
}
if (!db_result_list_size(key_data_list->result_list)) {
return NULL;
}
if (!(key_data_list->object_list = (key_data_t**)calloc(db_result_list_size(key_data_list->result_list), sizeof(key_data_t*)))) {
return NULL;
}
key_data_list->object_list_size = db_result_list_size(key_data_list->result_list);
key_data_list->object_list_position = 0;
}
else if (key_data_list->object_list_first) {
key_data_list->object_list_first = 0;
key_data_list->object_list_position = 0;
}
else {
key_data_list->object_list_position++;
}
if (key_data_list->object_list_position >= key_data_list->object_list_size) {
return NULL;
}
if (!(key_data_list->object_list[key_data_list->object_list_position])) {
if (!key_data_list->result_list) {
return NULL;
}
if (!(result = db_result_list_next(key_data_list->result_list))) {
return NULL;
}
if (!(key_data_list->object_list[key_data_list->object_list_position] = key_data_new(db_object_connection(key_data_list->dbo)))) {
return NULL;
}
if (key_data_from_result(key_data_list->object_list[key_data_list->object_list_position], result)) {
return NULL;
}
}
return key_data_list->object_list[key_data_list->object_list_position];
}
if (!key_data_list->result_list) {
return NULL;
}
if (!(result = db_result_list_next(key_data_list->result_list))) {
return NULL;
}
if (!key_data_list->key_data) {
if (!(key_data_list->key_data = key_data_new(db_object_connection(key_data_list->dbo)))) {
return NULL;
}
}
if (key_data_from_result(key_data_list->key_data, result)) {
return NULL;
}
return key_data_list->key_data;
}
key_data_t* key_data_list_get_next(key_data_list_t* key_data_list) {
const db_result_t* result;
key_data_t* key_data;
if (!key_data_list) {
return NULL;
}
if (key_data_list->object_store) {
if (!(key_data = key_data_new(db_object_connection(key_data_list->dbo)))) {
return NULL;
}
if (key_data_copy(key_data, key_data_list_next(key_data_list))) {
key_data_free(key_data);
return NULL;
}
return key_data;
}
if (!key_data_list->result_list) {
return NULL;
}
if (!(result = db_result_list_next(key_data_list->result_list))) {
return NULL;
}
if (!(key_data = key_data_new(db_object_connection(key_data_list->dbo)))) {
return NULL;
}
if (key_data_from_result(key_data, result)) {
key_data_free(key_data);
return NULL;
}
return key_data;
}
size_t key_data_list_size(key_data_list_t* key_data_list) {
if (!key_data_list) {
return 0;
}
if (key_data_list->object_store
&& key_data_list->object_list)
{
return key_data_list->object_list_size;
}
if (!key_data_list->result_list) {
return 0;
}
return db_result_list_size(key_data_list->result_list);
}
int key_data_get_by_hsm_key_id(key_data_t * key_data, const db_value_t* hsm_key_id) {
db_clause_list_t* clause_list;
db_clause_t* clause;
db_result_list_t* result_list;
const db_result_t* result;
if (!key_data) {
return DB_ERROR_UNKNOWN;
}
if (!key_data->dbo) {
return DB_ERROR_UNKNOWN;
}
if (!hsm_key_id) {
return DB_ERROR_UNKNOWN;
}
if (!(clause_list = db_clause_list_new())) {
return DB_ERROR_UNKNOWN;
}
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "hsmKeyId")
|| db_clause_set_type(clause, DB_CLAUSE_EQUAL)
|| db_value_copy(db_clause_get_value(clause), hsm_key_id)
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
result_list = db_object_read(key_data->dbo, NULL, clause_list);
db_clause_list_free(clause_list);
if (result_list) {
result = db_result_list_next(result_list);
if (result) {
if (key_data_from_result(key_data, result)) {
db_result_list_free(result_list);
return DB_ERROR_UNKNOWN;
}
db_result_list_free(result_list);
return DB_OK;
}
}
db_result_list_free(result_list);
return DB_ERROR_UNKNOWN;
}
key_data_t* key_data_new_get_by_hsm_key_id(const db_connection_t* connection, const db_value_t * hsm_key_id) {
key_data_t* key_data;
if (!connection) {
return NULL;
}
if (!hsm_key_id) {
return NULL;
}
if (!(key_data = key_data_new(connection))
|| key_data_get_by_hsm_key_id(key_data, hsm_key_id))
{
key_data_free(key_data);
return NULL;
}
return key_data;
}
key_state_list_next
const key_state_t * key_state_list_next(key_state_list_t *key_state_list)
Definition: key_state.c:1332
key_data_role_text
const char * key_data_role_text(const key_data_t *key_data)
Definition: key_data.c:711
key_data_new_get_by_hsm_key_id
key_data_t * key_data_new_get_by_hsm_key_id(const db_connection_t *connection, const db_value_t *hsm_key_id)
Definition: key_data.c:2530
key_data_set_inception
int key_data_set_inception(key_data_t *key_data, unsigned int inception)
Definition: key_data.c:880
zone_list_db_get_by_clauses
int zone_list_db_get_by_clauses(zone_list_db_t *zone_list, const db_clause_list_t *clause_list)
Definition: zone_db.c:2419
zone_db_copy
int zone_db_copy(zone_db_t *zone, const zone_db_t *zone_copy)
Definition: zone_db.c:365
key_data_list
Definition: key_data.h:477
key_data::minimize
unsigned int minimize
Definition: key_data.h:87
key_state
Definition: key_state.h:65
db_value_from_uint32
int db_value_from_uint32(db_value_t *value, db_type_uint32_t from_uint32)
Definition: db_value.c:492
zone_db_free
void zone_db_free(zone_db_t *zone)
Definition: zone_db.c:325
db_object_set_object_field_list
int db_object_set_object_field_list(db_object_t *object, db_object_field_list_t *object_field_list)
Definition: db_object.c:386
key_data_get_by_id
int key_data_get_by_id(key_data_t *key_data, const db_value_t *id)
Definition: key_data.c:1296
db_value_from_enum_value
int db_value_from_enum_value(db_value_t *value, int enum_value, const db_enum_t *enum_set)
Definition: db_value.c:572
db_object_set_primary_key_name
int db_object_set_primary_key_name(db_object_t *object, const char *primary_key_name)
Definition: db_object.c:371
zone_db_new_copy
zone_db_t * zone_db_new_copy(const zone_db_t *zone)
Definition: zone_db.c:306
KEY_DATA_ROLE_ZSK
Definition: key_data.h:43
key_data::private_hsm_key_id
hsm_key_t * private_hsm_key_id
Definition: key_data.h:75
key_data_get_hsm_key
hsm_key_t * key_data_get_hsm_key(const key_data_t *key_data)
Definition: key_data.c:649
key_data_list::result_list
db_result_list_t * result_list
Definition: key_data.h:479
db_object_field_list_new
db_object_field_list_t * db_object_field_list_new(void)
Definition: db_object.c:174
db_object_field_set_name
int db_object_field_set_name(db_object_field_t *object_field, const char *name)
Definition: db_object.c:110
hsm_key_list_get_by_clauses
int hsm_key_list_get_by_clauses(hsm_key_list_t *hsm_key_list, const db_clause_list_t *clause_list)
Definition: hsm_key.c:1684
key_state_list_new
key_state_list_t * key_state_list_new(const db_connection_t *connection)
Definition: key_state.c:881
hsm_key_list_new_copy
hsm_key_list_t * hsm_key_list_new_copy(const hsm_key_list_t *from_hsm_key_list)
Definition: hsm_key.c:1467
db_value_set_at
const db_value_t * db_value_set_at(const db_value_set_t *value_set, size_t at)
Definition: db_value.c:742
key_data.h
db_value_set_free
void db_value_set_free(db_value_set_t *value_set)
Definition: db_value.c:697
key_data::ds_at_parent
key_data_ds_at_parent_t ds_at_parent
Definition: key_data.h:85
db_value_to_uint32
int db_value_to_uint32(const db_value_t *value, db_type_uint32_t *to_uint32)
Definition: db_value.c:372
key_data_publish
unsigned int key_data_publish(const key_data_t *key_data)
Definition: key_data.c:743
DB_ERROR_UNKNOWN
#define DB_ERROR_UNKNOWN
Definition: db_error.h:40
db_value_copy
int db_value_copy(db_value_t *value, const db_value_t *from_value)
Definition: db_value.c:77
db_clause_list_new
db_clause_list_t * db_clause_list_new(void)
Definition: db_clause.c:202
key_data_keytag_clause
db_clause_t * key_data_keytag_clause(db_clause_list_t *clause_list, unsigned int keytag)
Definition: key_data.c:1072
db_object
Definition: db_object.h:201
key_data::should_revoke
unsigned int should_revoke
Definition: key_data.h:80
key_data_list_get_by_clauses
int key_data_list_get_by_clauses(key_data_list_t *key_data_list, const db_clause_list_t *clause_list)
Definition: key_data.c:2119
key_data_ds_at_parent
key_data_ds_at_parent_t key_data_ds_at_parent(const key_data_t *key_data)
Definition: key_data.c:759
key_state_new_copy
key_state_t * key_state_new_copy(const key_state_t *key_state)
Definition: key_state.c:195
DB_CLAUSE_EQUAL
Definition: db_clause.h:44
key_data_active_zsk
unsigned int key_data_active_zsk(const key_data_t *key_data)
Definition: key_data.c:735
key_data_list::object_list_size
size_t object_list_size
Definition: key_data.h:484
key_data_list::hsm_key_id_list
hsm_key_list_t * hsm_key_id_list
Definition: key_data.h:489
key_data_enum_set_role
const db_enum_t key_data_enum_set_role[]
Definition: key_data.c:36
key_data_list_get_by_zone_id
int key_data_list_get_by_zone_id(key_data_list_t *key_data_list, const db_value_t *zone_id)
Definition: key_data.c:2181
hsm_key_get_by_id
int hsm_key_get_by_id(hsm_key_t *hsm_key, const db_value_t *id)
Definition: hsm_key.c:1102
KEY_DATA_DS_AT_PARENT_SUBMIT
Definition: key_data.h:51
db_clause_new
db_clause_t * db_clause_new(void)
Definition: db_clause.c:43
key_data_list_new_get
key_data_list_t * key_data_list_new_get(const db_connection_t *connection)
Definition: key_data.c:2102
key_data_enum_set_ds_at_parent
const db_enum_t key_data_enum_set_ds_at_parent[]
Definition: key_data.c:43
key_data_list::object_list
key_data_t ** object_list
Definition: key_data.h:483
db_object_count
int db_object_count(const db_object_t *object, const db_join_list_t *join_list, const db_clause_list_t *clause_list, size_t *count)
Definition: db_object.c:481
db_object_field_set_type
int db_object_field_set_type(db_object_field_t *object_field, db_type_t type)
Definition: db_object.c:122
key_data_role
key_data_role_t key_data_role(const key_data_t *key_data)
Definition: key_data.c:703
db_clause_list
Definition: db_clause.h:226
key_data_cmp
int key_data_cmp(const key_data_t *key_data_a, const key_data_t *key_data_b)
Definition: key_data.c:402
key_data_key_state_list
key_state_list_t * key_data_key_state_list(key_data_t *key_data)
Definition: key_data.c:783
DB_TYPE_UINT32
Definition: db_type.h:70
zone_list_db_new
zone_list_db_t * zone_list_db_new(const db_connection_t *connection)
Definition: zone_db.c:1946
key_data_zone_id
const db_value_t * key_data_zone_id(const key_data_t *key_data)
Definition: key_data.c:561
key_data_role_t
enum key_data_role key_data_role_t
key_data_list::key_data
key_data_t * key_data
Definition: key_data.h:481
key_data::algorithm
unsigned int algorithm
Definition: key_data.h:76
key_data_id
const db_value_t * key_data_id(const key_data_t *key_data)
Definition: key_data.c:553
db_clause_set_type
int db_clause_set_type(db_clause_t *clause, db_clause_type_t type)
Definition: db_clause.c:130
key_data::associated_zone_id
const zone_db_t * associated_zone_id
Definition: key_data.h:71
KEY_DATA_ROLE_CSK
Definition: key_data.h:44
hsm_key_list_next
const hsm_key_t * hsm_key_list_next(hsm_key_list_t *hsm_key_list)
Definition: hsm_key.c:1924
key_data_ds_at_parent_t
enum key_data_ds_at_parent key_data_ds_at_parent_t
key_data_list_size
size_t key_data_list_size(key_data_list_t *key_data_list)
Definition: key_data.c:2461
key_state_list_new_copy
key_state_list_t * key_state_list_new_copy(const key_state_list_t *from_key_state_list)
Definition: key_state.c:895
KEY_DATA_ROLE_INVALID
Definition: key_data.h:41
key_data_list::object_list_position
size_t object_list_position
Definition: key_data.h:485
db_object_field_list
Definition: db_object.h:142
db_object_set_connection
int db_object_set_connection(db_object_t *object, const db_connection_t *connection)
Definition: db_object.c:341
db_value_not_empty
int db_value_not_empty(const db_value_t *value)
Definition: db_value.c:347
key_data_keytag
unsigned int key_data_keytag(const key_data_t *key_data)
Definition: key_data.c:767
key_data_list::associated_fetch
int associated_fetch
Definition: key_data.h:487
key_data_set_role
int key_data_set_role(key_data_t *key_data, key_data_role_t role)
Definition: key_data.c:890
key_state_key_data_id
const db_value_t * key_state_key_data_id(const key_state_t *key_state)
Definition: key_state.c:337
db_object_connection
const db_connection_t * db_object_connection(const db_object_t *object)
Definition: db_object.c:320
db_value_set
Definition: db_value.h:281
DB_TYPE_ENUM
Definition: db_type.h:86
db_result_list
Definition: db_result.h:114
key_data_list_new_copy
key_data_list_t * key_data_list_new_copy(const key_data_list_t *from_key_data_list)
Definition: key_data.c:1665
key_data_list_get_next
key_data_t * key_data_list_get_next(key_data_list_t *key_data_list)
Definition: key_data.c:2425
db_value
Definition: db_value.h:48
hsm_key
Definition: hsm_key.h:77
key_data_hsm_key_id_clause
db_clause_t * key_data_hsm_key_id_clause(db_clause_list_t *clause_list, const db_value_t *hsm_key_id)
Definition: key_data.c:1003
db_clause_list_begin
const db_clause_t * db_clause_list_begin(const db_clause_list_t *clause_list)
Definition: db_clause.c:255
key_data_create
int key_data_create(key_data_t *key_data)
Definition: key_data.c:1093
db_clause_set_field
int db_clause_set_field(db_clause_t *clause, const char *field)
Definition: db_clause.c:109
db_clause_list_free
void db_clause_list_free(db_clause_list_t *clause_list)
Definition: db_clause.c:209
key_data_set_hsm_key_id
int key_data_set_hsm_key_id(key_data_t *key_data, const db_value_t *hsm_key_id)
Definition: key_data.c:851
db_result_list_new_copy
db_result_list_t * db_result_list_new_copy(const db_result_list_t *from_result_list)
Definition: db_result.c:142
db_value_set_size
size_t db_value_set_size(const db_value_set_t *value_set)
Definition: db_value.c:734
key_data_introducing
unsigned int key_data_introducing(const key_data_t *key_data)
Definition: key_data.c:727
db_clause
Definition: db_clause.h:118
DB_CLAUSE_OPERATOR_AND
Definition: db_clause.h:97
key_state_list_object_store
int key_state_list_object_store(key_state_list_t *key_state_list)
Definition: key_state.c:914
key_state_list_get_by_clauses
int key_state_list_get_by_clauses(key_state_list_t *key_state_list, const db_clause_list_t *clause_list)
Definition: key_state.c:1112
db_clause_next
const db_clause_t * db_clause_next(const db_clause_t *clause)
Definition: db_clause.c:179
db_error.h
DB_TYPE_ANY
Definition: db_type.h:90
zone_list_db_free
void zone_list_db_free(zone_list_db_t *zone_list)
Definition: zone_db.c:1989
KEY_DATA_DS_AT_PARENT_UNSUBMITTED
Definition: key_data.h:50
zone_list_db_object_store
int zone_list_db_object_store(zone_list_db_t *zone_list)
Definition: zone_db.c:1979
db_clause_list_add
int db_clause_list_add(db_clause_list_t *clause_list, db_clause_t *clause)
Definition: db_clause.c:226
db_value_cmp
int db_value_cmp(const db_value_t *value_a, const db_value_t *value_b, int *result)
Definition: db_value.c:102
db_object_read
db_result_list_t * db_object_read(const db_object_t *object, const db_join_list_t *join_list, const db_clause_list_t *clause_list)
Definition: db_object.c:424
db_object_free
void db_object_free(db_object_t *object)
Definition: db_object.c:311
db_result_list_free
void db_result_list_free(db_result_list_t *result_list)
Definition: db_result.c:160
zone_list_db_next
const zone_db_t * zone_list_db_next(zone_list_db_t *zone_list)
Definition: zone_db.c:2603
db_object_update
int db_object_update(const db_object_t *object, const db_object_field_list_t *object_field_list, const db_value_set_t *value_set, const db_clause_list_t *clause_list)
Definition: db_object.c:441
key_state_list::object_list
key_state_t ** object_list
Definition: key_state.h:268
key_data_inception
unsigned int key_data_inception(const key_data_t *key_data)
Definition: key_data.c:695
key_data::standby
unsigned int standby
Definition: key_data.h:81
key_state_key_data_id_clause
db_clause_t * key_state_key_data_id_clause(db_clause_list_t *clause_list, const db_value_t *key_data_id)
Definition: key_state.c:492
key_data_from_result
int key_data_from_result(key_data_t *key_data, const db_result_t *result)
Definition: key_data.c:477
key_data_list::object_list_first
int object_list_first
Definition: key_data.h:486
KEY_DATA_DS_AT_PARENT_RETRACT
Definition: key_data.h:54
key_data_zone_id_clause
db_clause_t * key_data_zone_id_clause(db_clause_list_t *clause_list, const db_value_t *zone_id)
Definition: key_data.c:976
key_data_list::object_store
int object_store
Definition: key_data.h:482
key_data::key_state_list
key_state_list_t * key_state_list
Definition: key_data.h:88
zone_db
Definition: zone_db.h:46
key_data::id
db_value_t id
Definition: key_data.h:68
db_clause_set_operator
int db_clause_set_operator(db_clause_t *clause, db_clause_operator_t clause_operator)
Definition: db_clause.c:142
DB_TYPE_REVISION
Definition: db_type.h:97
db_value_reset
void db_value_reset(db_value_t *value)
Definition: db_value.c:60
db_object_field_new
db_object_field_t * db_object_field_new(void)
Definition: db_object.c:40
key_data_new
key_data_t * key_data_new(const db_connection_t *connection)
Definition: key_data.c:264
zone_db_get_by_id
int zone_db_get_by_id(zone_db_t *zone, const db_value_t *id)
Definition: zone_db.c:1466
key_data_list_begin
const key_data_t * key_data_list_begin(key_data_list_t *key_data_list)
Definition: key_data.c:2267
KEY_DATA_DS_AT_PARENT_SEEN
Definition: key_data.h:53
db_object_delete
int db_object_delete(const db_object_t *object, const db_clause_list_t *clause_list)
Definition: db_object.c:464
key_data_list_get
int key_data_list_get(key_data_list_t *key_data_list)
Definition: key_data.c:2063
DB_TYPE_PRIMARY_KEY
Definition: db_type.h:62
key_data_list_next
const key_data_t * key_data_list_next(key_data_list_t *key_data_list)
Definition: key_data.c:2359
key_data_set_publish
int key_data_set_publish(key_data_t *key_data, unsigned int publish)
Definition: key_data.c:923
db_result_list_size
size_t db_result_list_size(const db_result_list_t *result_list)
Definition: db_result.c:333
key_data_list_copy
int key_data_list_copy(key_data_list_t *key_data_list, const key_data_list_t *from_key_data_list)
Definition: key_data.c:1725
key_state_list::object_list_size
size_t object_list_size
Definition: key_state.h:269
db_enum::value
int value
Definition: db_enum.h:40
key_state_list::object_list_first
int object_list_first
Definition: key_state.h:271
db_object_field_free
void db_object_field_free(db_object_field_t *object_field)
Definition: db_object.c:69
key_data_list_new
key_data_list_t * key_data_list_new(const db_connection_t *connection)
Definition: key_data.c:1651
key_state_list
Definition: key_state.h:262
key_data::active_ksk
unsigned int active_ksk
Definition: key_data.h:84
key_data_list_new_get_by_clauses
key_data_list_t * key_data_list_new_get_by_clauses(const db_connection_t *connection, const db_clause_list_t *clause_list)
Definition: key_data.c:2161
KEY_DATA_DS_AT_PARENT_SUBMITTED
Definition: key_data.h:52
db_clause_free
void db_clause_free(db_clause_t *clause)
Definition: db_clause.c:56
key_data::zone_id
db_value_t zone_id
Definition: key_data.h:70
db_value_set_new
db_value_set_t * db_value_set_new(size_t size)
Definition: db_value.c:622
key_state_list_free
void key_state_list_free(key_state_list_t *key_state_list)
Definition: key_state.c:924
key_data_list::dbo
db_object_t * dbo
Definition: key_data.h:478
db_result_list_next
const db_result_t * db_result_list_next(db_result_list_t *result_list)
Definition: db_result.c:310
DB_CLAUSE_OPERATOR_OR
Definition: db_clause.h:101
db_result
Definition: db_result.h:56
key_data_role_clause
db_clause_t * key_data_role_clause(db_clause_list_t *clause_list, key_data_role_t role)
Definition: key_data.c:1030
db_object_field_set_enum_set
int db_object_field_set_enum_set(db_object_field_t *object_field, const db_enum_t *enum_set)
Definition: db_object.c:134
key_data_set_zone_id
int key_data_set_zone_id(key_data_t *key_data, const db_value_t *zone_id)
Definition: key_data.c:832
hsm_key_new_copy
hsm_key_t * hsm_key_new_copy(const hsm_key_t *hsm_key)
Definition: hsm_key.c:267
key_data::introducing
unsigned int introducing
Definition: key_data.h:79
key_data_get_zone
zone_db_t * key_data_get_zone(const key_data_t *key_data)
Definition: key_data.c:569
db_object_create
int db_object_create(const db_object_t *object, const db_object_field_list_t *object_field_list, const db_value_set_t *value_set)
Definition: db_object.c:401
db_object_field_list_free
void db_object_field_list_free(db_object_field_list_t *object_field_list)
Definition: db_object.c:199
key_data_cache_hsm_key
int key_data_cache_hsm_key(key_data_t *key_data)
Definition: key_data.c:615
key_data_list_free
void key_data_list_free(key_data_list_t *key_data_list)
Definition: key_data.c:1694
key_data::keytag
unsigned int keytag
Definition: key_data.h:86
key_data::associated_hsm_key_id
const hsm_key_t * associated_hsm_key_id
Definition: key_data.h:74
key_data_hsm_key_id
const db_value_t * key_data_hsm_key_id(const key_data_t *key_data)
Definition: key_data.c:607
key_data_ds_at_parent_clause
db_clause_t * key_data_ds_at_parent_clause(db_clause_list_t *clause_list, key_data_ds_at_parent_t ds_at_parent)
Definition: key_data.c:1051
key_data_list::zone_id_list
zone_list_db_t * zone_id_list
Definition: key_data.h:488
key_data_minimize
unsigned int key_data_minimize(const key_data_t *key_data)
Definition: key_data.c:775
key_data_copy
int key_data_copy(key_data_t *key_data, const key_data_t *key_data_copy)
Definition: key_data.c:326
zone_list_db_begin
const zone_db_t * zone_list_db_begin(zone_list_db_t *zone_list)
Definition: zone_db.c:2547
key_data_set_active_ksk
int key_data_set_active_ksk(key_data_t *key_data, unsigned int active_ksk)
Definition: key_data.c:933
key_data_free
void key_data_free(key_data_t *key_data)
Definition: key_data.c:304
db_object_new
db_object_t * db_object_new(void)
Definition: db_object.c:304
hsm_key_list_object_store
int hsm_key_list_object_store(hsm_key_list_t *hsm_key_list)
Definition: hsm_key.c:1486
KEY_DATA_DS_AT_PARENT_RETRACTED
Definition: key_data.h:55
key_data_set_ds_at_parent
int key_data_set_ds_at_parent(key_data_t *key_data, key_data_ds_at_parent_t ds_at_parent)
Definition: key_data.c:943
key_data_list_new_get_by_zone_id
key_data_list_t * key_data_list_new_get_by_zone_id(const db_connection_t *connection, const db_value_t *zone_id)
Definition: key_data.c:2244
key_data::rev
db_value_t rev
Definition: key_data.h:69
DB_OK
#define DB_OK
Definition: db_error.h:36
hsm_key_list_new
hsm_key_list_t * hsm_key_list_new(const db_connection_t *connection)
Definition: hsm_key.c:1453
hsm_key_free
void hsm_key_free(hsm_key_t *hsm_key)
Definition: hsm_key.c:286
key_data::dbo
db_object_t * dbo
Definition: key_data.h:67
key_data_retrieve_key_state_list
int key_data_retrieve_key_state_list(key_data_t *key_data)
Definition: key_data.c:801
key_data_new_copy
key_data_t * key_data_new_copy(const key_data_t *key_data)
Definition: key_data.c:285
KEY_DATA_ROLE_KSK
Definition: key_data.h:42
KEY_DATA_DS_AT_PARENT_INVALID
Definition: key_data.h:49
db_enum::text
const char * text
Definition: db_enum.h:39
key_data_active_ksk
unsigned int key_data_active_ksk(const key_data_t *key_data)
Definition: key_data.c:751
key_data
Definition: key_data.h:66
db_connection
Definition: db_connection.h:46
key_data::inception
unsigned int inception
Definition: key_data.h:77
db_result_value_set
const db_value_set_t * db_result_value_set(const db_result_t *result)
Definition: db_result.c:97
key_data_hsm_key
const hsm_key_t * key_data_hsm_key(const key_data_t *key_data)
Definition: key_data.c:638
db_object_set_table
int db_object_set_table(db_object_t *object, const char *table)
Definition: db_object.c:356
key_data::role
key_data_role_t role
Definition: key_data.h:78
key_data::active_zsk
unsigned int active_zsk
Definition: key_data.h:82
db_enum
Definition: db_enum.h:38
key_data_set_introducing
int key_data_set_introducing(key_data_t *key_data, unsigned int introducing)
Definition: key_data.c:903
key_data_algorithm
unsigned int key_data_algorithm(const key_data_t *key_data)
Definition: key_data.c:687
key_data_update
int key_data_update(key_data_t *key_data)
Definition: key_data.c:1349
db_result_list_fetch_all
int db_result_list_fetch_all(db_result_list_t *result_list)
Definition: db_result.c:341
db_result_list_begin
const db_result_t * db_result_list_begin(db_result_list_t *result_list)
Definition: db_result.c:290
hsm_key_list_begin
const hsm_key_t * hsm_key_list_begin(hsm_key_list_t *hsm_key_list)
Definition: hsm_key.c:1832
key_data_set_keytag
int key_data_set_keytag(key_data_t *key_data, unsigned int keytag)
Definition: key_data.c:956
key_data_set_active_zsk
int key_data_set_active_zsk(key_data_t *key_data, unsigned int active_zsk)
Definition: key_data.c:913
key_data::hsm_key_id
db_value_t hsm_key_id
Definition: key_data.h:73
db_value_to_enum_value
int db_value_to_enum_value(const db_value_t *value, int *to_int, const db_enum_t *enum_set)
Definition: db_value.c:438
db_clause_value
const db_value_t * db_clause_value(const db_clause_t *clause)
Definition: db_clause.c:85
key_data_list_object_store
int key_data_list_object_store(key_data_list_t *key_data_list)
Definition: key_data.c:1684
key_data_get_by_hsm_key_id
int key_data_get_by_hsm_key_id(key_data_t *key_data, const db_value_t *hsm_key_id)
Definition: key_data.c:2479
zone_db_id
const db_value_t * zone_db_id(const zone_db_t *zone)
Definition: zone_db.c:728
hsm_key_list_free
void hsm_key_list_free(hsm_key_list_t *hsm_key_list)
Definition: hsm_key.c:1496
hsm_key_id
const db_value_t * hsm_key_id(const hsm_key_t *hsm_key)
Definition: hsm_key.c:504
key_data::private_zone_id
zone_db_t * private_zone_id
Definition: key_data.h:72
key_data_count
int key_data_count(key_data_t *key_data, db_clause_list_t *clause_list, size_t *count)
Definition: key_data.c:1633
ds_at_parent
const int ds_at_parent[5]
Definition: keystate_import_cmd.c:54
key_data_delete
int key_data_delete(key_data_t *key_data)
Definition: key_data.c:1587
key_data::publish
unsigned int publish
Definition: key_data.h:83
key_state_list::object_store
int object_store
Definition: key_state.h:267
zone_list_db_new_copy
zone_list_db_t * zone_list_db_new_copy(const zone_list_db_t *from_zone_list)
Definition: zone_db.c:1960
key_state_list_begin
const key_state_t * key_state_list_begin(key_state_list_t *key_state_list)
Definition: key_state.c:1240
key_data_set_algorithm
int key_data_set_algorithm(key_data_t *key_data, unsigned int algorithm)
Definition: key_data.c:870
db_clause_get_value
db_value_t * db_clause_get_value(db_clause_t *clause)
Definition: db_clause.c:187
db_value_set_get
db_value_t * db_value_set_get(db_value_set_t *value_set, size_t at)
Definition: db_value.c:756
db_object_field_list_add
int db_object_field_list_add(db_object_field_list_t *object_field_list, db_object_field_t *object_field)
Definition: db_object.c:254
zone_db_new
zone_db_t * zone_db_new(const db_connection_t *connection)
Definition: zone_db.c:287
hsm_key_new
hsm_key_t * hsm_key_new(const db_connection_t *connection)
Definition: hsm_key.c:244
key_data_set_minimize
int key_data_set_minimize(key_data_t *key_data, unsigned int minimize)
Definition: key_data.c:966
hsm_key_copy
int hsm_key_copy(hsm_key_t *hsm_key, const hsm_key_t *hsm_key_copy)
Definition: hsm_key.c:307
key_data_list_get_begin
key_data_t * key_data_list_get_begin(key_data_list_t *key_data_list)
Definition: key_data.c:2323
db_object_field
Definition: db_object.h:52