ldnssec-utils/util.c
2021-12-10 22:41:31 +00:00

67 lines
1.5 KiB
C

/*
* ldnssec-utils
*
* Written in 2021 by Lucas
*
* To the extent possible under law, the author(s) have dedicated all
* copyright and related and neighboring rights to this software to the
* public domain worldwide. This software is distributed without any
* warranty.
*
* You should have received a copy of the CC0 Public Domain Dedication
* along with this software. If not, see
* <http://creativecommons.org/publicdomain/zero/1.0/>.
*/
#include <err.h>
#include <ldns/ldns.h>
#include "util.h"
#define MINIMUM_LDNS_VERSION "1.7.1"
#define MINIMUM_LDNS_REVISION ((1<<16)|(7<<8)|(1))
ldns_lookup_table ldnssec_hashes[] = {
{ LDNS_SHA1, "SHA1" },
{ LDNS_SHA256, "SHA256" },
{ LDNS_HASH_GOST, "GOST" },
{ LDNS_SHA384, "SHA384" },
{ 0, NULL },
};
ldns_hash
ldnssec_get_hash_algorithm_by_name(const char *name)
{
static ldns_lookup_table aliases[] = {
{ LDNS_SHA1, "SHA-1" },
{ LDNS_SHA256, "SHA-256" },
{ LDNS_SHA384, "SHA-384" },
{ 0, NULL },
};
ldns_lookup_table *lt;
const char *errstr;
long long n;
lt = ldns_lookup_by_name(ldnssec_hashes, name);
if (lt != NULL)
return lt->id;
lt = ldns_lookup_by_name(aliases, name);
if (lt != NULL)
return lt->id;
n = strtonum(name, 0, UINT8_MAX, &errstr);
if (errstr == NULL)
return n;
return 0;
}
void
fatal_check_minimum_ldns_revision(void)
{
if (MINIMUM_LDNS_REVISION > LDNS_REVISION)
errx(1, "ldns version should be greater or equal than "
MINIMUM_LDNS_VERSION "; got %s instead\n", ldns_version());
}