]> git.ipfire.org Git - thirdparty/knot-dns.git/commitdiff
libknot: replace dnssec/shared/dname with libknot/dname
authorDaniel Salzman <daniel.salzman@nic.cz>
Sun, 19 Oct 2025 11:43:27 +0000 (13:43 +0200)
committerLibor Peltan <libor.peltan@nic.cz>
Fri, 24 Oct 2025 07:17:08 +0000 (09:17 +0200)
12 files changed:
Knot.files
src/libknot/Makefile.inc
src/libknot/dnssec/key/ds.c
src/libknot/dnssec/key/internal.h
src/libknot/dnssec/key/key.c
src/libknot/dnssec/shared/dname.c [deleted file]
src/libknot/dnssec/shared/dname.h [deleted file]
src/libknot/dnssec/tsig.c
tests/.gitignore
tests/Makefile.am
tests/libknot/test_dnssec_shared_dname.c [deleted file]
tests/libknot/test_dnssec_tsig.c

index 355f5947f78a23592c2328d1692cff16d1bbcbea..540603b748dfd35d77fc7e7da1a83390840c1f98 100644 (file)
@@ -481,8 +481,6 @@ src/libknot/dnssec/sample_keys.h
 src/libknot/dnssec/shared/bignum.c
 src/libknot/dnssec/shared/bignum.h
 src/libknot/dnssec/shared/binary_wire.h
-src/libknot/dnssec/shared/dname.c
-src/libknot/dnssec/shared/dname.h
 src/libknot/dnssec/shared/keyid_gnutls.c
 src/libknot/dnssec/shared/keyid_gnutls.h
 src/libknot/dnssec/shared/shared.h
@@ -736,7 +734,6 @@ tests/libknot/test_dnssec_nsec_bitmap.c
 tests/libknot/test_dnssec_nsec_hash.c
 tests/libknot/test_dnssec_random.c
 tests/libknot/test_dnssec_shared_bignum.c
-tests/libknot/test_dnssec_shared_dname.c
 tests/libknot/test_dnssec_sign.c
 tests/libknot/test_dnssec_sign_der.c
 tests/libknot/test_dnssec_tsig.c
index 86658080870ceb76b86c5ca9170ebdbf450afc8d..3ab5a8b1f293cf2d2886b3e0a9759fef7fd33a0a 100755 (executable)
@@ -129,8 +129,6 @@ libknot_la_SOURCES = \
        libknot/dnssec/shared/bignum.c          \
        libknot/dnssec/shared/bignum.h          \
        libknot/dnssec/shared/binary_wire.h     \
-       libknot/dnssec/shared/dname.c           \
-       libknot/dnssec/shared/dname.h           \
        libknot/dnssec/shared/keyid_gnutls.c    \
        libknot/dnssec/shared/keyid_gnutls.h    \
        libknot/dnssec/shared/shared.h          \
index 1098cf71b14cfbe5b90376bcb99007d710c93fff..098bbfa3f57b7c5fb408fc0e507222a49f6dda89 100644 (file)
@@ -3,11 +3,11 @@
  *  For more information, see <https://www.knot-dns.cz/>
  */
 
+#include "libknot/dname.h"
 #include "libknot/dnssec/binary.h"
 #include "libknot/dnssec/error.h"
 #include "libknot/dnssec/key.h"
 #include "libknot/dnssec/key/internal.h"
-#include "libknot/dnssec/shared/dname.h"
 #include "libknot/dnssec/shared/shared.h"
 #include "libknot/dnssec/shared/binary_wire.h"
 
@@ -85,7 +85,7 @@ int dnssec_key_create_ds(const dnssec_key_t *key,
                return DNSSEC_DS_HASHING_ERROR;
        }
 
-       if (gnutls_hash(digest, key->dname, dname_length(key->dname)) != 0 ||
+       if (gnutls_hash(digest, key->dname, knot_dname_size(key->dname)) != 0 ||
            gnutls_hash(digest, key->rdata.data, key->rdata.size) != 0
        ) {
                return DNSSEC_DS_HASHING_ERROR;
index 8f69dce7be366c63f2410c2c0a4bfb91a22c232f..0bd6bfb70ab158209061b6b58fc4c315ed0fc299 100644 (file)
@@ -9,7 +9,6 @@
 #include <stdint.h>
 
 #include "libknot/dnssec/key.h"
-#include "libknot/dnssec/shared/dname.h"
 
 /*!
  * DNSSEC key.
index 684b5d16cbac11be795071f2aebca0a880959325..7ea3c05a689eb0f5261684cebfca59aa5752ef98 100644 (file)
@@ -9,6 +9,7 @@
 #include <stdlib.h>
 #include <string.h>
 
+#include "libknot/dname.h"
 #include "libknot/dnssec/binary.h"
 #include "libknot/dnssec/error.h"
 #include "libknot/dnssec/key.h"
@@ -176,12 +177,12 @@ int dnssec_key_set_dname(dnssec_key_t *key, const uint8_t *dname)
 
        uint8_t *copy = NULL;
        if (dname) {
-               copy = dname_copy(dname);
+               copy = knot_dname_copy(dname, NULL);
                if (!copy) {
                        return DNSSEC_ENOMEM;
                }
 
-               dname_normalize(copy);
+               knot_dname_to_lower(copy);
        }
 
        free(key->dname);
diff --git a/src/libknot/dnssec/shared/dname.c b/src/libknot/dnssec/shared/dname.c
deleted file mode 100644 (file)
index c50a4be..0000000
+++ /dev/null
@@ -1,154 +0,0 @@
-/*  Copyright (C) CZ.NIC, z.s.p.o. and contributors
- *  SPDX-License-Identifier: GPL-2.0-or-later
- *  For more information, see <https://www.knot-dns.cz/>
- */
-
-#include <assert.h>
-#include <stdbool.h>
-#include <stdlib.h>
-#include <stdint.h>
-#include <string.h>
-
-#include "libknot/dnssec/shared/dname.h"
-#include "libknot/dnssec/shared/shared.h"
-#include "contrib/tolower.h"
-
-/*!
- * Get length of a domain name in wire format.
- */
-size_t dname_length(const uint8_t *dname)
-{
-       if (!dname) {
-               return 0;
-       }
-
-       const uint8_t *scan = dname;
-       uint8_t label_len;
-       do {
-               label_len = *scan;
-               scan += 1 + label_len;
-       } while (label_len > 0);
-       assert(scan > dname);
-
-       size_t length = scan - dname;
-       if (length > DNAME_MAX_LENGTH) {
-               return 0;
-       }
-
-       return length;
-}
-
-/*!
- * Copy domain name in wire format.
- */
-uint8_t *dname_copy(const uint8_t *dname)
-{
-       if (!dname) {
-               return NULL;
-       }
-
-       size_t length = dname_length(dname);
-       if (length == 0) {
-               return NULL;
-       }
-
-       uint8_t *copy = malloc(length);
-       if (!copy) {
-               return NULL;
-       }
-
-       memmove(copy, dname, length);
-       return copy;
-}
-
-/*!
- * Normalize dname label in-place.
- *
- * \return Number of processed bytes, 0 if we encounter the last label.
- */
-static uint8_t normalize_label(uint8_t *label)
-{
-       assert(label);
-
-       uint8_t len = *label;
-       if (len == 0 || len > DNAME_MAX_LABEL_LENGTH) {
-               return 0;
-       }
-
-       for (uint8_t *scan = label + 1, *end = scan + len; scan < end; scan++) {
-               *scan = knot_tolower(*scan);
-       }
-
-       return len + 1;
-}
-
-/*!
- * Normalize domain name in wire format.
- */
-void dname_normalize(uint8_t *dname)
-{
-       if (!dname) {
-               return;
-       }
-
-       uint8_t read, *scan = dname;
-       do {
-               read = normalize_label(scan);
-               scan += read;
-       } while (read > 0);
-}
-
-/*!
- * Compare dname labels case insensitively.
- */
-static int label_casecmp(const uint8_t *a, const uint8_t *b, uint8_t len)
-{
-       assert(a);
-       assert(b);
-
-       for (const uint8_t *a_end = a + len; a < a_end; a++, b++) {
-               if (knot_tolower(*a) != knot_tolower(*b)) {
-                       return false;
-               }
-       }
-
-       return true;
-}
-
-/*!
- * Check if two dnames are equal.
- */
-bool dname_equal(const uint8_t *one, const uint8_t *two)
-{
-       if (!one || !two) {
-               return false;
-       }
-
-       const uint8_t *scan_one = one;
-       const uint8_t *scan_two = two;
-
-       for (;;) {
-               if (*scan_one != *scan_two) {
-                       return false;
-               }
-
-               uint8_t len = *scan_one;
-               if (len == 0) {
-                       return true;
-               } else if (len > DNAME_MAX_LABEL_LENGTH) {
-                       return false;
-               }
-
-               scan_one += 1;
-               scan_two += 1;
-
-               if (!label_casecmp(scan_one, scan_two, len)) {
-                       return false;
-               }
-
-               scan_one += len;
-               scan_two += len;
-       }
-
-       return true;
-}
diff --git a/src/libknot/dnssec/shared/dname.h b/src/libknot/dnssec/shared/dname.h
deleted file mode 100644 (file)
index 67e6cdd..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/*  Copyright (C) CZ.NIC, z.s.p.o. and contributors
- *  SPDX-License-Identifier: GPL-2.0-or-later
- *  For more information, see <https://www.knot-dns.cz/>
- */
-
-#pragma once
-
-#include <stdbool.h>
-#include <stdint.h>
-#include <stdlib.h>
-
-/*!
- * Maximal length of domain name including labels and length bytes.
- * \see RFC 1035
- */
-#define DNAME_MAX_LENGTH 255
-
-/*!
- * Maximal length of the domain name label, excluding the label size.
- * \see RFC 1035
- */
-#define DNAME_MAX_LABEL_LENGTH 63
-
-/*!
- * Get length of a domain name in wire format.
- */
-size_t dname_length(const uint8_t *dname);
-
-/*!
- * Copy domain name in wire format.
- */
-uint8_t *dname_copy(const uint8_t *dname);
-
-/*!
- * Normalize domain name in wire format.
- *
- * Currently converts all letters to lowercase.
- */
-void dname_normalize(uint8_t *dname);
-
-/*!
- * Check if two dnames are equal.
- *
- * Case insensitive.
- */
-bool dname_equal(const uint8_t *one, const uint8_t *two);
index 4cda99bb10020484e8893c280185af36558a4b5e..dc246d73f0175ed5ddccc40ae69eed2084f7a349 100644 (file)
@@ -11,7 +11,7 @@
 #include <stdlib.h>
 #include <string.h>
 
-#include "libknot/dnssec/shared/dname.h"
+#include "libknot/dname.h"
 #include "libknot/dnssec/error.h"
 #include "libknot/dnssec/shared/shared.h"
 #include "libknot/dnssec/tsig.h"
@@ -71,7 +71,7 @@ static const algorithm_id_t *lookup_algorithm(algorithm_match_cb match,
 static bool match_dname(const algorithm_id_t *algorithm, const void *data)
 {
        const uint8_t *search = data;
-       return dname_equal(search, (uint8_t *)algorithm->dname);
+       return knot_dname_is_case_equal(search, (uint8_t *)algorithm->dname);
 }
 
 static bool match_name(const algorithm_id_t *algorithm, const void *data)
index a362f8cdde3a26ec005ddaf9138a250e4286be24..a553a648a468822b2a7fd0b38157ac42259323ef 100644 (file)
@@ -66,7 +66,6 @@
 /libknot/test_dnssec_nsec_hash
 /libknot/test_dnssec_random
 /libknot/test_dnssec_shared_bignum
-/libknot/test_dnssec_shared_dname
 /libknot/test_dnssec_sign
 /libknot/test_dnssec_sign_der
 /libknot/test_dnssec_tsig
index 8e1d10cf2ca2babfa94c6b1b00c02636bf264c01..6e662272d8f42c7bdba33130d16285cc1e1cf81e 100644 (file)
@@ -131,7 +131,6 @@ check_PROGRAMS += \
        libknot/test_dnssec_sign                \
        libknot/test_dnssec_sign_der            \
        libknot/test_dnssec_shared_bignum       \
-       libknot/test_dnssec_shared_dname        \
        libknot/test_dnssec_tsig                \
        libknot/test_control                    \
        libknot/test_cookies                    \
diff --git a/tests/libknot/test_dnssec_shared_dname.c b/tests/libknot/test_dnssec_shared_dname.c
deleted file mode 100644 (file)
index 14ff9e2..0000000
+++ /dev/null
@@ -1,68 +0,0 @@
-/*  Copyright (C) CZ.NIC, z.s.p.o. and contributors
- *  SPDX-License-Identifier: GPL-2.0-or-later
- *  For more information, see <https://www.knot-dns.cz/>
- */
-
-#include <stdbool.h>
-#include <string.h>
-#include <tap/basic.h>
-
-#include "libknot/dnssec/shared/dname.c"
-
-static void ok_length(const char *dname, size_t length, const char *info)
-{
-       ok(dname_length((uint8_t *)dname) == length,
-          "dname_length() for %s", info);
-}
-
-static void test_length(void)
-{
-       ok_length(NULL, 0, "NULL");
-       ok_length("", 1, ".");
-       ok_length("\x2""cz", 4, "cz.");
-       ok_length("\x7""example""\x3""com", 13, "example.com.");
-}
-
-static bool dname_binary_equal(const uint8_t *one, const uint8_t *two)
-{
-       return one && two && strcmp((char *)one, (char *)two) == 0;
-}
-
-static void test_copy(void)
-{
-       const uint8_t *dname = (uint8_t *)"\x3""www""\x8""KNOT-DNS""\x2""cz";
-       uint8_t *copy = dname_copy(dname);
-       ok(dname_binary_equal(dname, copy), "dname_copy()");
-       free(copy);
-}
-
-static void test_equal(void)
-{
-       #define eq(a, b) dname_equal((uint8_t *)a, (uint8_t *)b)
-
-       ok(eq("\x4""kiwi""\x4""limo", "\x4""kiwi""\x4""limo") == true,
-          "dname_equal() same");
-       ok(eq("\x6""orange", "\x6""ORANGE") == true,
-          "dname_equal() case single label");
-       ok(eq("\x6""Banana""\03""Tea", "\x6""bANAna""\x3""tea") == true,
-          "dname_equal() case two labels");
-       ok(eq("\x4""Coco""\x4""MILK", "\x3""cow""\x4""milk") == false,
-          "dname_equal() different first");
-       ok(eq("\x4""LIME""\x5""syrup", "\x4""LIme""\x4""beer") == false,
-          "dname_equal() different last");
-       ok(eq("\x5""apple", "\x5""apple""\x5""shake") == false,
-          "dname_equal() a prefix of b");
-       ok(eq("\x5""apple""\x5""juice", "\x5""apple") == false,
-          "dname_equal() b prefix of a");
-}
-
-int main(void)
-{
-       plan_lazy();
-
-       test_length();
-       test_copy();
-       test_equal();
-
-       return 0;
-}
index bc5ec6492fdbe70f252b96e1f44e08efd3ead962..0db129903ffadc041d3f075403b387faa3098838 100644 (file)
@@ -6,8 +6,8 @@
 #include <tap/basic.h>
 #include <string.h>
 
+#include "libknot/dname.h"
 #include "libknot/dnssec/binary.h"
-#include "libknot/dnssec/shared/dname.c"
 #include "libknot/dnssec/tsig.h"
 
 static const dnssec_binary_t payload = {
@@ -82,7 +82,7 @@ static void test_lookup_dname(const uint8_t *dname, int algorithm)
 
        const uint8_t *reverse = dnssec_tsig_algorithm_to_dname(algorithm);
        ok((algorithm == DNSSEC_TSIG_UNKNOWN && reverse == NULL) ||
-          (algorithm != DNSSEC_TSIG_UNKNOWN && dname_equal(reverse, dname)),
+          (algorithm != DNSSEC_TSIG_UNKNOWN && knot_dname_is_case_equal(reverse, dname)),
          "dnssec_tsig_algorithm_to_dname(%d)", algorithm);
 }