hsm_key.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 "hsm_key.h"
#include "db_error.h"
#include <string.h>
const db_enum_t hsm_key_enum_set_state[] = {
{ "UNUSED", (hsm_key_state_t)HSM_KEY_STATE_UNUSED },
{ "PRIVATE", (hsm_key_state_t)HSM_KEY_STATE_PRIVATE },
{ "SHARED", (hsm_key_state_t)HSM_KEY_STATE_SHARED },
{ "DELETE", (hsm_key_state_t)HSM_KEY_STATE_DELETE },
{ NULL, 0 }
};
const db_enum_t hsm_key_enum_set_role[] = {
{ "KSK", (hsm_key_role_t)HSM_KEY_ROLE_KSK },
{ "ZSK", (hsm_key_role_t)HSM_KEY_ROLE_ZSK },
{ "CSK", (hsm_key_role_t)HSM_KEY_ROLE_CSK },
{ NULL, 0 }
};
const db_enum_t hsm_key_enum_set_key_type[] = {
{ "RSA", (hsm_key_key_type_t)HSM_KEY_KEY_TYPE_RSA },
{ NULL, 0 }
};
const db_enum_t hsm_key_enum_set_backup[] = {
{ "Not Required", (hsm_key_backup_t)HSM_KEY_BACKUP_NO_BACKUP },
{ "Required", (hsm_key_backup_t)HSM_KEY_BACKUP_BACKUP_REQUIRED },
{ "Prepared", (hsm_key_backup_t)HSM_KEY_BACKUP_BACKUP_REQUESTED },
{ "Done", (hsm_key_backup_t)HSM_KEY_BACKUP_BACKUP_DONE },
{ NULL, 0 }
};
static db_object_t* __hsm_key_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, "hsmKey")
|| 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, "policyId")
|| 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, "locator")
|| db_object_field_set_type(object_field, DB_TYPE_TEXT)
|| 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, "state")
|| db_object_field_set_type(object_field, DB_TYPE_ENUM)
|| db_object_field_set_enum_set(object_field, hsm_key_enum_set_state)
|| 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, "bits")
|| 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, "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, "role")
|| db_object_field_set_type(object_field, DB_TYPE_ENUM)
|| db_object_field_set_enum_set(object_field, hsm_key_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, "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, "isRevoked")
|| 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, "keyType")
|| db_object_field_set_type(object_field, DB_TYPE_ENUM)
|| db_object_field_set_enum_set(object_field, hsm_key_enum_set_key_type)
|| 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, "repository")
|| db_object_field_set_type(object_field, DB_TYPE_TEXT)
|| 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, "backup")
|| db_object_field_set_type(object_field, DB_TYPE_ENUM)
|| db_object_field_set_enum_set(object_field, hsm_key_enum_set_backup)
|| 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;
}
/* HSM KEY */
hsm_key_t* hsm_key_new(const db_connection_t* connection) {
hsm_key_t* hsm_key =
(hsm_key_t*)calloc(1, sizeof(hsm_key_t));
if (hsm_key) {
if (!(hsm_key->dbo = __hsm_key_new_object(connection))) {
free(hsm_key);
return NULL;
}
db_value_reset(&(hsm_key->id));
db_value_reset(&(hsm_key->rev));
db_value_reset(&(hsm_key->policy_id));
hsm_key->state = HSM_KEY_STATE_UNUSED;
hsm_key->bits = 2048;
hsm_key->algorithm = 1;
hsm_key->role = HSM_KEY_ROLE_ZSK;
hsm_key->key_type = HSM_KEY_KEY_TYPE_RSA;
hsm_key->backup = HSM_KEY_BACKUP_NO_BACKUP;
}
return hsm_key;
}
hsm_key_t* hsm_key_new_copy(const hsm_key_t* hsm_key) {
hsm_key_t* new_hsm_key;
if (!hsm_key) {
return NULL;
}
if (!hsm_key->dbo) {
return NULL;
}
if (!(new_hsm_key = hsm_key_new(db_object_connection(hsm_key->dbo)))
|| hsm_key_copy(new_hsm_key, hsm_key))
{
hsm_key_free(new_hsm_key);
return NULL;
}
return new_hsm_key;
}
void hsm_key_free(hsm_key_t* hsm_key) {
if (hsm_key) {
if (hsm_key->dbo) {
db_object_free(hsm_key->dbo);
}
db_value_reset(&(hsm_key->id));
db_value_reset(&(hsm_key->rev));
db_value_reset(&(hsm_key->policy_id));
if (hsm_key->private_policy_id) {
policy_free(hsm_key->private_policy_id);
}
if (hsm_key->locator) {
free(hsm_key->locator);
}
if (hsm_key->repository) {
free(hsm_key->repository);
}
free(hsm_key);
}
}
int hsm_key_copy(hsm_key_t* hsm_key, const hsm_key_t* hsm_key_copy) {
char* locator_text = NULL;
char* repository_text = NULL;
if (!hsm_key) {
return DB_ERROR_UNKNOWN;
}
if (!hsm_key_copy) {
return DB_ERROR_UNKNOWN;
}
if (hsm_key_copy->locator) {
if (!(locator_text = strdup(hsm_key_copy->locator))) {
return DB_ERROR_UNKNOWN;
}
}
if (hsm_key_copy->repository) {
if (!(repository_text = strdup(hsm_key_copy->repository))) {
if (locator_text) {
free(locator_text);
}
return DB_ERROR_UNKNOWN;
}
}
if (db_value_copy(&(hsm_key->id), &(hsm_key_copy->id))) {
if (locator_text) {
free(locator_text);
}
if (repository_text) {
free(repository_text);
}
return DB_ERROR_UNKNOWN;
}
if (db_value_copy(&(hsm_key->rev), &(hsm_key_copy->rev))) {
if (locator_text) {
free(locator_text);
}
if (repository_text) {
free(repository_text);
}
return DB_ERROR_UNKNOWN;
}
if (db_value_copy(&(hsm_key->policy_id), &(hsm_key_copy->policy_id))) {
if (locator_text) {
free(locator_text);
}
if (repository_text) {
free(repository_text);
}
return DB_ERROR_UNKNOWN;
}
if (hsm_key->private_policy_id) {
policy_free(hsm_key->private_policy_id);
hsm_key->private_policy_id = NULL;
}
if (hsm_key_copy->private_policy_id
&& !(hsm_key->private_policy_id = policy_new_copy(hsm_key_copy->private_policy_id)))
{
if (locator_text) {
free(locator_text);
}
if (repository_text) {
free(repository_text);
}
return DB_ERROR_UNKNOWN;
}
hsm_key->associated_policy_id = NULL;
if (!hsm_key_copy->private_policy_id
&& hsm_key_copy->associated_policy_id
&& !(hsm_key->private_policy_id = policy_new_copy(hsm_key_copy->associated_policy_id)))
{
if (locator_text) {
free(locator_text);
}
if (repository_text) {
free(repository_text);
}
return DB_ERROR_UNKNOWN;
}
if (hsm_key->locator) {
free(hsm_key->locator);
}
hsm_key->locator = locator_text;
hsm_key->state = hsm_key_copy->state;
hsm_key->bits = hsm_key_copy->bits;
hsm_key->algorithm = hsm_key_copy->algorithm;
hsm_key->role = hsm_key_copy->role;
hsm_key->inception = hsm_key_copy->inception;
hsm_key->is_revoked = hsm_key_copy->is_revoked;
hsm_key->key_type = hsm_key_copy->key_type;
if (hsm_key->repository) {
free(hsm_key->repository);
}
hsm_key->repository = repository_text;
hsm_key->backup = hsm_key_copy->backup;
return DB_OK;
}
int hsm_key_from_result(hsm_key_t* hsm_key, const db_result_t* result) {
const db_value_set_t* value_set;
int state;
int role;
int key_type;
int backup;
if (!hsm_key) {
return DB_ERROR_UNKNOWN;
}
if (!result) {
return DB_ERROR_UNKNOWN;
}
db_value_reset(&(hsm_key->id));
db_value_reset(&(hsm_key->rev));
db_value_reset(&(hsm_key->policy_id));
if (hsm_key->locator) {
free(hsm_key->locator);
}
hsm_key->locator = NULL;
if (hsm_key->repository) {
free(hsm_key->repository);
}
hsm_key->repository = NULL;
if (!(value_set = db_result_value_set(result))
|| db_value_set_size(value_set) != 13
|| db_value_copy(&(hsm_key->id), db_value_set_at(value_set, 0))
|| db_value_copy(&(hsm_key->rev), db_value_set_at(value_set, 1))
|| db_value_copy(&(hsm_key->policy_id), db_value_set_at(value_set, 2))
|| db_value_to_text(db_value_set_at(value_set, 3), &(hsm_key->locator))
|| db_value_to_enum_value(db_value_set_at(value_set, 4), &state, hsm_key_enum_set_state)
|| db_value_to_uint32(db_value_set_at(value_set, 5), &(hsm_key->bits))
|| db_value_to_uint32(db_value_set_at(value_set, 6), &(hsm_key->algorithm))
|| db_value_to_enum_value(db_value_set_at(value_set, 7), &role, hsm_key_enum_set_role)
|| db_value_to_uint32(db_value_set_at(value_set, 8), &(hsm_key->inception))
|| db_value_to_uint32(db_value_set_at(value_set, 9), &(hsm_key->is_revoked))
|| db_value_to_enum_value(db_value_set_at(value_set, 10), &key_type, hsm_key_enum_set_key_type)
|| db_value_to_text(db_value_set_at(value_set, 11), &(hsm_key->repository))
|| db_value_to_enum_value(db_value_set_at(value_set, 12), &backup, hsm_key_enum_set_backup))
{
return DB_ERROR_UNKNOWN;
}
if (state == (hsm_key_state_t)HSM_KEY_STATE_UNUSED) {
hsm_key->state = HSM_KEY_STATE_UNUSED;
}
else if (state == (hsm_key_state_t)HSM_KEY_STATE_PRIVATE) {
hsm_key->state = HSM_KEY_STATE_PRIVATE;
}
else if (state == (hsm_key_state_t)HSM_KEY_STATE_SHARED) {
hsm_key->state = HSM_KEY_STATE_SHARED;
}
else if (state == (hsm_key_state_t)HSM_KEY_STATE_DELETE) {
hsm_key->state = HSM_KEY_STATE_DELETE;
}
else {
return DB_ERROR_UNKNOWN;
}
if (role == (hsm_key_role_t)HSM_KEY_ROLE_KSK) {
hsm_key->role = HSM_KEY_ROLE_KSK;
}
else if (role == (hsm_key_role_t)HSM_KEY_ROLE_ZSK) {
hsm_key->role = HSM_KEY_ROLE_ZSK;
}
else if (role == (hsm_key_role_t)HSM_KEY_ROLE_CSK) {
hsm_key->role = HSM_KEY_ROLE_CSK;
}
else {
return DB_ERROR_UNKNOWN;
}
if (key_type == (hsm_key_key_type_t)HSM_KEY_KEY_TYPE_RSA) {
hsm_key->key_type = HSM_KEY_KEY_TYPE_RSA;
}
else {
return DB_ERROR_UNKNOWN;
}
if (backup == (hsm_key_backup_t)HSM_KEY_BACKUP_NO_BACKUP) {
hsm_key->backup = HSM_KEY_BACKUP_NO_BACKUP;
}
else if (backup == (hsm_key_backup_t)HSM_KEY_BACKUP_BACKUP_REQUIRED) {
hsm_key->backup = HSM_KEY_BACKUP_BACKUP_REQUIRED;
}
else if (backup == (hsm_key_backup_t)HSM_KEY_BACKUP_BACKUP_REQUESTED) {
hsm_key->backup = HSM_KEY_BACKUP_BACKUP_REQUESTED;
}
else if (backup == (hsm_key_backup_t)HSM_KEY_BACKUP_BACKUP_DONE) {
hsm_key->backup = HSM_KEY_BACKUP_BACKUP_DONE;
}
else {
return DB_ERROR_UNKNOWN;
}
return DB_OK;
}
const db_value_t* hsm_key_id(const hsm_key_t* hsm_key) {
if (!hsm_key) {
return NULL;
}
return &(hsm_key->id);
}
const db_value_t* hsm_key_policy_id(const hsm_key_t* hsm_key) {
if (!hsm_key) {
return NULL;
}
return &(hsm_key->policy_id);
}
const char* hsm_key_locator(const hsm_key_t* hsm_key) {
if (!hsm_key) {
return NULL;
}
return hsm_key->locator;
}
hsm_key_state_t hsm_key_state(const hsm_key_t* hsm_key) {
if (!hsm_key) {
return HSM_KEY_STATE_INVALID;
}
return hsm_key->state;
}
unsigned int hsm_key_bits(const hsm_key_t* hsm_key) {
if (!hsm_key) {
return 0;
}
return hsm_key->bits;
}
unsigned int hsm_key_algorithm(const hsm_key_t* hsm_key) {
if (!hsm_key) {
return 0;
}
return hsm_key->algorithm;
}
hsm_key_role_t hsm_key_role(const hsm_key_t* hsm_key) {
if (!hsm_key) {
return HSM_KEY_ROLE_INVALID;
}
return hsm_key->role;
}
unsigned int hsm_key_inception(const hsm_key_t* hsm_key) {
if (!hsm_key) {
return 0;
}
return hsm_key->inception;
}
const char* hsm_key_repository(const hsm_key_t* hsm_key) {
if (!hsm_key) {
return NULL;
}
return hsm_key->repository;
}
hsm_key_backup_t hsm_key_backup(const hsm_key_t* hsm_key) {
if (!hsm_key) {
return HSM_KEY_BACKUP_INVALID;
}
return hsm_key->backup;
}
int hsm_key_set_policy_id(hsm_key_t* hsm_key, const db_value_t* policy_id) {
if (!hsm_key) {
return DB_ERROR_UNKNOWN;
}
if (!policy_id) {
return DB_ERROR_UNKNOWN;
}
if (db_value_not_empty(policy_id)) {
return DB_ERROR_UNKNOWN;
}
db_value_reset(&(hsm_key->policy_id));
if (db_value_copy(&(hsm_key->policy_id), policy_id)) {
return DB_ERROR_UNKNOWN;
}
return DB_OK;
}
int hsm_key_set_locator(hsm_key_t* hsm_key, const char* locator_text) {
char* new_locator;
if (!hsm_key) {
return DB_ERROR_UNKNOWN;
}
if (!locator_text) {
return DB_ERROR_UNKNOWN;
}
if (!(new_locator = strdup(locator_text))) {
return DB_ERROR_UNKNOWN;
}
if (hsm_key->locator) {
free(hsm_key->locator);
}
hsm_key->locator = new_locator;
return DB_OK;
}
int hsm_key_set_state(hsm_key_t* hsm_key, hsm_key_state_t state) {
if (!hsm_key) {
return DB_ERROR_UNKNOWN;
}
if (state == HSM_KEY_STATE_INVALID) {
return DB_ERROR_UNKNOWN;
}
hsm_key->state = state;
return DB_OK;
}
int hsm_key_set_bits(hsm_key_t* hsm_key, unsigned int bits) {
if (!hsm_key) {
return DB_ERROR_UNKNOWN;
}
hsm_key->bits = bits;
return DB_OK;
}
int hsm_key_set_algorithm(hsm_key_t* hsm_key, unsigned int algorithm) {
if (!hsm_key) {
return DB_ERROR_UNKNOWN;
}
hsm_key->algorithm = algorithm;
return DB_OK;
}
int hsm_key_set_role(hsm_key_t* hsm_key, hsm_key_role_t role) {
if (!hsm_key) {
return DB_ERROR_UNKNOWN;
}
if (role == HSM_KEY_ROLE_INVALID) {
return DB_ERROR_UNKNOWN;
}
hsm_key->role = role;
return DB_OK;
}
int hsm_key_set_inception(hsm_key_t* hsm_key, unsigned int inception) {
if (!hsm_key) {
return DB_ERROR_UNKNOWN;
}
hsm_key->inception = inception;
return DB_OK;
}
int hsm_key_set_key_type(hsm_key_t* hsm_key, hsm_key_key_type_t key_type) {
if (!hsm_key) {
return DB_ERROR_UNKNOWN;
}
if (key_type == HSM_KEY_KEY_TYPE_INVALID) {
return DB_ERROR_UNKNOWN;
}
hsm_key->key_type = key_type;
return DB_OK;
}
int hsm_key_set_repository(hsm_key_t* hsm_key, const char* repository_text) {
char* new_repository;
if (!hsm_key) {
return DB_ERROR_UNKNOWN;
}
if (!repository_text) {
return DB_ERROR_UNKNOWN;
}
if (!(new_repository = strdup(repository_text))) {
return DB_ERROR_UNKNOWN;
}
if (hsm_key->repository) {
free(hsm_key->repository);
}
hsm_key->repository = new_repository;
return DB_OK;
}
int hsm_key_set_backup(hsm_key_t* hsm_key, hsm_key_backup_t backup) {
if (!hsm_key) {
return DB_ERROR_UNKNOWN;
}
if (backup == HSM_KEY_BACKUP_INVALID) {
return DB_ERROR_UNKNOWN;
}
hsm_key->backup = backup;
return DB_OK;
}
db_clause_t* hsm_key_policy_id_clause(db_clause_list_t* clause_list, const db_value_t* policy_id) {
db_clause_t* clause;
if (!clause_list) {
return NULL;
}
if (!policy_id) {
return NULL;
}
if (db_value_not_empty(policy_id)) {
return NULL;
}
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "policyId")
|| 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), policy_id)
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
return NULL;
}
return clause;
}
db_clause_t* hsm_key_state_clause(db_clause_list_t* clause_list, hsm_key_state_t state) {
db_clause_t* clause;
if (!clause_list) {
return NULL;
}
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "state")
|| 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), state, hsm_key_enum_set_state)
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
return NULL;
}
return clause;
}
db_clause_t* hsm_key_bits_clause(db_clause_list_t* clause_list, unsigned int bits) {
db_clause_t* clause;
if (!clause_list) {
return NULL;
}
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "bits")
|| 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), bits)
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
return NULL;
}
return clause;
}
db_clause_t* hsm_key_algorithm_clause(db_clause_list_t* clause_list, unsigned int algorithm) {
db_clause_t* clause;
if (!clause_list) {
return NULL;
}
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "algorithm")
|| 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), algorithm)
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
return NULL;
}
return clause;
}
db_clause_t* hsm_key_role_clause(db_clause_list_t* clause_list, hsm_key_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, hsm_key_enum_set_role)
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
return NULL;
}
return clause;
}
db_clause_t* hsm_key_is_revoked_clause(db_clause_list_t* clause_list, unsigned int is_revoked) {
db_clause_t* clause;
if (!clause_list) {
return NULL;
}
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "isRevoked")
|| 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), is_revoked)
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
return NULL;
}
return clause;
}
db_clause_t* hsm_key_key_type_clause(db_clause_list_t* clause_list, hsm_key_key_type_t key_type) {
db_clause_t* clause;
if (!clause_list) {
return NULL;
}
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "keyType")
|| 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), key_type, hsm_key_enum_set_key_type)
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
return NULL;
}
return clause;
}
db_clause_t* hsm_key_repository_clause(db_clause_list_t* clause_list, const char* repository_text) {
db_clause_t* clause;
if (!clause_list) {
return NULL;
}
if (!repository_text) {
return NULL;
}
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "repository")
|| db_clause_set_type(clause, DB_CLAUSE_EQUAL)
|| db_clause_set_operator(clause, DB_CLAUSE_OPERATOR_AND)
|| db_value_from_text(db_clause_get_value(clause), repository_text)
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
return NULL;
}
return clause;
}
db_clause_t* hsm_key_backup_clause(db_clause_list_t* clause_list, hsm_key_backup_t backup) {
db_clause_t* clause;
if (!clause_list) {
return NULL;
}
if (!(clause = db_clause_new())
|| db_clause_set_field(clause, "backup")
|| 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), backup, hsm_key_enum_set_backup)
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
return NULL;
}
return clause;
}
int hsm_key_create(hsm_key_t* hsm_key) {
db_object_field_list_t* object_field_list;
db_object_field_t* object_field;
db_value_set_t* value_set;
int ret;
if (!hsm_key) {
return DB_ERROR_UNKNOWN;
}
if (!hsm_key->dbo) {
return DB_ERROR_UNKNOWN;
}
if (!db_value_not_empty(&(hsm_key->id))) {
return DB_ERROR_UNKNOWN;
}
if (!db_value_not_empty(&(hsm_key->rev))) {
return DB_ERROR_UNKNOWN;
}
if (db_value_not_empty(&(hsm_key->policy_id))) {
return DB_ERROR_UNKNOWN;
}
if (!hsm_key->locator) {
return DB_ERROR_UNKNOWN;
}
if (!hsm_key->repository) {
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, "policyId")
|| 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, "locator")
|| db_object_field_set_type(object_field, DB_TYPE_TEXT)
|| 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, "state")
|| db_object_field_set_type(object_field, DB_TYPE_ENUM)
|| db_object_field_set_enum_set(object_field, hsm_key_enum_set_state)
|| 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, "bits")
|| 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, "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, "role")
|| db_object_field_set_type(object_field, DB_TYPE_ENUM)
|| db_object_field_set_enum_set(object_field, hsm_key_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, "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, "isRevoked")
|| 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, "keyType")
|| db_object_field_set_type(object_field, DB_TYPE_ENUM)
|| db_object_field_set_enum_set(object_field, hsm_key_enum_set_key_type)
|| 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, "repository")
|| db_object_field_set_type(object_field, DB_TYPE_TEXT)
|| 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, "backup")
|| db_object_field_set_type(object_field, DB_TYPE_ENUM)
|| db_object_field_set_enum_set(object_field, hsm_key_enum_set_backup)
|| 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(11))) {
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (db_value_copy(db_value_set_get(value_set, 0), &(hsm_key->policy_id))
|| db_value_from_text(db_value_set_get(value_set, 1), hsm_key->locator)
|| db_value_from_enum_value(db_value_set_get(value_set, 2), hsm_key->state, hsm_key_enum_set_state)
|| db_value_from_uint32(db_value_set_get(value_set, 3), hsm_key->bits)
|| db_value_from_uint32(db_value_set_get(value_set, 4), hsm_key->algorithm)
|| db_value_from_enum_value(db_value_set_get(value_set, 5), hsm_key->role, hsm_key_enum_set_role)
|| db_value_from_uint32(db_value_set_get(value_set, 6), hsm_key->inception)
|| db_value_from_uint32(db_value_set_get(value_set, 7), hsm_key->is_revoked)
|| db_value_from_enum_value(db_value_set_get(value_set, 8), hsm_key->key_type, hsm_key_enum_set_key_type)
|| db_value_from_text(db_value_set_get(value_set, 9), hsm_key->repository)
|| db_value_from_enum_value(db_value_set_get(value_set, 10), hsm_key->backup, hsm_key_enum_set_backup))
{
db_value_set_free(value_set);
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
ret = db_object_create(hsm_key->dbo, object_field_list, value_set);
db_value_set_free(value_set);
db_object_field_list_free(object_field_list);
return ret;
}
int hsm_key_get_by_id(hsm_key_t* hsm_key, 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 (!hsm_key) {
return DB_ERROR_UNKNOWN;
}
if (!hsm_key->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(hsm_key->dbo, NULL, clause_list);
db_clause_list_free(clause_list);
if (result_list) {
result = db_result_list_next(result_list);
if (result) {
if (hsm_key_from_result(hsm_key, 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 hsm_key_get_by_locator(hsm_key_t* hsm_key, const char* locator) {
db_clause_list_t* clause_list;
db_clause_t* clause;
db_result_list_t* result_list;
const db_result_t* result;
if (!hsm_key) {
return DB_ERROR_UNKNOWN;
}
if (!hsm_key->dbo) {
return DB_ERROR_UNKNOWN;
}
if (!locator) {
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, "locator")
|| db_clause_set_type(clause, DB_CLAUSE_EQUAL)
|| db_value_from_text(db_clause_get_value(clause), locator)
|| 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(hsm_key->dbo, NULL, clause_list);
db_clause_list_free(clause_list);
if (result_list) {
result = db_result_list_next(result_list);
if (result) {
if (hsm_key_from_result(hsm_key, 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;
}
hsm_key_t* hsm_key_new_get_by_locator(const db_connection_t* connection, const char* locator) {
hsm_key_t* hsm_key;
if (!connection) {
return NULL;
}
if (!locator) {
return NULL;
}
if (!(hsm_key = hsm_key_new(connection))
|| hsm_key_get_by_locator(hsm_key, locator))
{
hsm_key_free(hsm_key);
return NULL;
}
return hsm_key;
}
int hsm_key_update(hsm_key_t* hsm_key) {
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 (!hsm_key) {
return DB_ERROR_UNKNOWN;
}
if (!hsm_key->dbo) {
return DB_ERROR_UNKNOWN;
}
if (db_value_not_empty(&(hsm_key->id))) {
return DB_ERROR_UNKNOWN;
}
if (db_value_not_empty(&(hsm_key->rev))) {
return DB_ERROR_UNKNOWN;
}
if (db_value_not_empty(&(hsm_key->policy_id))) {
return DB_ERROR_UNKNOWN;
}
if (!hsm_key->locator) {
return DB_ERROR_UNKNOWN;
}
if (!hsm_key->repository) {
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, "policyId")
|| 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, "locator")
|| db_object_field_set_type(object_field, DB_TYPE_TEXT)
|| 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, "state")
|| db_object_field_set_type(object_field, DB_TYPE_ENUM)
|| db_object_field_set_enum_set(object_field, hsm_key_enum_set_state)
|| 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, "bits")
|| 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, "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, "role")
|| db_object_field_set_type(object_field, DB_TYPE_ENUM)
|| db_object_field_set_enum_set(object_field, hsm_key_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, "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, "isRevoked")
|| 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, "keyType")
|| db_object_field_set_type(object_field, DB_TYPE_ENUM)
|| db_object_field_set_enum_set(object_field, hsm_key_enum_set_key_type)
|| 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, "repository")
|| db_object_field_set_type(object_field, DB_TYPE_TEXT)
|| 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, "backup")
|| db_object_field_set_type(object_field, DB_TYPE_ENUM)
|| db_object_field_set_enum_set(object_field, hsm_key_enum_set_backup)
|| 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(11))) {
db_object_field_list_free(object_field_list);
return DB_ERROR_UNKNOWN;
}
if (db_value_copy(db_value_set_get(value_set, 0), &(hsm_key->policy_id))
|| db_value_from_text(db_value_set_get(value_set, 1), hsm_key->locator)
|| db_value_from_enum_value(db_value_set_get(value_set, 2), hsm_key->state, hsm_key_enum_set_state)
|| db_value_from_uint32(db_value_set_get(value_set, 3), hsm_key->bits)
|| db_value_from_uint32(db_value_set_get(value_set, 4), hsm_key->algorithm)
|| db_value_from_enum_value(db_value_set_get(value_set, 5), hsm_key->role, hsm_key_enum_set_role)
|| db_value_from_uint32(db_value_set_get(value_set, 6), hsm_key->inception)
|| db_value_from_uint32(db_value_set_get(value_set, 7), hsm_key->is_revoked)
|| db_value_from_enum_value(db_value_set_get(value_set, 8), hsm_key->key_type, hsm_key_enum_set_key_type)
|| db_value_from_text(db_value_set_get(value_set, 9), hsm_key->repository)
|| db_value_from_enum_value(db_value_set_get(value_set, 10), hsm_key->backup, hsm_key_enum_set_backup))
{
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), &(hsm_key->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), &(hsm_key->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(hsm_key->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 hsm_key_count(hsm_key_t* hsm_key, db_clause_list_t* clause_list, size_t* count) {
if (!hsm_key) {
return DB_ERROR_UNKNOWN;
}
if (!hsm_key->dbo) {
return DB_ERROR_UNKNOWN;
}
if (!count) {
return DB_ERROR_UNKNOWN;
}
return db_object_count(hsm_key->dbo, NULL, clause_list, count);
}
/* HSM KEY LIST */
hsm_key_list_t* hsm_key_list_new(const db_connection_t* connection) {
hsm_key_list_t* hsm_key_list =
(hsm_key_list_t*)calloc(1, sizeof(hsm_key_list_t));
if (hsm_key_list) {
if (!(hsm_key_list->dbo = __hsm_key_new_object(connection))) {
free(hsm_key_list);
return NULL;
}
}
return hsm_key_list;
}
hsm_key_list_t* hsm_key_list_new_copy(const hsm_key_list_t* from_hsm_key_list) {
hsm_key_list_t* hsm_key_list;
if (!from_hsm_key_list) {
return NULL;
}
if (!from_hsm_key_list->dbo) {
return NULL;
}
if (!(hsm_key_list = hsm_key_list_new(db_object_connection(from_hsm_key_list->dbo)))
|| hsm_key_list_copy(hsm_key_list, from_hsm_key_list))
{
hsm_key_list_free(hsm_key_list);
return NULL;
}
return hsm_key_list;
}
int hsm_key_list_object_store(hsm_key_list_t* hsm_key_list) {
if (!hsm_key_list) {
return DB_ERROR_UNKNOWN;
}
hsm_key_list->object_store = 1;
return DB_OK;
}
void hsm_key_list_free(hsm_key_list_t* hsm_key_list) {
size_t i;
if (hsm_key_list) {
if (hsm_key_list->dbo) {
db_object_free(hsm_key_list->dbo);
}
if (hsm_key_list->result_list) {
db_result_list_free(hsm_key_list->result_list);
}
if (hsm_key_list->hsm_key) {
hsm_key_free(hsm_key_list->hsm_key);
}
for (i = 0; i < hsm_key_list->object_list_size; i++) {
if (hsm_key_list->object_list[i]) {
hsm_key_free(hsm_key_list->object_list[i]);
}
}
if (hsm_key_list->object_list) {
free(hsm_key_list->object_list);
}
if (hsm_key_list->policy_id_list) {
policy_list_free(hsm_key_list->policy_id_list);
}
free(hsm_key_list);
}
}
int hsm_key_list_copy(hsm_key_list_t* hsm_key_list, const hsm_key_list_t* from_hsm_key_list) {
size_t i;
if (!hsm_key_list) {
return DB_ERROR_UNKNOWN;
}
if (!from_hsm_key_list) {
return DB_ERROR_UNKNOWN;
}
if (from_hsm_key_list->object_list && !from_hsm_key_list->object_list_size) {
return DB_ERROR_UNKNOWN;
}
if (hsm_key_list->result_list) {
db_result_list_free(hsm_key_list->result_list);
hsm_key_list->result_list = NULL;
}
if (from_hsm_key_list->result_list
&& !(hsm_key_list->result_list = db_result_list_new_copy(from_hsm_key_list->result_list)))
{
return DB_ERROR_UNKNOWN;
}
hsm_key_list->object_store = from_hsm_key_list->object_store;
for (i = 0; i < hsm_key_list->object_list_size; i++) {
if (hsm_key_list->object_list[i]) {
hsm_key_free(hsm_key_list->object_list[i]);
}
}
hsm_key_list->object_list_size = 0;
if (hsm_key_list->object_list) {
free(hsm_key_list->object_list);
hsm_key_list->object_list = NULL;
}
if (from_hsm_key_list->object_list) {
if (!(hsm_key_list->object_list = (hsm_key_t**)calloc(from_hsm_key_list->object_list_size, sizeof(hsm_key_t*)))) {
return DB_ERROR_UNKNOWN;
}
hsm_key_list->object_list_size = from_hsm_key_list->object_list_size;
for (i = 0; i < from_hsm_key_list->object_list_size; i++) {
if (!from_hsm_key_list->object_list[i]) {
continue;
}
if (!(hsm_key_list->object_list[i] = hsm_key_new_copy(from_hsm_key_list->object_list[i]))) {
return DB_ERROR_UNKNOWN;
}
}
}
hsm_key_list->object_list_position = 0;;
hsm_key_list->object_list_first = 1;
hsm_key_list->associated_fetch = from_hsm_key_list->associated_fetch;
if (from_hsm_key_list->policy_id_list
&& !(hsm_key_list->policy_id_list = policy_list_new_copy(from_hsm_key_list->policy_id_list)))
{
return DB_ERROR_UNKNOWN;
}
return DB_OK;
}
static int hsm_key_list_get_associated(hsm_key_list_t* hsm_key_list) {
const db_clause_t* clause_walk;
const policy_t* policy_policy_id;
int cmp;
size_t i;
db_clause_list_t* clause_list;
db_clause_t* clause;
const hsm_key_t* hsm_key;
if (!hsm_key_list) {
return DB_ERROR_UNKNOWN;
}
if (!hsm_key_list->dbo) {
return DB_ERROR_UNKNOWN;
}
if (!hsm_key_list->associated_fetch) {
return DB_ERROR_UNKNOWN;
}
if (!hsm_key_list->result_list) {
return DB_ERROR_UNKNOWN;
}
if (hsm_key_list->object_list) {
return DB_ERROR_UNKNOWN;
}
if (hsm_key_list->policy_id_list) {
policy_list_free(hsm_key_list->policy_id_list);
hsm_key_list->policy_id_list = NULL;
}
if (!(clause_list = db_clause_list_new())) {
return DB_ERROR_UNKNOWN;
}
hsm_key = hsm_key_list_begin(hsm_key_list);
while (hsm_key) {
cmp = 1;
clause_walk = db_clause_list_begin(clause_list);
while (clause_walk) {
if (db_value_cmp(db_clause_value(clause_walk), hsm_key_policy_id(hsm_key), &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), hsm_key_policy_id(hsm_key))
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
}
hsm_key = hsm_key_list_next(hsm_key_list);
}
if (!(hsm_key_list->policy_id_list = policy_list_new(db_object_connection(hsm_key_list->dbo)))
|| policy_list_object_store(hsm_key_list->policy_id_list)
|| policy_list_get_by_clauses(hsm_key_list->policy_id_list, clause_list))
{
if (hsm_key_list->policy_id_list) {
policy_list_free(hsm_key_list->policy_id_list);
hsm_key_list->policy_id_list = NULL;
}
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
db_clause_list_free(clause_list);
for (i = 0; i < hsm_key_list->object_list_size; i++) {
if (!(hsm_key_list->object_list[i])) {
return DB_ERROR_UNKNOWN;
}
policy_policy_id = policy_list_begin(hsm_key_list->policy_id_list);
while (policy_policy_id) {
if (db_value_cmp(hsm_key_policy_id(hsm_key_list->object_list[i]), policy_id(policy_policy_id), &cmp)) {
return DB_ERROR_UNKNOWN;
}
if (!cmp) {
hsm_key_list->object_list[i]->associated_policy_id = policy_policy_id;
}
policy_policy_id = policy_list_next(hsm_key_list->policy_id_list);
}
}
hsm_key_list->object_list_first = 1;
return DB_OK;
}
int hsm_key_list_get_by_clauses(hsm_key_list_t* hsm_key_list, const db_clause_list_t* clause_list) {
size_t i;
if (!hsm_key_list) {
return DB_ERROR_UNKNOWN;
}
if (!clause_list) {
return DB_ERROR_UNKNOWN;
}
if (!hsm_key_list->dbo) {
return DB_ERROR_UNKNOWN;
}
if (hsm_key_list->result_list) {
db_result_list_free(hsm_key_list->result_list);
}
if (hsm_key_list->object_list_size) {
for (i = 0; i < hsm_key_list->object_list_size; i++) {
if (hsm_key_list->object_list[i]) {
hsm_key_free(hsm_key_list->object_list[i]);
}
}
hsm_key_list->object_list_size = 0;
hsm_key_list->object_list_first = 0;
}
if (hsm_key_list->object_list) {
free(hsm_key_list->object_list);
hsm_key_list->object_list = NULL;
}
if (!(hsm_key_list->result_list = db_object_read(hsm_key_list->dbo, NULL, clause_list))
|| db_result_list_fetch_all(hsm_key_list->result_list))
{
return DB_ERROR_UNKNOWN;
}
if (hsm_key_list->associated_fetch
&& hsm_key_list_get_associated(hsm_key_list))
{
return DB_ERROR_UNKNOWN;
}
return DB_OK;
}
hsm_key_list_t* hsm_key_list_new_get_by_clauses(const db_connection_t* connection, const db_clause_list_t* clause_list) {
hsm_key_list_t* hsm_key_list;
if (!connection) {
return NULL;
}
if (!clause_list) {
return NULL;
}
if (!(hsm_key_list = hsm_key_list_new(connection))
|| hsm_key_list_get_by_clauses(hsm_key_list, clause_list))
{
hsm_key_list_free(hsm_key_list);
return NULL;
}
return hsm_key_list;
}
int hsm_key_list_get_by_policy_id(hsm_key_list_t* hsm_key_list, const db_value_t* policy_id) {
db_clause_list_t* clause_list;
db_clause_t* clause;
size_t i;
if (!hsm_key_list) {
return DB_ERROR_UNKNOWN;
}
if (!hsm_key_list->dbo) {
return DB_ERROR_UNKNOWN;
}
if (!policy_id) {
return DB_ERROR_UNKNOWN;
}
if (db_value_not_empty(policy_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, "policyId")
|| db_clause_set_type(clause, DB_CLAUSE_EQUAL)
|| db_value_copy(db_clause_get_value(clause), policy_id)
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
if (hsm_key_list->result_list) {
db_result_list_free(hsm_key_list->result_list);
}
if (hsm_key_list->object_list_size) {
for (i = 0; i < hsm_key_list->object_list_size; i++) {
if (hsm_key_list->object_list[i]) {
hsm_key_free(hsm_key_list->object_list[i]);
}
}
hsm_key_list->object_list_size = 0;
hsm_key_list->object_list_first = 0;
}
if (hsm_key_list->object_list) {
free(hsm_key_list->object_list);
hsm_key_list->object_list = NULL;
}
if (!(hsm_key_list->result_list = db_object_read(hsm_key_list->dbo, NULL, clause_list))
|| db_result_list_fetch_all(hsm_key_list->result_list))
{
db_clause_list_free(clause_list);
return DB_ERROR_UNKNOWN;
}
db_clause_list_free(clause_list);
if (hsm_key_list->associated_fetch
&& hsm_key_list_get_associated(hsm_key_list))
{
return DB_ERROR_UNKNOWN;
}
return DB_OK;
}
hsm_key_list_t* hsm_key_list_new_get_by_policy_id(const db_connection_t* connection, const db_value_t* policy_id) {
hsm_key_list_t* hsm_key_list;
if (!connection) {
return NULL;
}
if (!policy_id) {
return NULL;
}
if (db_value_not_empty(policy_id)) {
return NULL;
}
if (!(hsm_key_list = hsm_key_list_new(connection))
|| hsm_key_list_get_by_policy_id(hsm_key_list, policy_id))
{
hsm_key_list_free(hsm_key_list);
return NULL;
}
return hsm_key_list;
}
const hsm_key_t* hsm_key_list_begin(hsm_key_list_t* hsm_key_list) {
const db_result_t* result;
if (!hsm_key_list) {
return NULL;
}
if (hsm_key_list->object_store) {
if (!hsm_key_list->object_list) {
if (!hsm_key_list->result_list) {
return NULL;
}
if (!db_result_list_size(hsm_key_list->result_list)) {
return NULL;
}
if (!(hsm_key_list->object_list = (hsm_key_t**)calloc(db_result_list_size(hsm_key_list->result_list), sizeof(hsm_key_t*)))) {
return NULL;
}
hsm_key_list->object_list_size = db_result_list_size(hsm_key_list->result_list);
}
if (!(hsm_key_list->object_list[0])) {
if (!hsm_key_list->result_list) {
return NULL;
}
if (!(result = db_result_list_begin(hsm_key_list->result_list))) {
return NULL;
}
if (!(hsm_key_list->object_list[0] = hsm_key_new(db_object_connection(hsm_key_list->dbo)))) {
return NULL;
}
if (hsm_key_from_result(hsm_key_list->object_list[0], result)) {
return NULL;
}
}
hsm_key_list->object_list_position = 0;
return hsm_key_list->object_list[0];
}
if (!hsm_key_list->result_list) {
return NULL;
}
if (!(result = db_result_list_begin(hsm_key_list->result_list))) {
return NULL;
}
if (!hsm_key_list->hsm_key) {
if (!(hsm_key_list->hsm_key = hsm_key_new(db_object_connection(hsm_key_list->dbo)))) {
return NULL;
}
}
if (hsm_key_from_result(hsm_key_list->hsm_key, result)) {
return NULL;
}
return hsm_key_list->hsm_key;
}
hsm_key_t* hsm_key_list_get_begin(hsm_key_list_t* hsm_key_list) {
const db_result_t* result;
hsm_key_t* hsm_key;
if (!hsm_key_list) {
return NULL;
}
if (hsm_key_list->object_store) {
if (!(hsm_key = hsm_key_new(db_object_connection(hsm_key_list->dbo)))) {
return NULL;
}
if (hsm_key_copy(hsm_key, hsm_key_list_begin(hsm_key_list))) {
hsm_key_free(hsm_key);
return NULL;
}
return hsm_key;
}
if (!hsm_key_list->result_list) {
return NULL;
}
if (!(result = db_result_list_begin(hsm_key_list->result_list))) {
return NULL;
}
if (!(hsm_key = hsm_key_new(db_object_connection(hsm_key_list->dbo)))) {
return NULL;
}
if (hsm_key_from_result(hsm_key, result)) {
hsm_key_free(hsm_key);
return NULL;
}
return hsm_key;
}
const hsm_key_t* hsm_key_list_next(hsm_key_list_t* hsm_key_list) {
const db_result_t* result;
if (!hsm_key_list) {
return NULL;
}
if (hsm_key_list->object_store) {
if (!hsm_key_list->object_list) {
if (!hsm_key_list->result_list) {
return NULL;
}
if (!db_result_list_size(hsm_key_list->result_list)) {
return NULL;
}
if (!(hsm_key_list->object_list = (hsm_key_t**)calloc(db_result_list_size(hsm_key_list->result_list), sizeof(hsm_key_t*)))) {
return NULL;
}
hsm_key_list->object_list_size = db_result_list_size(hsm_key_list->result_list);
hsm_key_list->object_list_position = 0;
}
else if (hsm_key_list->object_list_first) {
hsm_key_list->object_list_first = 0;
hsm_key_list->object_list_position = 0;
}
else {
hsm_key_list->object_list_position++;
}
if (hsm_key_list->object_list_position >= hsm_key_list->object_list_size) {
return NULL;
}
if (!(hsm_key_list->object_list[hsm_key_list->object_list_position])) {
if (!hsm_key_list->result_list) {
return NULL;
}
if (!(result = db_result_list_next(hsm_key_list->result_list))) {
return NULL;
}
if (!(hsm_key_list->object_list[hsm_key_list->object_list_position] = hsm_key_new(db_object_connection(hsm_key_list->dbo)))) {
return NULL;
}
if (hsm_key_from_result(hsm_key_list->object_list[hsm_key_list->object_list_position], result)) {
return NULL;
}
}
return hsm_key_list->object_list[hsm_key_list->object_list_position];
}
if (!hsm_key_list->result_list) {
return NULL;
}
if (!(result = db_result_list_next(hsm_key_list->result_list))) {
return NULL;
}
if (!hsm_key_list->hsm_key) {
if (!(hsm_key_list->hsm_key = hsm_key_new(db_object_connection(hsm_key_list->dbo)))) {
return NULL;
}
}
if (hsm_key_from_result(hsm_key_list->hsm_key, result)) {
return NULL;
}
return hsm_key_list->hsm_key;
}
hsm_key_t* hsm_key_list_get_next(hsm_key_list_t* hsm_key_list) {
const db_result_t* result;
hsm_key_t* hsm_key;
if (!hsm_key_list) {
return NULL;
}
if (hsm_key_list->object_store) {
if (!(hsm_key = hsm_key_new(db_object_connection(hsm_key_list->dbo)))) {
return NULL;
}
if (hsm_key_copy(hsm_key, hsm_key_list_next(hsm_key_list))) {
hsm_key_free(hsm_key);
return NULL;
}
return hsm_key;
}
if (!hsm_key_list->result_list) {
return NULL;
}
if (!(result = db_result_list_next(hsm_key_list->result_list))) {
return NULL;
}
if (!(hsm_key = hsm_key_new(db_object_connection(hsm_key_list->dbo)))) {
return NULL;
}
if (hsm_key_from_result(hsm_key, result)) {
hsm_key_free(hsm_key);
return NULL;
}
return hsm_key;
}
db_clause_value
const db_value_t * db_clause_value(const db_clause_t *clause)
Definition db_clause.c:85
db_clause_free
void db_clause_free(db_clause_t *clause)
Definition db_clause.c:56
db_clause_list_new
db_clause_list_t * db_clause_list_new(void)
Definition db_clause.c:202
db_clause_new
db_clause_t * db_clause_new(void)
Definition db_clause.c:43
db_clause_next
const db_clause_t * db_clause_next(const db_clause_t *clause)
Definition db_clause.c:179
db_clause_get_value
db_value_t * db_clause_get_value(db_clause_t *clause)
Definition db_clause.c:187
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_clause_list_free
void db_clause_list_free(db_clause_list_t *clause_list)
Definition db_clause.c:209
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_clause_set_field
int db_clause_set_field(db_clause_t *clause, const char *field)
Definition db_clause.c:109
db_clause_list_begin
const db_clause_t * db_clause_list_begin(const db_clause_list_t *clause_list)
Definition db_clause.c:255
db_clause_set_type
int db_clause_set_type(db_clause_t *clause, db_clause_type_t type)
Definition db_clause.c:130
DB_CLAUSE_OPERATOR_AND
@ DB_CLAUSE_OPERATOR_AND
Definition db_clause.h:97
DB_CLAUSE_OPERATOR_OR
@ DB_CLAUSE_OPERATOR_OR
Definition db_clause.h:101
DB_CLAUSE_EQUAL
@ DB_CLAUSE_EQUAL
Definition db_clause.h:44
db_error.h
DB_ERROR_UNKNOWN
#define DB_ERROR_UNKNOWN
Definition db_error.h:40
DB_OK
#define DB_OK
Definition db_error.h:36
db_object_connection
const db_connection_t * db_object_connection(const db_object_t *object)
Definition db_object.c:320
db_object_field_new
db_object_field_t * db_object_field_new(void)
Definition db_object.c:40
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
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
db_object_new
db_object_t * db_object_new(void)
Definition db_object.c:304
db_object_set_table
int db_object_set_table(db_object_t *object, const char *table)
Definition db_object.c:356
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
db_object_set_connection
int db_object_set_connection(db_object_t *object, const db_connection_t *connection)
Definition db_object.c:341
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_field_set_type
int db_object_field_set_type(db_object_field_t *object_field, db_type_t type)
Definition db_object.c:122
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
db_object_free
void db_object_free(db_object_t *object)
Definition db_object.c:311
db_object_field_list_new
db_object_field_list_t * db_object_field_list_new(void)
Definition db_object.c:174
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
db_object_field_free
void db_object_field_free(db_object_field_t *object_field)
Definition db_object.c:69
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
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_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
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_size
size_t db_result_list_size(const db_result_list_t *result_list)
Definition db_result.c:333
db_result_list_next
const db_result_t * db_result_list_next(db_result_list_t *result_list)
Definition db_result.c:310
db_result_list_begin
const db_result_t * db_result_list_begin(db_result_list_t *result_list)
Definition db_result.c:290
db_result_list_free
void db_result_list_free(db_result_list_t *result_list)
Definition db_result.c:160
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_result_value_set
const db_value_set_t * db_result_value_set(const db_result_t *result)
Definition db_result.c:97
DB_TYPE_PRIMARY_KEY
@ DB_TYPE_PRIMARY_KEY
Definition db_type.h:62
DB_TYPE_REVISION
@ DB_TYPE_REVISION
Definition db_type.h:97
DB_TYPE_TEXT
@ DB_TYPE_TEXT
Definition db_type.h:82
DB_TYPE_ENUM
@ DB_TYPE_ENUM
Definition db_type.h:86
DB_TYPE_UINT32
@ DB_TYPE_UINT32
Definition db_type.h:70
DB_TYPE_ANY
@ DB_TYPE_ANY
Definition db_type.h:90
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
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_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_value_set_free
void db_value_set_free(db_value_set_t *value_set)
Definition db_value.c:697
db_value_from_uint32
int db_value_from_uint32(db_value_t *value, db_type_uint32_t from_uint32)
Definition db_value.c:492
db_value_set_new
db_value_set_t * db_value_set_new(size_t size)
Definition db_value.c:622
db_value_from_text
int db_value_from_text(db_value_t *value, const char *from_text)
Definition db_value.c:531
db_value_copy
int db_value_copy(db_value_t *value, const db_value_t *from_value)
Definition db_value.c:77
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_value_set_size
size_t db_value_set_size(const db_value_set_t *value_set)
Definition db_value.c:734
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
db_value_to_text
int db_value_to_text(const db_value_t *value, char **to_text)
Definition db_value.c:417
db_value_not_empty
int db_value_not_empty(const db_value_t *value)
Definition db_value.c:347
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_value_reset
void db_value_reset(db_value_t *value)
Definition db_value.c:60
hsm_key_list_get_begin
hsm_key_t * hsm_key_list_get_begin(hsm_key_list_t *hsm_key_list)
Definition hsm_key.c:1888
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
hsm_key_free
void hsm_key_free(hsm_key_t *hsm_key)
Definition hsm_key.c:286
hsm_key_enum_set_role
const db_enum_t hsm_key_enum_set_role[]
Definition hsm_key.c:44
hsm_key_enum_set_key_type
const db_enum_t hsm_key_enum_set_key_type[]
Definition hsm_key.c:51
hsm_key_set_role
int hsm_key_set_role(hsm_key_t *hsm_key, hsm_key_role_t role)
Definition hsm_key.c:658
hsm_key_count
int hsm_key_count(hsm_key_t *hsm_key, db_clause_list_t *clause_list, size_t *count)
Definition hsm_key.c:1435
hsm_key_set_state
int hsm_key_set_state(hsm_key_t *hsm_key, hsm_key_state_t state)
Definition hsm_key.c:625
hsm_key_copy
int hsm_key_copy(hsm_key_t *hsm_key, const hsm_key_t *hsm_key_copy)
Definition hsm_key.c:307
hsm_key_repository
const char * hsm_key_repository(const hsm_key_t *hsm_key)
Definition hsm_key.c:568
hsm_key_list_object_store
int hsm_key_list_object_store(hsm_key_list_t *hsm_key_list)
Definition hsm_key.c:1486
hsm_key_locator
const char * hsm_key_locator(const hsm_key_t *hsm_key)
Definition hsm_key.c:520
hsm_key_set_inception
int hsm_key_set_inception(hsm_key_t *hsm_key, unsigned int inception)
Definition hsm_key.c:671
hsm_key_new_get_by_locator
hsm_key_t * hsm_key_new_get_by_locator(const db_connection_t *connection, const char *locator)
Definition hsm_key.c:1205
hsm_key_new
hsm_key_t * hsm_key_new(const db_connection_t *connection)
Definition hsm_key.c:244
hsm_key_set_bits
int hsm_key_set_bits(hsm_key_t *hsm_key, unsigned int bits)
Definition hsm_key.c:638
hsm_key_list_next
const hsm_key_t * hsm_key_list_next(hsm_key_list_t *hsm_key_list)
Definition hsm_key.c:1924
hsm_key_list_begin
const hsm_key_t * hsm_key_list_begin(hsm_key_list_t *hsm_key_list)
Definition hsm_key.c:1832
hsm_key_update
int hsm_key_update(hsm_key_t *hsm_key)
Definition hsm_key.c:1225
hsm_key_create
int hsm_key_create(hsm_key_t *hsm_key)
Definition hsm_key.c:927
hsm_key_set_key_type
int hsm_key_set_key_type(hsm_key_t *hsm_key, hsm_key_key_type_t key_type)
Definition hsm_key.c:681
hsm_key_list_free
void hsm_key_list_free(hsm_key_list_t *hsm_key_list)
Definition hsm_key.c:1496
hsm_key_policy_id_clause
db_clause_t * hsm_key_policy_id_clause(db_clause_list_t *clause_list, const db_value_t *policy_id)
Definition hsm_key.c:729
hsm_key_list_copy
int hsm_key_list_copy(hsm_key_list_t *hsm_key_list, const hsm_key_list_t *from_hsm_key_list)
Definition hsm_key.c:1524
hsm_key_algorithm
unsigned int hsm_key_algorithm(const hsm_key_t *hsm_key)
Definition hsm_key.c:544
hsm_key_enum_set_state
const db_enum_t hsm_key_enum_set_state[]
Definition hsm_key.c:36
hsm_key_is_revoked_clause
db_clause_t * hsm_key_is_revoked_clause(db_clause_list_t *clause_list, unsigned int is_revoked)
Definition hsm_key.c:840
hsm_key_list_new_get_by_policy_id
hsm_key_list_t * hsm_key_list_new_get_by_policy_id(const db_connection_t *connection, const db_value_t *policy_id)
Definition hsm_key.c:1809
hsm_key_set_repository
int hsm_key_set_repository(hsm_key_t *hsm_key, const char *repository_text)
Definition hsm_key.c:694
hsm_key_list_new
hsm_key_list_t * hsm_key_list_new(const db_connection_t *connection)
Definition hsm_key.c:1453
hsm_key_backup_clause
db_clause_t * hsm_key_backup_clause(db_clause_list_t *clause_list, hsm_key_backup_t backup)
Definition hsm_key.c:906
hsm_key_set_backup
int hsm_key_set_backup(hsm_key_t *hsm_key, hsm_key_backup_t backup)
Definition hsm_key.c:716
hsm_key_bits
unsigned int hsm_key_bits(const hsm_key_t *hsm_key)
Definition hsm_key.c:536
hsm_key_get_by_locator
int hsm_key_get_by_locator(hsm_key_t *hsm_key, const char *locator)
Definition hsm_key.c:1155
hsm_key_from_result
int hsm_key_from_result(hsm_key_t *hsm_key, const db_result_t *result)
Definition hsm_key.c:405
hsm_key_algorithm_clause
db_clause_t * hsm_key_algorithm_clause(db_clause_list_t *clause_list, unsigned int algorithm)
Definition hsm_key.c:798
hsm_key_repository_clause
db_clause_t * hsm_key_repository_clause(db_clause_list_t *clause_list, const char *repository_text)
Definition hsm_key.c:882
hsm_key_state_clause
db_clause_t * hsm_key_state_clause(db_clause_list_t *clause_list, hsm_key_state_t state)
Definition hsm_key.c:756
hsm_key_set_policy_id
int hsm_key_set_policy_id(hsm_key_t *hsm_key, const db_value_t *policy_id)
Definition hsm_key.c:584
hsm_key_policy_id
const db_value_t * hsm_key_policy_id(const hsm_key_t *hsm_key)
Definition hsm_key.c:512
hsm_key_new_copy
hsm_key_t * hsm_key_new_copy(const hsm_key_t *hsm_key)
Definition hsm_key.c:267
hsm_key_inception
unsigned int hsm_key_inception(const hsm_key_t *hsm_key)
Definition hsm_key.c:560
hsm_key_id
const db_value_t * hsm_key_id(const hsm_key_t *hsm_key)
Definition hsm_key.c:504
hsm_key_list_get_by_policy_id
int hsm_key_list_get_by_policy_id(hsm_key_list_t *hsm_key_list, const db_value_t *policy_id)
Definition hsm_key.c:1746
hsm_key_key_type_clause
db_clause_t * hsm_key_key_type_clause(db_clause_list_t *clause_list, hsm_key_key_type_t key_type)
Definition hsm_key.c:861
hsm_key_list_get_next
hsm_key_t * hsm_key_list_get_next(hsm_key_list_t *hsm_key_list)
Definition hsm_key.c:1990
hsm_key_enum_set_backup
const db_enum_t hsm_key_enum_set_backup[]
Definition hsm_key.c:56
hsm_key_bits_clause
db_clause_t * hsm_key_bits_clause(db_clause_list_t *clause_list, unsigned int bits)
Definition hsm_key.c:777
hsm_key_list_new_get_by_clauses
hsm_key_list_t * hsm_key_list_new_get_by_clauses(const db_connection_t *connection, const db_clause_list_t *clause_list)
Definition hsm_key.c:1726
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
hsm_key_role_clause
db_clause_t * hsm_key_role_clause(db_clause_list_t *clause_list, hsm_key_role_t role)
Definition hsm_key.c:819
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
hsm_key_set_locator
int hsm_key_set_locator(hsm_key_t *hsm_key, const char *locator_text)
Definition hsm_key.c:603
hsm_key_set_algorithm
int hsm_key_set_algorithm(hsm_key_t *hsm_key, unsigned int algorithm)
Definition hsm_key.c:648
hsm_key.h
hsm_key_backup_t
enum hsm_key_backup hsm_key_backup_t
hsm_key_state_t
enum hsm_key_state hsm_key_state_t
hsm_key_role_t
enum hsm_key_role hsm_key_role_t
hsm_key_state
hsm_key_state
Definition hsm_key.h:40
HSM_KEY_STATE_UNUSED
@ HSM_KEY_STATE_UNUSED
Definition hsm_key.h:42
HSM_KEY_STATE_INVALID
@ HSM_KEY_STATE_INVALID
Definition hsm_key.h:41
HSM_KEY_STATE_PRIVATE
@ HSM_KEY_STATE_PRIVATE
Definition hsm_key.h:43
HSM_KEY_STATE_SHARED
@ HSM_KEY_STATE_SHARED
Definition hsm_key.h:44
HSM_KEY_STATE_DELETE
@ HSM_KEY_STATE_DELETE
Definition hsm_key.h:45
hsm_key_backup
hsm_key_backup
Definition hsm_key.h:64
HSM_KEY_BACKUP_BACKUP_REQUESTED
@ HSM_KEY_BACKUP_BACKUP_REQUESTED
Definition hsm_key.h:68
HSM_KEY_BACKUP_NO_BACKUP
@ HSM_KEY_BACKUP_NO_BACKUP
Definition hsm_key.h:66
HSM_KEY_BACKUP_INVALID
@ HSM_KEY_BACKUP_INVALID
Definition hsm_key.h:65
HSM_KEY_BACKUP_BACKUP_DONE
@ HSM_KEY_BACKUP_BACKUP_DONE
Definition hsm_key.h:69
HSM_KEY_BACKUP_BACKUP_REQUIRED
@ HSM_KEY_BACKUP_BACKUP_REQUIRED
Definition hsm_key.h:67
hsm_key_key_type_t
enum hsm_key_key_type hsm_key_key_type_t
hsm_key_role
hsm_key_role
Definition hsm_key.h:49
HSM_KEY_ROLE_INVALID
@ HSM_KEY_ROLE_INVALID
Definition hsm_key.h:50
HSM_KEY_ROLE_KSK
@ HSM_KEY_ROLE_KSK
Definition hsm_key.h:51
HSM_KEY_ROLE_ZSK
@ HSM_KEY_ROLE_ZSK
Definition hsm_key.h:52
HSM_KEY_ROLE_CSK
@ HSM_KEY_ROLE_CSK
Definition hsm_key.h:53
HSM_KEY_KEY_TYPE_RSA
@ HSM_KEY_KEY_TYPE_RSA
Definition hsm_key.h:61
HSM_KEY_KEY_TYPE_INVALID
@ HSM_KEY_KEY_TYPE_INVALID
Definition hsm_key.h:60
policy_list_free
void policy_list_free(policy_list_t *policy_list)
Definition policy.c:2664
policy_list_begin
const policy_t * policy_list_begin(policy_list_t *policy_list)
Definition policy.c:3158
policy_list_next
const policy_t * policy_list_next(policy_list_t *policy_list)
Definition policy.c:3214
policy_new_copy
policy_t * policy_new_copy(const policy_t *policy)
Definition policy.c:499
policy_list_new_copy
policy_list_t * policy_list_new_copy(const policy_list_t *from_policy_list)
Definition policy.c:2635
policy_id
const db_value_t * policy_id(const policy_t *policy)
Definition policy.c:805
policy_list_new
policy_list_t * policy_list_new(const db_connection_t *connection)
Definition policy.c:2621
policy_list_object_store
int policy_list_object_store(policy_list_t *policy_list)
Definition policy.c:2654
policy_list_get_by_clauses
int policy_list_get_by_clauses(policy_list_t *policy_list, const db_clause_list_t *clause_list)
Definition policy.c:3096
policy_free
void policy_free(policy_t *policy)
Definition policy.c:518
db_clause_list
Definition db_clause.h:226
db_clause
Definition db_clause.h:118
db_connection
Definition db_connection.h:46
db_enum
Definition db_enum.h:38
db_object_field_list
Definition db_object.h:142
db_object_field
Definition db_object.h:52
db_object
Definition db_object.h:201
db_result_list
Definition db_result.h:114
db_result
Definition db_result.h:56
db_value_set
Definition db_value.h:281
db_value
Definition db_value.h:48
hsm_key_list
Definition hsm_key.h:436
hsm_key_list::object_list_position
size_t object_list_position
Definition hsm_key.h:444
hsm_key_list::object_store
int object_store
Definition hsm_key.h:441
hsm_key_list::associated_fetch
int associated_fetch
Definition hsm_key.h:446
hsm_key_list::hsm_key
hsm_key_t * hsm_key
Definition hsm_key.h:440
hsm_key_list::policy_id_list
policy_list_t * policy_id_list
Definition hsm_key.h:447
hsm_key_list::result_list
db_result_list_t * result_list
Definition hsm_key.h:438
hsm_key_list::object_list
hsm_key_t ** object_list
Definition hsm_key.h:442
hsm_key_list::object_list_first
int object_list_first
Definition hsm_key.h:445
hsm_key_list::object_list_size
size_t object_list_size
Definition hsm_key.h:443
hsm_key_list::dbo
db_object_t * dbo
Definition hsm_key.h:437
hsm_key
Definition hsm_key.h:79
hsm_key::backup
hsm_key_backup_t backup
Definition hsm_key.h:95
hsm_key::state
hsm_key_state_t state
Definition hsm_key.h:87
hsm_key::associated_policy_id
const policy_t * associated_policy_id
Definition hsm_key.h:84
hsm_key::inception
unsigned int inception
Definition hsm_key.h:91
hsm_key::key_type
hsm_key_key_type_t key_type
Definition hsm_key.h:93
hsm_key::locator
char * locator
Definition hsm_key.h:86
hsm_key::policy_id
db_value_t policy_id
Definition hsm_key.h:83
hsm_key::rev
db_value_t rev
Definition hsm_key.h:82
hsm_key::bits
unsigned int bits
Definition hsm_key.h:88
hsm_key::repository
char * repository
Definition hsm_key.h:94
hsm_key::private_policy_id
policy_t * private_policy_id
Definition hsm_key.h:85
hsm_key::id
db_value_t id
Definition hsm_key.h:81
hsm_key::dbo
db_object_t * dbo
Definition hsm_key.h:80
hsm_key::is_revoked
unsigned int is_revoked
Definition hsm_key.h:92
hsm_key::role
hsm_key_role_t role
Definition hsm_key.h:90
hsm_key::algorithm
unsigned int algorithm
Definition hsm_key.h:89
policy
Definition policy.h:60