Commit 68352fc9 authored by Filip Široký's avatar Filip Široký Committed by Daniel Salzman

doxygen: fix errors + code cleanup

parent d7f3adc4
/* Copyright (C) 2014 Farsight Security, Inc. <software@farsightsecurity.com>
/* Copyright (C) 2017 Farsight Security, Inc. <software@farsightsecurity.com>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -58,8 +58,8 @@ void dt_reader_free(dt_reader_t *reader);
* Caller must deallocate the returned protobuf with the
* dnstap__dnstap__free_unpacked() function.
*
* \param reader dnstap file reader structure.
* \param d[out] Unpacked dnstap protobuf.
* \param[in] reader dnstap file reader structure.
* \param[out] d Unpacked dnstap protobuf.
*
* \retval KNOT_EOK
* \retval KNOT_ERROR
......
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -22,7 +22,7 @@
#include "libknot/mm_ctx.h"
/*!
* \file \brief Native API of QP-tries:
* \brief Native API of QP-tries:
*
* - keys are char strings, not necessarily zero-terminated,
* the structure copies the contents of the passed keys
......@@ -60,7 +60,10 @@ trie_val_t* trie_get_ins(trie_t *tbl, const char *key, uint32_t len);
/*!
* \brief Search for less-or-equal element.
*
* \param val must be valid; it will be set to NULL if not found or errored.
* \param tbl Trie.
* \param key Searched key.
* \param len Key length.
* \param val Must be valid; it will be set to NULL if not found or errored.
* \return KNOT_EOK for exact match, 1 for previous, KNOT_ENOENT for not-found,
* or KNOT_E*.
*/
......
/* Copyright (C) 2016 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -92,7 +92,7 @@ int sockaddr_set_raw(struct sockaddr_storage *ss, int family,
/*!
* \brief Return string representation of socket address.
*
* \note String format: <address>[@<port>], f.e. '127.0.0.1@53'
* \note String format: \<address>[@<port>], f.e. '127.0.0.1@53'
*
* \param buf Destination for string representation.
* \param maxlen Maximum number of written bytes.
......
......@@ -139,18 +139,18 @@ inline static knot_time_t knot_time_from_u32(uint32_t u32time)
* \param time The parsed timestamp.
*
* The format specification basics:
* <format 1>|<format2> - The pipe sign separates two time format specifications. Leftmost
* specification matching the timespec is used.
* '<a string>' - Matches exactly <a string> (not containing apostrophes) in timespec.
* # - Hashtag matches for a number in timespec, stands for either a UNIX timestamp,
* or, within a context of an unit, as a number of such units.
* Y, M, D, h, m, s - Matches a number, stands for a number of years, months, days, hours,
* minutes and seconds, respectively.
* +, - - The + and - signs declaring that following timespec is relative to "now".
* A single sign can be used to limit the timestamp being in future or in past,
* or both +- allow the timestamp to select any (just one) of them.
* U - Matches one of Y, M, D, h, m, s in the timespec standing for a time unit.
* u - Like U, but the unit in the timestamp is from: y, mo, d, h, mi, s.
* <format 1>|<format 2> - The pipe sign separates two time format specifications. Leftmost
* specification matching the timespec is used.
* '<a string>' - Matches exactly <a string> (not containing apostrophes) in timespec.
* # - Hashtag matches for a number in timespec, stands for either a UNIX timestamp,
* or, within a context of an unit, as a number of such units.
* Y, M, D, h, m, s - Matches a number, stands for a number of years, months, days, hours,
* minutes and seconds, respectively.
* +, - - The + and - signs declaring that following timespec is relative to "now".
* A single sign can be used to limit the timestamp being in future or in past,
* or both +- allow the timestamp to select any (just one) of them.
* U - Matches one of Y, M, D, h, m, s in the timespec standing for a time unit.
* u - Like U, but the unit in the timestamp is from: y, mo, d, h, mi, s.
*
* \retval -1 An error occured, out_time has no sense.
* \return 0 OK, timestamp parsed successfully.
......
......@@ -16,8 +16,8 @@
***/
/**
* Find the first element not lower than @x in the sorted array @ary of @N elements (non-decreasing order).
* Returns the index of the found element or @N if no exists. Uses `ary_lt_x(ary,i,x)` to compare the @i'th element with @x.
* Find the first element not lower than \p x in the sorted array \p ary of \p N elements (non-decreasing order).
* Returns the index of the found element or \p N if no exists. Uses `ary_lt_x(ary,i,x)` to compare the i'th element with \p x.
* The time complexity is `O(log(N))`.
**/
#define BIN_SEARCH_FIRST_GE_CMP(ary, N, ary_lt_x, x, ...) ({ \
......@@ -34,17 +34,17 @@
})
/**
* The default comparison macro for @BIN_SEARCH_FIRST_GE_CMP().
* The default comparison macro for \ref BIN_SEARCH_FIRST_GE_CMP().
**/
#define ARY_LT_NUM(ary,i,x) (ary)[i] < (x)
/**
* Same as @BIN_SEARCH_FIRST_GE_CMP(), but uses the default `<` operator for comparisons.
* Same as \ref BIN_SEARCH_FIRST_GE_CMP(), but uses the default `<` operator for comparisons.
**/
#define BIN_SEARCH_FIRST_GE(ary,N,x) BIN_SEARCH_FIRST_GE_CMP(ary,N,ARY_LT_NUM,x)
/**
* Search the sorted array @ary of @N elements (non-decreasing) for the first occurrence of @x.
* Search the sorted array \p ary of \p N elements (non-decreasing) for the first occurrence of \p x.
* Returns the index or -1 if no such element exists. Uses the `<` operator for comparisons.
**/
#define BIN_SEARCH_EQ(ary,N,x) ({ int i = BIN_SEARCH_FIRST_GE(ary,N,x); if (i >= (N) || (ary)[i] != (x)) i=-1; i; })
......@@ -2,6 +2,7 @@
* BIRD Library -- Linked Lists
*
* (c) 1998 Martin Mares <mj@ucw.cz>
* (c) 2015, 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
......@@ -31,10 +32,10 @@
/**
* add_tail - append a node to a list
* @l: linked list
* @n: list node
* \p l: linked list
* \p n: list node
*
* add_tail() takes a node @n and appends it at the end of the list @l.
* add_tail() takes a node \p n and appends it at the end of the list \p l.
*/
void
add_tail(list_t *l, node_t *n)
......@@ -49,10 +50,10 @@ add_tail(list_t *l, node_t *n)
/**
* add_head - prepend a node to a list
* @l: linked list
* @n: list node
* \p l: linked list
* \p n: list node
*
* add_head() takes a node @n and prepends it at the start of the list @l.
* add_head() takes a node \p n and prepends it at the start of the list \p l.
*/
void
add_head(list_t *l, node_t *n)
......@@ -67,11 +68,11 @@ add_head(list_t *l, node_t *n)
/**
* insert_node - insert a node to a list
* @n: a new list node
* @after: a node of a list
* \p n: a new list node
* \p after: a node of a list
*
* Inserts a node @n to a linked list after an already inserted
* node @after.
* Inserts a node \p n to a linked list after an already inserted
* node \p after.
*/
void
insert_node(node_t *n, node_t *after)
......@@ -86,9 +87,9 @@ insert_node(node_t *n, node_t *after)
/**
* rem_node - remove a node from a list
* @n: node to be removed
* \p n: node to be removed
*
* Removes a node @n from the list it's linked in.
* Removes a node \p n from the list it's linked in.
*/
void
rem_node(node_t *n)
......@@ -104,7 +105,7 @@ rem_node(node_t *n)
/**
* init_list - create an empty list
* @l: list
* \p l: list
*
* init_list() takes a &list structure and initializes its
* fields, so that it represents an empty list.
......@@ -119,11 +120,11 @@ init_list(list_t *l)
/**
* add_tail_list - concatenate two lists
* @to: destination list
* @l: source list
* \p to: destination list
* \p l: source list
*
* This function appends all elements of the list @l to
* the list @to in constant time.
* This function appends all elements of the list \p l to
* the list \p to in constant time.
*/
void
add_tail_list(list_t *to, list_t *l)
......@@ -140,11 +141,11 @@ add_tail_list(list_t *to, list_t *l)
/**
* list_dup - duplicate list
* @to: destination list
* @l: source list
* \p to: destination list
* \p l: source list
*
* This function duplicates all elements of the list @l to
* the list @to in linear time.
* This function duplicates all elements of the list \p l to
* the list \p to in linear time.
*
* This function only works with a homogenous item size.
*/
......@@ -160,9 +161,9 @@ void list_dup(list_t *dst, list_t *src, size_t itemsz)
/**
* list_size - gets number of nodes
* @l: list
* \p l: list
*
* This function counts nodes in list @l and returns this number.
* This function counts nodes in list \p l and returns this number.
*/
size_t list_size(const list_t *l)
{
......@@ -178,9 +179,9 @@ size_t list_size(const list_t *l)
/**
* ptrlist_add - add pointer to pointer list
* @to: destination list
* @val: added pointer
* @mm: memory context
* \p to: destination list
* \p val: added pointer
* \p mm: memory context
*/
ptrnode_t *ptrlist_add(list_t *to, void *val, knot_mm_t *mm)
{
......@@ -196,8 +197,8 @@ ptrnode_t *ptrlist_add(list_t *to, void *val, knot_mm_t *mm)
/**
* ptrlist_free - free all nodes in pointer list
* @list: list nodes
* @mm: memory context
* \p list: list nodes
* \p mm: memory context
*/
void ptrlist_free(list_t *list, knot_mm_t *mm)
{
......@@ -210,8 +211,8 @@ void ptrlist_free(list_t *list, knot_mm_t *mm)
/**
* ptrlist_rem - remove pointer node
* @val: pointer to remove
* @mm: memory context
* \p val: pointer to remove
* \p mm: memory context
*/
void ptrlist_rem(ptrnode_t *node, knot_mm_t *mm)
{
......@@ -221,8 +222,8 @@ void ptrlist_rem(ptrnode_t *node, knot_mm_t *mm)
/**
* ptrlist_deep_free - free all nodes incl referenced data
* @list: list nodes
* @mm: memory context
* \p list: list nodes
* \p mm: memory context
*/
void ptrlist_deep_free(list_t *l, knot_mm_t *mm)
{
......
......@@ -2,6 +2,7 @@
* BIRD Library -- Linked Lists
*
* (c) 1998 Martin Mares <mj@ucw.cz>
* (c) 2015, 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
*
* Can be freely distributed and used under the terms of the GNU GPL.
*/
......
......@@ -22,7 +22,7 @@
/** \todo This shouldn't be precalculated, but computed on load. */
#define CPU_PAGE_SIZE 4096
/** Align an integer @s to the nearest higher multiple of @a (which should be a power of two) **/
/** Align an integer \p s to the nearest higher multiple of \p a (which should be a power of two) **/
#define ALIGN_TO(s, a) (((s)+a-1)&~(a-1))
#define MP_CHUNK_TAIL ALIGN_TO(sizeof(struct mempool_chunk), CPU_STRUCT_ALIGN)
#define MP_SIZE_MAX (~0U - MP_CHUNK_TAIL - CPU_PAGE_SIZE)
......
......@@ -23,7 +23,7 @@
***/
/**
* Memory pool state (see @mp_push(), ...).
* Memory pool state (see mp_push(), ...).
* You should use this one as an opaque handle only, the insides are internal.
**/
struct mempool_state {
......@@ -41,7 +41,7 @@ struct mempool {
unsigned chunk_size, threshold, idx;
};
struct mempool_stats { /** Mempool statistics. See @mp_stats(). **/
struct mempool_stats { /** Mempool statistics. See mp_stats(). **/
uint64_t total_size; /** Real allocated size in bytes. */
unsigned chain_count[3]; /** Number of allocated chunks in small/big/unused chains. */
unsigned chain_size[3]; /** Size of allocated chunks in small/big/unused chains. */
......@@ -55,7 +55,7 @@ struct mempool_stats { /** Mempool statistics. See @mp_stats(). **/
/**
* Initialize a given mempool structure.
* @chunk_size must be in the interval `[1, UINT_MAX / 2]`.
* \p chunk_size must be in the interval `[1, UINT_MAX / 2]`.
* It will allocate memory by this large chunks and take
* memory to satisfy requests from them.
*
......@@ -65,7 +65,7 @@ void mp_init(struct mempool *pool, unsigned chunk_size);
/**
* Allocate and initialize a new memory pool.
* See @mp_init() for @chunk_size limitations.
* See \ref mp_init() for \p chunk_size limitations.
*
* The new mempool structure is allocated on the new mempool.
*
......@@ -76,15 +76,15 @@ struct mempool *mp_new(unsigned chunk_size);
/**
* Cleanup mempool initialized by mp_init or mp_new.
* Frees all the memory allocated by this mempool and,
* if created by @mp_new(), the @pool itself.
* if created by \ref mp_new(), the \p pool itself.
**/
void mp_delete(struct mempool *pool);
/**
* Frees all data on a memory pool, but leaves it working.
* It can keep some of the chunks allocated to serve
* further allocation requests. Leaves the @pool alive,
* even if it was created with @mp_new().
* further allocation requests. Leaves the \p pool alive,
* even if it was created with \ref mp_new().
**/
void mp_flush(struct mempool *pool);
......@@ -102,8 +102,8 @@ uint64_t mp_total_size(struct mempool *pool); /** How many bytes were allocated
***/
/**
* The function allocates new @size bytes on a given memory pool.
* If the @size is zero, the resulting pointer is undefined,
* The function allocates new \p size bytes on a given memory pool.
* If the \p size is zero, the resulting pointer is undefined,
* but it may be safely reallocated or used as the parameter
* to other functions below.
*
......@@ -114,11 +114,11 @@ uint64_t mp_total_size(struct mempool *pool); /** How many bytes were allocated
void *mp_alloc(struct mempool *pool, unsigned size);
/**
* The same as @mp_alloc(), but the result may be unaligned.
* The same as \ref mp_alloc(), but the result may be unaligned.
**/
void *mp_alloc_noalign(struct mempool *pool, unsigned size);
/**
* The same as @mp_alloc(), but fills the newly allocated memory with zeroes.
* The same as \ref mp_alloc(), but fills the newly allocated memory with zeroes.
**/
void *mp_alloc_zero(struct mempool *pool, unsigned size);
......@@ -22,7 +22,7 @@
*
* DNSSEC public and private key manipulation.
*
* The \ref dnssec_key_t is an abstraction for a DNSSEC key pair. If the key
* The dnssec_key_t is an abstraction for a DNSSEC key pair. If the key
* key is initialized with a public key data only, it can be used only for
* signature verification. In order to use the key for signing, private key
* has to be loaded. If only a private key is loaded into the structure,
......
......@@ -34,7 +34,7 @@ static inline void clist_init(clist *l)
}
/**
* Return the first node on @l or NULL if @l is empty.
* Return the first node on \p l or NULL if \p l is empty.
**/
static inline void *clist_head(clist *l)
{
......@@ -42,7 +42,7 @@ static inline void *clist_head(clist *l)
}
/**
* Return the last node on @l or NULL if @l is empty.
* Return the last node on \p l or NULL if \p l is empty.
**/
static inline void *clist_tail(clist *l)
{
......@@ -50,7 +50,7 @@ static inline void *clist_tail(clist *l)
}
/**
* Find the next node to @n or NULL if @n is the last one.
* Find the next node to \p n or NULL if \p n is the last one.
**/
static inline void *clist_next(clist *l, cnode *n)
{
......@@ -58,7 +58,7 @@ static inline void *clist_next(clist *l, cnode *n)
}
/**
* Find the previous node to @n or NULL if @n is the first one.
* Find the previous node to \p n or NULL if \p n is the first one.
**/
static inline void *clist_prev(clist *l, cnode *n)
{
......@@ -66,7 +66,7 @@ static inline void *clist_prev(clist *l, cnode *n)
}
/**
* Return a non-zero value iff @l is empty.
* Return a non-zero value iff \p l is empty.
**/
static inline int clist_empty(clist *l)
{
......@@ -74,33 +74,33 @@ static inline int clist_empty(clist *l)
}
/**
* Loop over all nodes in the @list and perform the next C statement on them. The current node is stored in @n which must be defined before as pointer to any type.
* Loop over all nodes in the \ref list and perform the next C statement on them. The current node is stored in \p n which must be defined before as pointer to any type.
* The list should not be changed during this loop command.
**/
#define CLIST_WALK(n,list) for(n=(void*)(list).head.next; (cnode*)(n) != &(list).head; n=(void*)((cnode*)(n))->next)
/**
* Same as @CLIST_WALK(), but allows removal of the current node. This macro requires one more variable to store some temporary pointers.
* Same as \ref CLIST_WALK(), but allows removal of the current node. This macro requires one more variable to store some temporary pointers.
**/
#define CLIST_WALK_DELSAFE(n,list,tmp) for(n=(void*)(list).head.next; tmp=(void*)((cnode*)(n))->next, (cnode*)(n) != &(list).head; n=(void*)tmp)
/**
* Same as @CLIST_WALK(), but it defines the variable for the current node in place. @type should be a pointer type.
* Same as \ref CLIST_WALK(), but it defines the variable for the current node in place. \p type should be a pointer type.
**/
#define CLIST_FOR_EACH(type,n,list) for(type n=(void*)(list).head.next; (cnode*)(n) != &(list).head; n=(void*)((cnode*)(n))->next)
/**
* Same as @CLIST_WALK_DELSAFE(), but it defines the variable for the current node in place. @type should be a pointer type. The temporary variable must be still known before.
* Same as \ref CLIST_WALK_DELSAFE(), but it defines the variable for the current node in place. \p type should be a pointer type. The temporary variable must be still known before.
**/
#define CLIST_FOR_EACH_DELSAFE(type,n,list,tmp) for(type n=(void*)(list).head.next; tmp=(void*)((cnode*)(n))->next, (cnode*)(n) != &(list).head; n=(void*)tmp)
/**
* Reversed version of @CLIST_FOR_EACH().
* Reversed version of \ref CLIST_FOR_EACH().
**/
#define CLIST_FOR_EACH_BACKWARDS(type,n,list) for(type n=(void*)(list).head.prev; (cnode*)(n) != &(list).head; n=(void*)((cnode*)(n))->prev)
/**
* Insert a new node just after the node @after. To insert at the head of the list, use @clist_add_head() instead.
* Insert a new node just after the node \p after. To insert at the head of the list, use \ref clist_add_head() instead.
**/
static inline void clist_insert_after(cnode *what, cnode *after)
{
......@@ -112,7 +112,7 @@ static inline void clist_insert_after(cnode *what, cnode *after)
}
/**
* Insert a new node just before the node @before. To insert at the tail of the list, use @clist_add_tail() instead.
* Insert a new node just before the node \p before. To insert at the tail of the list, use \ref clist_add_tail() instead.
**/
static inline void clist_insert_before(cnode *what, cnode *before)
{
......@@ -140,7 +140,7 @@ static inline void clist_add_tail(clist *l, cnode *n)
}
/**
* Remove node @n.
* Remove node \p n.
**/
static inline void clist_remove(cnode *n)
{
......@@ -151,7 +151,7 @@ static inline void clist_remove(cnode *n)
}
/**
* Remove the first node in @l, if it exists. Return the pointer to that node or NULL.
* Remove the first node in \p l, if it exists. Return the pointer to that node or NULL.
**/
static inline void *clist_remove_head(clist *l)
{
......@@ -162,7 +162,7 @@ static inline void *clist_remove_head(clist *l)
}
/**
* Remove the last node in @l, if it exists. Return the pointer to that node or NULL.
* Remove the last node in \p l, if it exists. Return the pointer to that node or NULL.
**/
static inline void *clist_remove_tail(clist *l)
{
......@@ -173,7 +173,7 @@ static inline void *clist_remove_tail(clist *l)
}
/**
* Merge two lists by inserting the list @what just after the node @after in a different list.
* Merge two lists by inserting the list \p what just after the node \p after in a different list.
* The first list is then cleared.
**/
static inline void clist_insert_list_after(clist *what, cnode *after)
......@@ -201,7 +201,7 @@ static inline void clist_move(clist *to, clist *from)
}
/**
* Compute the number of nodes in @l. Beware of linear time complexity.
* Compute the number of nodes in \p l. Beware of linear time complexity.
**/
static inline unsigned int clist_size(clist *l)
{
......@@ -212,7 +212,7 @@ static inline unsigned int clist_size(clist *l)
}
/**
* Remove a node @n and mark it as unlinked by setting the previous and next pointers to NULL.
* Remove a node \p n and mark it as unlinked by setting the previous and next pointers to NULL.
**/
static inline void clist_unlink(cnode *n)
{
......@@ -221,7 +221,7 @@ static inline void clist_unlink(cnode *n)
}
/**
* Remove the first node on @l and mark it as unlinked.
* Remove the first node on \p l and mark it as unlinked.
* Return the pointer to that node or NULL.
**/
static inline void *clist_unlink_head(clist *l)
......@@ -233,7 +233,7 @@ static inline void *clist_unlink_head(clist *l)
}
/**
* Remove the last node on @l and mark it as unlinked.
* Remove the last node on \p l and mark it as unlinked.
* Return the pointer to that node or NULL.
**/
static inline void *clist_unlink_tail(clist *l)
......@@ -249,8 +249,8 @@ static inline void *clist_unlink_tail(clist *l)
* previous and next pointers equal to NULL. Returns 0 or 1.
*
* Nodes initialized to all zeroes are unlinked, inserting a node anywhere in a list
* makes it linked. Normal removal functions like @clist_remove() do not mark nodes
* as unlinked, you need to call @clist_unlink() instead.
* makes it linked. Normal removal functions like \ref clist_remove() do not mark nodes
* as unlinked, you need to call \ref clist_unlink() instead.
**/
static inline int clist_is_linked(cnode *n)
{
......
/* Copyright (C) 2014 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -115,9 +115,9 @@ int dnssec_nsec3_hash(const dnssec_binary_t *data,
* Get length of raw NSEC3 hash for a given algorithm.
*/
_public_
size_t dnssec_nsec3_hash_length(dnssec_nsec3_algorithm_t dnssec)
size_t dnssec_nsec3_hash_length(dnssec_nsec3_algorithm_t algorithm)
{
gnutls_digest_algorithm_t gnutls = algorithm_d2g(dnssec);
gnutls_digest_algorithm_t gnutls = algorithm_d2g(algorithm);
if (gnutls == GNUTLS_DIG_UNKNOWN) {
return 0;
}
......
......@@ -188,9 +188,9 @@ int dss_sig_value_decode(const dnssec_binary_t *der,
* Encode signature parameters from X.509 ECDSA signature.
*/
int dss_sig_value_encode(const dnssec_binary_t *r, const dnssec_binary_t *s,
dnssec_binary_t *_der)
dnssec_binary_t *der)
{
if (!r || !r->data || !s || !s->data || !_der) {
if (!r || !r->data || !s || !s->data || !der) {
return DNSSEC_EINVAL;
}
......@@ -212,18 +212,18 @@ int dss_sig_value_encode(const dnssec_binary_t *r, const dnssec_binary_t *s,
size_t total_size = 2 + seq_size;
dnssec_binary_t der = { 0 };
if (dnssec_binary_alloc(&der, total_size)) {
dnssec_binary_t _der = { 0 };
if (dnssec_binary_alloc(&_der, total_size)) {
return DNSSEC_ENOMEM;
}
wire_ctx_t wire = wire_init_binary(&der);
wire_ctx_t wire = wire_init_binary(&_der);
asn1_write_header(&wire, ASN1_TYPE_SEQUENCE, seq_size);
asn1_write_integer(&wire, r_size, r);
asn1_write_integer(&wire, s_size, s);
assert(wire_available(&wire) == 0);
*_der = der;
*der = _der;
return DNSSEC_EOK;
}
/* Copyright (C) 2014 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
/* Copyright (C) 2017 CZ.NIC, z.s.p.o. <knot-dns@labs.nic.cz>
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
......@@ -32,15 +32,15 @@
/*!
* Create GnuTLS X.509 private key from unencrypted PEM data.
*/
int pem_x509(const dnssec_binary_t *data, gnutls_x509_privkey_t *key_ptr)
int pem_x509(const dnssec_binary_t *pem, gnutls_x509_privkey_t *key)
{
assert(data);
assert(key_ptr);
assert(pem);
assert(key);
gnutls_datum_t pem = binary_to_datum(data);
gnutls_datum_t data = binary_to_datum(pem);
gnutls_x509_privkey_t key = NULL;
int r = gnutls_x509_privkey_init(&key);
gnutls_x509_privkey_t _key = NULL;
int r = gnutls_x509_privkey_init(&_key);
if (r != GNUTLS_E_SUCCESS) {
return DNSSEC_ENOMEM;
}
......@@ -48,13 +48,13 @@ int pem_x509(const dnssec_binary_t *data, gnutls_x509_privkey_t *key_ptr)
int format = GNUTLS_X509_FMT_PEM;
char *password = NULL;
int flags = GNUTLS_PKCS_PLAIN;
r = gnutls_x509_privkey_import_pkcs8(key, &pem, format, password, flags);
r = gnutls_x509_privkey_import_pkcs8(_key, &data, format, password, flags);
if (r != GNUTLS_E_SUCCESS) {
gnutls_x509_privkey_deinit(key);
gnutls_x509_privkey_deinit(_key);
return DNSSEC_PKCS8_IMPORT_ERROR;
}
*key_ptr = key;
*key = _key;
return DNSSEC_EOK;
}
......@@ -62,13 +62,13 @@ int pem_x509(const dnssec_binary_t *data, gnutls_x509_privkey_t *key_ptr)
/*!
* Create GnuTLS private key from unencrypted PEM data.
*/
int pem_privkey(const dnssec_binary_t *data, gnutls_privkey_t *key)
int pem_privkey(const dnssec_binary_t *pem, gnutls_privkey_t *key)
{
assert(data);
assert(pem);
assert(key);
gnutls_x509_privkey_t key_x509 = NULL;
int r = pem_x509(data, &key_x509);
int r = pem_x509(pem, &key_x509);
if (r != DNSSEC_EOK) {
return r;
}
......@@ -97,10 +97,10 @@ int pem_privkey(const dnssec_binary_t *data, gnutls_privkey_t *key)
* Generate new key and export it in the PEM format.
*/
int pem_generate(gnutls_pk_algorithm_t algorithm, unsigned bits,
dnssec_binary_t *pem_ptr, char **id_ptr)
dnssec_binary_t *pem, char **id)
{
assert(pem_ptr);
assert(id_ptr);
assert(pem);
assert(id);
// generate key
......@@ -117,23 +117,23 @@ int pem_generate(gnutls_pk_algorithm_t algorithm, unsigned bits,
// convert to PEM and export the ID
dnssec_binary_t pem = { 0 };
r = pem_from_x509(key, &pem);
dnssec_binary_t _pem = { 0 };
r = pem_from_x509(key, &_pem);
if (r != DNSSEC_EOK) {
return r;
}
// export key ID
char *id = NULL;
r = keyid_x509_hex(key, &id);
char *_id = NULL;
r = keyid_x509_hex(key, &_id);
if (r != DNSSEC_EOK) {
dnssec_binary_free(&pem);
dnssec_binary_free(&_pem);
return r;
}
*id_ptr = id;
*pem_ptr = pem;
*id = _id;
*pem = _pem;
return DNSSEC_EOK;
}
......@@ -153,29 +153,29 @@ static int try_export_pem(gnutls_x509_privkey_t key, dnssec_binary_t *pem)
/*!
* Export GnuTLS X.509 private key to PEM binary.
*/
int pem_from_x509(gnutls_x509_privkey_t key, dnssec_binary_t *pem_ptr)
int pem_from_x509(gnutls_x509_privkey_t key, dnssec_binary_t *pem)
{
assert(key);
assert(pem_ptr);
assert(pem);
dnssec_binary_t pem = { 0 };
int r = try_export_pem(key, &pem);
if (r != GNUTLS_E_SHORT_MEMORY_BUFFER || pem.size == 0) {
dnssec_binary_t _pem = { 0 };
int r = try_export_pem(key, &_pem);
if (r != GNUTLS_E_SHORT_MEMORY_BUFFER || _pem.size == 0) {
return DNSSEC_KEY_EXPORT_ERROR;
}
r = dnssec_binary_alloc(&pem, pem.size);
r = dnssec_binary_alloc(&_pem, _pem.size);
if (r != DNSSEC_EOK) {
return r;
}
r = try_export_pem(key, &pem);
r = try_export_pem(key, &_pem);
if (r != GNUTLS_E_SUCCESS) {
dnssec_binary_free(&pem);
dnssec_binary_free(&_pem);