Commit 1211c348 authored by Matthijs Mekking's avatar Matthijs Mekking 🏡

Add dst_key_copy_metadata function.

When updating DNSSEC keys we would like to be able to copy the
metadata from one key to another.
parent 29e6ec31
......@@ -2587,3 +2587,52 @@ dst_key_is_removed(dst_key_t *key, isc_stdtime_t now, isc_stdtime_t *remove)
return state_ok && time_ok;
}
void
dst_key_copy_metadata(dst_key_t *to, dst_key_t *from)
{
dst_key_state_t state;
isc_stdtime_t when;
uint32_t num;
bool yesno;
isc_result_t result;
REQUIRE(VALID_KEY(to));
REQUIRE(VALID_KEY(from));
for (int i = 0; i < DST_MAX_TIMES+1; i++) {
result = dst_key_gettime(from, i, &when);
if (result == ISC_R_SUCCESS) {
dst_key_settime(to, i, when);
} else {
dst_key_unsettime(to, i);
}
}
for (int i = 0; i < DST_MAX_NUMERIC+1; i++) {
result = dst_key_getnum(from, i, &num);
if (result == ISC_R_SUCCESS) {
dst_key_setnum(to, i, num);
} else {
dst_key_unsetnum(to, i);
}
}
for (int i = 0; i < DST_MAX_BOOLEAN+1; i++) {
result = dst_key_getbool(from, i, &yesno);
if (result == ISC_R_SUCCESS) {
dst_key_setbool(to, i, yesno);
} else {
dst_key_unsetnum(to, i);
}
}
for (int i = 0; i < DST_MAX_KEYSTATES+1; i++) {
result = dst_key_getstate(from, i, &state);
if (result == ISC_R_SUCCESS) {
dst_key_setstate(to, i, state);
} else {
dst_key_unsetstate(to, i);
}
}
}
......@@ -1166,6 +1166,16 @@ dst_key_is_removed(dst_key_t *key, isc_stdtime_t now, isc_stdtime_t *remove);
* 'key' to be valid.
*/
void
dst_key_copy_metadata(dst_key_t *to, dst_key_t *from);
/*%<
* Copy key metadata from one key to another.
*
* Requires:
* 'to' and 'from' to be valid.
*/
ISC_LANG_ENDDECLS
#endif /* DST_DST_H */
......@@ -1405,6 +1405,7 @@ dst_key_attach
dst_key_buildfilename
dst_key_buildinternal
dst_key_class
dst_key_copy_metadata
dst_key_compare
dst_key_computesecret
dst_key_dump
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment