hsm_key_ext.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"
char const *
hsm_key_to_backup_state(hsm_key_t const *hsm_key) {
int i;
for (i = 0; hsm_key_enum_set_backup[i].text; i++) {
if (hsm_key_enum_set_backup[i].value == hsm_key_backup(hsm_key))
return hsm_key_enum_set_backup[i].text;
}
return NULL;
}
hsm_key_list_t* hsm_key_list_new_get_by_policy_key(const policy_key_t *pkey)
{
hsm_key_list_t* hkey_list = NULL;
db_clause_list_t* clause_list;
db_clause_t* clause;
if (!pkey || !pkey->dbo || !(clause_list = db_clause_list_new()))
return NULL;
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_key_policy_id(pkey))
|| db_clause_list_add(clause_list, clause)
|| !(clause = db_clause_new())
|| db_clause_set_field(clause, "algorithm")
|| db_clause_set_type(clause, DB_CLAUSE_EQUAL)
|| db_value_from_uint32(db_clause_get_value(clause), policy_key_algorithm(pkey))
|| db_clause_list_add(clause_list, clause)
|| !(clause = db_clause_new())
|| db_clause_set_field(clause, "bits")
|| db_clause_set_type(clause, DB_CLAUSE_EQUAL)
|| db_value_from_uint32(db_clause_get_value(clause), policy_key_bits(pkey))
|| db_clause_list_add(clause_list, clause)
|| !(clause = db_clause_new())
|| db_clause_set_field(clause, "repository")
|| db_clause_set_type(clause, DB_CLAUSE_EQUAL)
|| db_value_from_text(db_clause_get_value(clause), policy_key_repository(pkey))
|| db_clause_list_add(clause_list, clause))
{
db_clause_free(clause);
db_clause_list_free(clause_list);
return NULL;
}
hkey_list = hsm_key_list_new_get_by_clauses(
db_object_connection(pkey->dbo), clause_list);
db_clause_list_free(clause_list);
return hkey_list;
}
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_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
DB_CLAUSE_EQUAL
Definition: db_clause.h:44
hsm_key_enum_set_backup
const db_enum_t hsm_key_enum_set_backup[]
Definition: hsm_key.c:56
db_clause_new
db_clause_t * db_clause_new(void)
Definition: db_clause.c:43
db_clause_list
Definition: db_clause.h:226
db_clause_set_type
int db_clause_set_type(db_clause_t *clause, db_clause_type_t type)
Definition: db_clause.c:130
db_value_from_text
int db_value_from_text(db_value_t *value, const char *from_text)
Definition: db_value.c:531
db_object_connection
const db_connection_t * db_object_connection(const db_object_t *object)
Definition: db_object.c:320
hsm_key
Definition: hsm_key.h:77
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
db_clause
Definition: db_clause.h:118
db_error.h
db_clause_list_add
int db_clause_list_add(db_clause_list_t *clause_list, db_clause_t *clause)
Definition: db_clause.c:226
policy_key_repository
const char * policy_key_repository(const policy_key_t *policy_key)
Definition: policy_key.c:534
hsm_key_list
Definition: hsm_key.h:434
policy_key
Definition: policy_key.h:54
db_clause_free
void db_clause_free(db_clause_t *clause)
Definition: db_clause.c:56
hsm_key_to_backup_state
char const * hsm_key_to_backup_state(hsm_key_t const *hsm_key)
Definition: hsm_key_ext.c:34
hsm_key_backup
hsm_key_backup
Definition: hsm_key.h:62
hsm_key_list_new_get_by_policy_key
hsm_key_list_t * hsm_key_list_new_get_by_policy_key(const policy_key_t *pkey)
Definition: hsm_key_ext.c:43
db_enum::text
const char * text
Definition: db_enum.h:39
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
policy_key::dbo
db_object_t * dbo
Definition: policy_key.h:55
policy_key_algorithm
unsigned int policy_key_algorithm(const policy_key_t *policy_key)
Definition: policy_key.c:510
hsm_key.h
policy_key_bits
unsigned int policy_key_bits(const policy_key_t *policy_key)
Definition: policy_key.c:518
policy_key_policy_id
const db_value_t * policy_key_policy_id(const policy_key_t *policy_key)
Definition: policy_key.c:478
db_clause_get_value
db_value_t * db_clause_get_value(db_clause_t *clause)
Definition: db_clause.c:187