From 3d223e0338f28156fd0a150fecab031afd43fc92 Mon Sep 17 00:00:00 2001 From: Mark Andrews Date: Fri, 16 Sep 2022 00:42:15 +1000 Subject: [PATCH] Replace alg_totext with dst_hmac_algorithm_totext The new library function will be reused by subsequent commits. (cherry picked from commit 151cc2fff99efe11e284ce3ae0796523ce1975e5) --- bin/confgen/keygen.c | 25 +------------------------ bin/confgen/rndc-confgen.c | 2 +- bin/confgen/tsig-keygen.c | 2 +- lib/dns/dst_api.c | 20 ++++++++++++++++++++ lib/dns/include/dst/dst.h | 7 +++++++ 5 files changed, 30 insertions(+), 26 deletions(-) diff --git a/bin/confgen/keygen.c b/bin/confgen/keygen.c index 345933d374..97dfa34667 100644 --- a/bin/confgen/keygen.c +++ b/bin/confgen/keygen.c @@ -34,29 +34,6 @@ #include "util.h" -/*% - * Convert algorithm type to string. - */ -const char * -alg_totext(dns_secalg_t alg) { - switch (alg) { - case DST_ALG_HMACMD5: - return ("hmac-md5"); - case DST_ALG_HMACSHA1: - return ("hmac-sha1"); - case DST_ALG_HMACSHA224: - return ("hmac-sha224"); - case DST_ALG_HMACSHA256: - return ("hmac-sha256"); - case DST_ALG_HMACSHA384: - return ("hmac-sha384"); - case DST_ALG_HMACSHA512: - return ("hmac-sha512"); - default: - return ("(unknown)"); - } -} - /*% * Convert string to algorithm type. */ @@ -175,7 +152,7 @@ void write_key_file(const char *keyfile, const char *user, const char *keyname, isc_buffer_t *secret, dns_secalg_t alg) { isc_result_t result; - const char *algname = alg_totext(alg); + const char *algname = dst_hmac_algorithm_totext(alg); FILE *fd = NULL; DO("create keyfile", isc_file_safecreate(keyfile, &fd)); diff --git a/bin/confgen/rndc-confgen.c b/bin/confgen/rndc-confgen.c index e0786be782..817929544e 100644 --- a/bin/confgen/rndc-confgen.c +++ b/bin/confgen/rndc-confgen.c @@ -222,7 +222,7 @@ main(int argc, char **argv) { if (keysize < 0) { keysize = alg_bits(alg); } - algname = alg_totext(alg); + algname = dst_hmac_algorithm_totext(alg); isc_mem_create(&mctx); isc_buffer_init(&key_txtbuffer, &key_txtsecret, sizeof(key_txtsecret)); diff --git a/bin/confgen/tsig-keygen.c b/bin/confgen/tsig-keygen.c index dd39ad8726..f6c5b2e272 100644 --- a/bin/confgen/tsig-keygen.c +++ b/bin/confgen/tsig-keygen.c @@ -208,7 +208,7 @@ main(int argc, char **argv) { } /* Use canonical algorithm name */ - algname = alg_totext(alg); + algname = dst_hmac_algorithm_totext(alg); isc_mem_create(&mctx); diff --git a/lib/dns/dst_api.c b/lib/dns/dst_api.c index 39fcbf1fa6..c13463ffd1 100644 --- a/lib/dns/dst_api.c +++ b/lib/dns/dst_api.c @@ -2747,3 +2747,23 @@ dst_key_copy_metadata(dst_key_t *to, dst_key_t *from) { dst_key_setmodified(to, dst_key_ismodified(from)); } + +const char * +dst_hmac_algorithm_totext(dst_algorithm_t alg) { + switch (alg) { + case DST_ALG_HMACMD5: + return ("hmac-md5"); + case DST_ALG_HMACSHA1: + return ("hmac-sha1"); + case DST_ALG_HMACSHA224: + return ("hmac-sha224"); + case DST_ALG_HMACSHA256: + return ("hmac-sha256"); + case DST_ALG_HMACSHA384: + return ("hmac-sha384"); + case DST_ALG_HMACSHA512: + return ("hmac-sha512"); + default: + return ("unknown"); + } +} diff --git a/lib/dns/include/dst/dst.h b/lib/dns/include/dst/dst.h index 4e2437e11e..62192a9be7 100644 --- a/lib/dns/include/dst/dst.h +++ b/lib/dns/include/dst/dst.h @@ -1225,4 +1225,11 @@ dst_key_copy_metadata(dst_key_t *to, dst_key_t *from); * 'to' and 'from' to be valid. */ +const char * +dst_hmac_algorithm_totext(dst_algorithm_t alg); +/*$< + * Return the name associtated with the HMAC algorithm 'alg' + * or return "unknown". + */ + ISC_LANG_ENDDECLS