Home | History | Annotate | Line # | Download | only in dns
rdata_test.c revision 1.1
      1  1.1  christos /*	$NetBSD: rdata_test.c,v 1.1 2024/02/21 21:54:55 christos Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*
      4  1.1  christos  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
      5  1.1  christos  *
      6  1.1  christos  * SPDX-License-Identifier: MPL-2.0
      7  1.1  christos  *
      8  1.1  christos  * This Source Code Form is subject to the terms of the Mozilla Public
      9  1.1  christos  * License, v. 2.0. If a copy of the MPL was not distributed with this
     10  1.1  christos  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
     11  1.1  christos  *
     12  1.1  christos  * See the COPYRIGHT file distributed with this work for additional
     13  1.1  christos  * information regarding copyright ownership.
     14  1.1  christos  */
     15  1.1  christos 
     16  1.1  christos #include <inttypes.h>
     17  1.1  christos #include <sched.h> /* IWYU pragma: keep */
     18  1.1  christos #include <setjmp.h>
     19  1.1  christos #include <stdarg.h>
     20  1.1  christos #include <stdbool.h>
     21  1.1  christos #include <stddef.h>
     22  1.1  christos #include <stdlib.h>
     23  1.1  christos #include <string.h>
     24  1.1  christos #include <unistd.h>
     25  1.1  christos 
     26  1.1  christos #define UNIT_TESTING
     27  1.1  christos 
     28  1.1  christos #include <openssl_shim.h>
     29  1.1  christos 
     30  1.1  christos #include <openssl/err.h>
     31  1.1  christos 
     32  1.1  christos #include <isc/cmocka.h>
     33  1.1  christos #include <isc/commandline.h>
     34  1.1  christos #include <isc/hex.h>
     35  1.1  christos #include <isc/lex.h>
     36  1.1  christos #include <isc/print.h>
     37  1.1  christos #include <isc/stdio.h>
     38  1.1  christos #include <isc/types.h>
     39  1.1  christos #include <isc/util.h>
     40  1.1  christos 
     41  1.1  christos #include <dns/rdata.h>
     42  1.1  christos 
     43  1.1  christos #include <tests/dns.h>
     44  1.1  christos 
     45  1.1  christos static bool debug = false;
     46  1.1  christos 
     47  1.1  christos /*
     48  1.1  christos  * An array of these structures is passed to compare_ok().
     49  1.1  christos  */
     50  1.1  christos struct compare_ok {
     51  1.1  christos 	const char *text1; /* text passed to fromtext_*() */
     52  1.1  christos 	const char *text2; /* text passed to fromtext_*() */
     53  1.1  christos 	int answer;	   /* -1, 0, 1 */
     54  1.1  christos 	int lineno;	   /* source line defining this RDATA */
     55  1.1  christos };
     56  1.1  christos typedef struct compare_ok compare_ok_t;
     57  1.1  christos 
     58  1.1  christos struct textvsunknown {
     59  1.1  christos 	const char *text1;
     60  1.1  christos 	const char *text2;
     61  1.1  christos };
     62  1.1  christos typedef struct textvsunknown textvsunknown_t;
     63  1.1  christos 
     64  1.1  christos /*
     65  1.1  christos  * An array of these structures is passed to check_text_ok().
     66  1.1  christos  */
     67  1.1  christos typedef struct text_ok {
     68  1.1  christos 	const char *text_in;  /* text passed to fromtext_*() */
     69  1.1  christos 	const char *text_out; /* text expected from totext_*();
     70  1.1  christos 			       * NULL indicates text_in is invalid */
     71  1.1  christos 	unsigned int loop;
     72  1.1  christos } text_ok_t;
     73  1.1  christos 
     74  1.1  christos /*
     75  1.1  christos  * An array of these structures is passed to check_wire_ok().
     76  1.1  christos  */
     77  1.1  christos typedef struct wire_ok {
     78  1.1  christos 	unsigned char data[512]; /* RDATA in wire format */
     79  1.1  christos 	size_t len;		 /* octets of data to parse */
     80  1.1  christos 	bool ok;		 /* is this RDATA valid? */
     81  1.1  christos 	unsigned int loop;
     82  1.1  christos } wire_ok_t;
     83  1.1  christos 
     84  1.1  christos #define COMPARE(r1, r2, answer)          \
     85  1.1  christos 	{                                \
     86  1.1  christos 		r1, r2, answer, __LINE__ \
     87  1.1  christos 	}
     88  1.1  christos #define COMPARE_SENTINEL()              \
     89  1.1  christos 	{                               \
     90  1.1  christos 		NULL, NULL, 0, __LINE__ \
     91  1.1  christos 	}
     92  1.1  christos 
     93  1.1  christos #define TEXT_VALID_CHANGED(data_in, data_out) \
     94  1.1  christos 	{                                     \
     95  1.1  christos 		data_in, data_out, 0          \
     96  1.1  christos 	}
     97  1.1  christos #define TEXT_VALID(data)      \
     98  1.1  christos 	{                     \
     99  1.1  christos 		data, data, 0 \
    100  1.1  christos 	}
    101  1.1  christos #define TEXT_VALID_LOOP(loop, data) \
    102  1.1  christos 	{                           \
    103  1.1  christos 		data, data, loop    \
    104  1.1  christos 	}
    105  1.1  christos #define TEXT_VALID_LOOPCHG(loop, data_in, data_out) \
    106  1.1  christos 	{                                           \
    107  1.1  christos 		data_in, data_out, loop             \
    108  1.1  christos 	}
    109  1.1  christos #define TEXT_INVALID(data)    \
    110  1.1  christos 	{                     \
    111  1.1  christos 		data, NULL, 0 \
    112  1.1  christos 	}
    113  1.1  christos #define TEXT_SENTINEL() TEXT_INVALID(NULL)
    114  1.1  christos 
    115  1.1  christos #define VARGC(...) (sizeof((unsigned char[]){ __VA_ARGS__ }))
    116  1.1  christos #define WIRE_TEST(ok, loop, ...)                              \
    117  1.1  christos 	{                                                     \
    118  1.1  christos 		{ __VA_ARGS__ }, VARGC(__VA_ARGS__), ok, loop \
    119  1.1  christos 	}
    120  1.1  christos #define WIRE_VALID(...)		   WIRE_TEST(true, 0, __VA_ARGS__)
    121  1.1  christos #define WIRE_VALID_LOOP(loop, ...) WIRE_TEST(true, loop, __VA_ARGS__)
    122  1.1  christos /*
    123  1.1  christos  * WIRE_INVALID() test cases must always have at least one octet specified to
    124  1.1  christos  * distinguish them from WIRE_SENTINEL().  Use the 'empty_ok' parameter passed
    125  1.1  christos  * to check_wire_ok() for indicating whether empty RDATA is allowed for a given
    126  1.1  christos  * RR type or not.
    127  1.1  christos  */
    128  1.1  christos #define WIRE_INVALID(FIRST, ...) WIRE_TEST(false, 0, FIRST, __VA_ARGS__)
    129  1.1  christos #define WIRE_SENTINEL()		 WIRE_TEST(false, 0)
    130  1.1  christos 
    131  1.1  christos static void
    132  1.1  christos detect_uncleared_libcrypto_error(void) {
    133  1.1  christos 	const char *file, *func, *data;
    134  1.1  christos 	int line, flags;
    135  1.1  christos 	long err;
    136  1.1  christos 	bool leak = false;
    137  1.1  christos 	while ((err = ERR_get_error_all(&file, &line, &func, &data, &flags)) !=
    138  1.1  christos 	       0L)
    139  1.1  christos 	{
    140  1.1  christos 		fprintf(stderr,
    141  1.1  christos 			"# Uncleared libcrypto error: %s:%d %s %s %ld %x\n",
    142  1.1  christos 			file, line, func, data, err, flags);
    143  1.1  christos 		leak = true;
    144  1.1  christos 	}
    145  1.1  christos 	assert_false(leak);
    146  1.1  christos }
    147  1.1  christos 
    148  1.1  christos /*
    149  1.1  christos  * Call dns_rdata_fromwire() for data in 'src', which is 'srclen' octets in
    150  1.1  christos  * size and represents RDATA of given 'type' and 'class'.  Store the resulting
    151  1.1  christos  * uncompressed wire form in 'dst', which is 'dstlen' octets in size, and make
    152  1.1  christos  * 'rdata' refer to that uncompressed wire form.
    153  1.1  christos  */
    154  1.1  christos static isc_result_t
    155  1.1  christos wire_to_rdata(const unsigned char *src, size_t srclen, dns_rdataclass_t rdclass,
    156  1.1  christos 	      dns_rdatatype_t type, unsigned char *dst, size_t dstlen,
    157  1.1  christos 	      dns_rdata_t *rdata) {
    158  1.1  christos 	isc_buffer_t source, target;
    159  1.1  christos 	dns_decompress_t dctx;
    160  1.1  christos 	isc_result_t result;
    161  1.1  christos 
    162  1.1  christos 	/*
    163  1.1  christos 	 * Set up len-octet buffer pointing at data.
    164  1.1  christos 	 */
    165  1.1  christos 	isc_buffer_constinit(&source, src, srclen);
    166  1.1  christos 	isc_buffer_add(&source, srclen);
    167  1.1  christos 	isc_buffer_setactive(&source, srclen);
    168  1.1  christos 
    169  1.1  christos 	/*
    170  1.1  christos 	 * Initialize target buffer.
    171  1.1  christos 	 */
    172  1.1  christos 	isc_buffer_init(&target, dst, dstlen);
    173  1.1  christos 
    174  1.1  christos 	/*
    175  1.1  christos 	 * Try converting input data into uncompressed wire form.
    176  1.1  christos 	 */
    177  1.1  christos 	dns_decompress_init(&dctx, -1, DNS_DECOMPRESS_ANY);
    178  1.1  christos 	result = dns_rdata_fromwire(rdata, rdclass, type, &source, &dctx, 0,
    179  1.1  christos 				    &target);
    180  1.1  christos 	dns_decompress_invalidate(&dctx);
    181  1.1  christos 	detect_uncleared_libcrypto_error();
    182  1.1  christos 
    183  1.1  christos 	return (result);
    184  1.1  christos }
    185  1.1  christos 
    186  1.1  christos /*
    187  1.1  christos  * Call dns_rdata_towire() for rdata and write to result to dst.
    188  1.1  christos  */
    189  1.1  christos static isc_result_t
    190  1.1  christos rdata_towire(dns_rdata_t *rdata, unsigned char *dst, size_t dstlen,
    191  1.1  christos 	     size_t *length) {
    192  1.1  christos 	isc_buffer_t target;
    193  1.1  christos 	dns_compress_t cctx;
    194  1.1  christos 	isc_result_t result;
    195  1.1  christos 
    196  1.1  christos 	/*
    197  1.1  christos 	 * Initialize target buffer.
    198  1.1  christos 	 */
    199  1.1  christos 	isc_buffer_init(&target, dst, dstlen);
    200  1.1  christos 
    201  1.1  christos 	/*
    202  1.1  christos 	 * Try converting input data into uncompressed wire form.
    203  1.1  christos 	 */
    204  1.1  christos 	dns_compress_init(&cctx, -1, mctx);
    205  1.1  christos 	result = dns_rdata_towire(rdata, &cctx, &target);
    206  1.1  christos 	detect_uncleared_libcrypto_error();
    207  1.1  christos 	dns_compress_invalidate(&cctx);
    208  1.1  christos 
    209  1.1  christos 	*length = isc_buffer_usedlength(&target);
    210  1.1  christos 
    211  1.1  christos 	return (result);
    212  1.1  christos }
    213  1.1  christos 
    214  1.1  christos static isc_result_t
    215  1.1  christos additionaldata_cb(void *arg, const dns_name_t *name, dns_rdatatype_t qtype,
    216  1.1  christos 		  dns_rdataset_t *found) {
    217  1.1  christos 	UNUSED(arg);
    218  1.1  christos 	UNUSED(name);
    219  1.1  christos 	UNUSED(qtype);
    220  1.1  christos 	UNUSED(found);
    221  1.1  christos 	return (ISC_R_SUCCESS);
    222  1.1  christos }
    223  1.1  christos 
    224  1.1  christos /*
    225  1.1  christos  * call dns_rdata_additionaldata() for rdata.
    226  1.1  christos  */
    227  1.1  christos static isc_result_t
    228  1.1  christos rdata_additionadata(dns_rdata_t *rdata) {
    229  1.1  christos 	return (dns_rdata_additionaldata(rdata, dns_rootname, additionaldata_cb,
    230  1.1  christos 					 NULL));
    231  1.1  christos }
    232  1.1  christos 
    233  1.1  christos /*
    234  1.1  christos  * Call dns_rdata_checknames() with various owner names chosen to
    235  1.1  christos  * match well known forms.
    236  1.1  christos  *
    237  1.1  christos  * We are currently only checking that the calls do not trigger
    238  1.1  christos  * assertion failures.
    239  1.1  christos  *
    240  1.1  christos  * XXXMPA A future extension could be to record the expected
    241  1.1  christos  * result and the expected value of 'bad'.
    242  1.1  christos  */
    243  1.1  christos static void
    244  1.1  christos rdata_checknames(dns_rdata_t *rdata) {
    245  1.1  christos 	dns_fixedname_t fixed, bfixed;
    246  1.1  christos 	dns_name_t *name, *bad;
    247  1.1  christos 	isc_result_t result;
    248  1.1  christos 
    249  1.1  christos 	name = dns_fixedname_initname(&fixed);
    250  1.1  christos 	bad = dns_fixedname_initname(&bfixed);
    251  1.1  christos 
    252  1.1  christos 	(void)dns_rdata_checknames(rdata, dns_rootname, NULL);
    253  1.1  christos 	(void)dns_rdata_checknames(rdata, dns_rootname, bad);
    254  1.1  christos 
    255  1.1  christos 	result = dns_name_fromstring(name, "example.net", 0, NULL);
    256  1.1  christos 	assert_int_equal(result, ISC_R_SUCCESS);
    257  1.1  christos 	(void)dns_rdata_checknames(rdata, name, NULL);
    258  1.1  christos 	(void)dns_rdata_checknames(rdata, name, bad);
    259  1.1  christos 
    260  1.1  christos 	result = dns_name_fromstring(name, "in-addr.arpa", 0, NULL);
    261  1.1  christos 	assert_int_equal(result, ISC_R_SUCCESS);
    262  1.1  christos 	(void)dns_rdata_checknames(rdata, name, NULL);
    263  1.1  christos 	(void)dns_rdata_checknames(rdata, name, bad);
    264  1.1  christos 
    265  1.1  christos 	result = dns_name_fromstring(name, "ip6.arpa", 0, NULL);
    266  1.1  christos 	assert_int_equal(result, ISC_R_SUCCESS);
    267  1.1  christos 	(void)dns_rdata_checknames(rdata, name, NULL);
    268  1.1  christos 	(void)dns_rdata_checknames(rdata, name, bad);
    269  1.1  christos }
    270  1.1  christos 
    271  1.1  christos /*
    272  1.1  christos  * Test whether converting rdata to a type-specific struct and then back to
    273  1.1  christos  * rdata results in the same uncompressed wire form.  This checks whether
    274  1.1  christos  * tostruct_*() and fromstruct_*() routines for given RR class and type behave
    275  1.1  christos  * consistently.
    276  1.1  christos  *
    277  1.1  christos  * This function is called for every correctly processed input RDATA, from both
    278  1.1  christos  * check_text_ok_single() and check_wire_ok_single().
    279  1.1  christos  */
    280  1.1  christos static void
    281  1.1  christos check_struct_conversions(dns_rdata_t *rdata, size_t structsize,
    282  1.1  christos 			 unsigned int loop) {
    283  1.1  christos 	dns_rdataclass_t rdclass = rdata->rdclass;
    284  1.1  christos 	dns_rdatatype_t type = rdata->type;
    285  1.1  christos 	isc_result_t result;
    286  1.1  christos 	isc_buffer_t target;
    287  1.1  christos 	void *rdata_struct;
    288  1.1  christos 	char buf[1024];
    289  1.1  christos 	unsigned int count = 0;
    290  1.1  christos 
    291  1.1  christos 	rdata_struct = isc_mem_allocate(mctx, structsize);
    292  1.1  christos 	assert_non_null(rdata_struct);
    293  1.1  christos 
    294  1.1  christos 	/*
    295  1.1  christos 	 * Convert from uncompressed wire form into type-specific struct.
    296  1.1  christos 	 */
    297  1.1  christos 	result = dns_rdata_tostruct(rdata, rdata_struct, NULL);
    298  1.1  christos 	detect_uncleared_libcrypto_error();
    299  1.1  christos 	assert_int_equal(result, ISC_R_SUCCESS);
    300  1.1  christos 
    301  1.1  christos 	/*
    302  1.1  christos 	 * Convert from type-specific struct into uncompressed wire form.
    303  1.1  christos 	 */
    304  1.1  christos 	isc_buffer_init(&target, buf, sizeof(buf));
    305  1.1  christos 	result = dns_rdata_fromstruct(NULL, rdclass, type, rdata_struct,
    306  1.1  christos 				      &target);
    307  1.1  christos 	assert_int_equal(result, ISC_R_SUCCESS);
    308  1.1  christos 
    309  1.1  christos 	/*
    310  1.1  christos 	 * Ensure results are consistent.
    311  1.1  christos 	 */
    312  1.1  christos 	assert_int_equal(isc_buffer_usedlength(&target), rdata->length);
    313  1.1  christos 
    314  1.1  christos 	assert_memory_equal(buf, rdata->data, rdata->length);
    315  1.1  christos 
    316  1.1  christos 	/*
    317  1.1  christos 	 * Check that one can walk hip rendezvous servers and
    318  1.1  christos 	 * https/svcb parameters.
    319  1.1  christos 	 */
    320  1.1  christos 	switch (type) {
    321  1.1  christos 	case dns_rdatatype_hip: {
    322  1.1  christos 		dns_rdata_hip_t *hip = rdata_struct;
    323  1.1  christos 
    324  1.1  christos 		for (result = dns_rdata_hip_first(hip); result == ISC_R_SUCCESS;
    325  1.1  christos 		     result = dns_rdata_hip_next(hip))
    326  1.1  christos 		{
    327  1.1  christos 			dns_name_t name;
    328  1.1  christos 			dns_name_init(&name, NULL);
    329  1.1  christos 			dns_rdata_hip_current(hip, &name);
    330  1.1  christos 			assert_int_not_equal(dns_name_countlabels(&name), 0);
    331  1.1  christos 			assert_true(dns_name_isabsolute(&name));
    332  1.1  christos 			count++;
    333  1.1  christos 		}
    334  1.1  christos 		assert_int_equal(result, ISC_R_NOMORE);
    335  1.1  christos 		assert_int_equal(count, loop);
    336  1.1  christos 		break;
    337  1.1  christos 	}
    338  1.1  christos 	case dns_rdatatype_https: {
    339  1.1  christos 		dns_rdata_in_https_t *https = rdata_struct;
    340  1.1  christos 
    341  1.1  christos 		for (result = dns_rdata_in_https_first(https);
    342  1.1  christos 		     result == ISC_R_SUCCESS;
    343  1.1  christos 		     result = dns_rdata_in_https_next(https))
    344  1.1  christos 		{
    345  1.1  christos 			isc_region_t region;
    346  1.1  christos 			dns_rdata_in_https_current(https, &region);
    347  1.1  christos 			assert_true(region.length >= 4);
    348  1.1  christos 			count++;
    349  1.1  christos 		}
    350  1.1  christos 		assert_int_equal(result, ISC_R_NOMORE);
    351  1.1  christos 		assert_int_equal(count, loop);
    352  1.1  christos 		break;
    353  1.1  christos 	}
    354  1.1  christos 	case dns_rdatatype_svcb: {
    355  1.1  christos 		dns_rdata_in_svcb_t *svcb = rdata_struct;
    356  1.1  christos 
    357  1.1  christos 		for (result = dns_rdata_in_svcb_first(svcb);
    358  1.1  christos 		     result == ISC_R_SUCCESS;
    359  1.1  christos 		     result = dns_rdata_in_svcb_next(svcb))
    360  1.1  christos 		{
    361  1.1  christos 			isc_region_t region;
    362  1.1  christos 			dns_rdata_in_svcb_current(svcb, &region);
    363  1.1  christos 			assert_true(region.length >= 4);
    364  1.1  christos 			count++;
    365  1.1  christos 		}
    366  1.1  christos 		assert_int_equal(result, ISC_R_NOMORE);
    367  1.1  christos 		assert_int_equal(count, loop);
    368  1.1  christos 		break;
    369  1.1  christos 	}
    370  1.1  christos 	}
    371  1.1  christos 
    372  1.1  christos 	isc_mem_free(mctx, rdata_struct);
    373  1.1  christos }
    374  1.1  christos 
    375  1.1  christos /*
    376  1.1  christos  * Check whether converting supplied text form RDATA into uncompressed wire
    377  1.1  christos  * form succeeds (tests fromtext_*()).  If so, try converting it back into text
    378  1.1  christos  * form and see if it results in the original text (tests totext_*()).
    379  1.1  christos  */
    380  1.1  christos static void
    381  1.1  christos check_text_ok_single(const text_ok_t *text_ok, dns_rdataclass_t rdclass,
    382  1.1  christos 		     dns_rdatatype_t type, size_t structsize) {
    383  1.1  christos 	unsigned char buf_fromtext[1024], buf_fromwire[1024], buf_towire[1024];
    384  1.1  christos 	dns_rdata_t rdata = DNS_RDATA_INIT, rdata2 = DNS_RDATA_INIT;
    385  1.1  christos 	char buf_totext[1024] = { 0 };
    386  1.1  christos 	isc_buffer_t target;
    387  1.1  christos 	isc_result_t result;
    388  1.1  christos 	size_t length = 0;
    389  1.1  christos 
    390  1.1  christos 	if (debug) {
    391  1.1  christos 		fprintf(stdout, "#check_text_ok_single(%s)\n",
    392  1.1  christos 			text_ok->text_in);
    393  1.1  christos 	}
    394  1.1  christos 	/*
    395  1.1  christos 	 * Try converting text form RDATA into uncompressed wire form.
    396  1.1  christos 	 */
    397  1.1  christos 	result = dns_test_rdatafromstring(&rdata, rdclass, type, buf_fromtext,
    398  1.1  christos 					  sizeof(buf_fromtext),
    399  1.1  christos 					  text_ok->text_in, false);
    400  1.1  christos 	/*
    401  1.1  christos 	 * Check whether result is as expected.
    402  1.1  christos 	 */
    403  1.1  christos 	if (text_ok->text_out != NULL) {
    404  1.1  christos 		if (debug && result != ISC_R_SUCCESS) {
    405  1.1  christos 			fprintf(stdout, "# '%s'\n", text_ok->text_in);
    406  1.1  christos 			fprintf(stdout, "# result=%s\n",
    407  1.1  christos 				isc_result_totext(result));
    408  1.1  christos 		}
    409  1.1  christos 		assert_int_equal(result, ISC_R_SUCCESS);
    410  1.1  christos 	} else {
    411  1.1  christos 		if (debug && result == ISC_R_SUCCESS) {
    412  1.1  christos 			fprintf(stdout, "#'%s'\n", text_ok->text_in);
    413  1.1  christos 		}
    414  1.1  christos 		assert_int_not_equal(result, ISC_R_SUCCESS);
    415  1.1  christos 	}
    416  1.1  christos 
    417  1.1  christos 	/*
    418  1.1  christos 	 * If text form RDATA was not parsed correctly, performing any
    419  1.1  christos 	 * additional checks is pointless.
    420  1.1  christos 	 */
    421  1.1  christos 	if (result != ISC_R_SUCCESS) {
    422  1.1  christos 		return;
    423  1.1  christos 	}
    424  1.1  christos 
    425  1.1  christos 	/*
    426  1.1  christos 	 * Try converting uncompressed wire form RDATA back into text form and
    427  1.1  christos 	 * check whether the resulting text is the same as the original one.
    428  1.1  christos 	 */
    429  1.1  christos 	isc_buffer_init(&target, buf_totext, sizeof(buf_totext));
    430  1.1  christos 	result = dns_rdata_totext(&rdata, NULL, &target);
    431  1.1  christos 	detect_uncleared_libcrypto_error();
    432  1.1  christos 	if (result != ISC_R_SUCCESS && debug) {
    433  1.1  christos 		size_t i;
    434  1.1  christos 		fprintf(stdout, "# dns_rdata_totext -> %s",
    435  1.1  christos 			isc_result_totext(result));
    436  1.1  christos 		for (i = 0; i < rdata.length; i++) {
    437  1.1  christos 			if ((i % 16) == 0) {
    438  1.1  christos 				fprintf(stdout, "\n#");
    439  1.1  christos 			}
    440  1.1  christos 			fprintf(stdout, " %02x", rdata.data[i]);
    441  1.1  christos 		}
    442  1.1  christos 		fprintf(stdout, "\n");
    443  1.1  christos 	}
    444  1.1  christos 	assert_int_equal(result, ISC_R_SUCCESS);
    445  1.1  christos 	/*
    446  1.1  christos 	 * Ensure buf_totext is properly NUL terminated as dns_rdata_totext()
    447  1.1  christos 	 * may attempt different output formats writing into the apparently
    448  1.1  christos 	 * unused part of the buffer.
    449  1.1  christos 	 */
    450  1.1  christos 	isc_buffer_putuint8(&target, 0);
    451  1.1  christos 	if (debug && strcmp(buf_totext, text_ok->text_out) != 0) {
    452  1.1  christos 		fprintf(stdout, "# '%s' != '%s'\n", buf_totext,
    453  1.1  christos 			text_ok->text_out);
    454  1.1  christos 	}
    455  1.1  christos 	assert_string_equal(buf_totext, text_ok->text_out);
    456  1.1  christos 
    457  1.1  christos 	if (debug) {
    458  1.1  christos 		fprintf(stdout, "#dns_rdata_totext -> '%s'\n", buf_totext);
    459  1.1  christos 	}
    460  1.1  christos 
    461  1.1  christos 	/*
    462  1.1  christos 	 * Ensure that fromtext_*() output is valid input for fromwire_*().
    463  1.1  christos 	 */
    464  1.1  christos 	result = wire_to_rdata(rdata.data, rdata.length, rdclass, type,
    465  1.1  christos 			       buf_fromwire, sizeof(buf_fromwire), &rdata2);
    466  1.1  christos 	assert_int_equal(result, ISC_R_SUCCESS);
    467  1.1  christos 	assert_int_equal(rdata.length, rdata2.length);
    468  1.1  christos 	assert_memory_equal(rdata.data, buf_fromwire, rdata.length);
    469  1.1  christos 
    470  1.1  christos 	/*
    471  1.1  christos 	 * Ensure that fromtext_*() output is valid input for towire_*().
    472  1.1  christos 	 */
    473  1.1  christos 	result = rdata_towire(&rdata, buf_towire, sizeof(buf_towire), &length);
    474  1.1  christos 	assert_int_equal(result, ISC_R_SUCCESS);
    475  1.1  christos 	assert_int_equal(rdata.length, length);
    476  1.1  christos 	assert_memory_equal(rdata.data, buf_towire, length);
    477  1.1  christos 
    478  1.1  christos 	/*
    479  1.1  christos 	 * Test that additionaldata_*() succeeded.
    480  1.1  christos 	 */
    481  1.1  christos 	result = rdata_additionadata(&rdata);
    482  1.1  christos 	assert_int_equal(result, ISC_R_SUCCESS);
    483  1.1  christos 
    484  1.1  christos 	/*
    485  1.1  christos 	 * Exercise checknames_*().
    486  1.1  christos 	 */
    487  1.1  christos 	rdata_checknames(&rdata);
    488  1.1  christos 
    489  1.1  christos 	/*
    490  1.1  christos 	 * Perform two-way conversion checks between uncompressed wire form and
    491  1.1  christos 	 * type-specific struct.
    492  1.1  christos 	 */
    493  1.1  christos 	check_struct_conversions(&rdata, structsize, text_ok->loop);
    494  1.1  christos }
    495  1.1  christos 
    496  1.1  christos /*
    497  1.1  christos  * Test whether converting rdata to text form and then parsing the result of
    498  1.1  christos  * that conversion again results in the same uncompressed wire form.  This
    499  1.1  christos  * checks whether totext_*() output is parsable by fromtext_*() for given RR
    500  1.1  christos  * class and type.
    501  1.1  christos  *
    502  1.1  christos  * This function is called for every input RDATA which is successfully parsed
    503  1.1  christos  * by check_wire_ok_single() and whose type is not a meta-type.
    504  1.1  christos  */
    505  1.1  christos static void
    506  1.1  christos check_text_conversions(dns_rdata_t *rdata) {
    507  1.1  christos 	char buf_totext[1024] = { 0 };
    508  1.1  christos 	unsigned char buf_fromtext[1024];
    509  1.1  christos 	isc_result_t result;
    510  1.1  christos 	isc_buffer_t target;
    511  1.1  christos 	dns_rdata_t rdata2 = DNS_RDATA_INIT;
    512  1.1  christos 
    513  1.1  christos 	/*
    514  1.1  christos 	 * Convert uncompressed wire form RDATA into text form.  This
    515  1.1  christos 	 * conversion must succeed since input RDATA was successfully
    516  1.1  christos 	 * parsed by check_wire_ok_single().
    517  1.1  christos 	 */
    518  1.1  christos 	isc_buffer_init(&target, buf_totext, sizeof(buf_totext));
    519  1.1  christos 	result = dns_rdata_totext(rdata, NULL, &target);
    520  1.1  christos 	detect_uncleared_libcrypto_error();
    521  1.1  christos 	assert_int_equal(result, ISC_R_SUCCESS);
    522  1.1  christos 	/*
    523  1.1  christos 	 * Ensure buf_totext is properly NUL terminated as dns_rdata_totext()
    524  1.1  christos 	 * may attempt different output formats writing into the apparently
    525  1.1  christos 	 * unused part of the buffer.
    526  1.1  christos 	 */
    527  1.1  christos 	isc_buffer_putuint8(&target, 0);
    528  1.1  christos 	if (debug) {
    529  1.1  christos 		fprintf(stdout, "#'%s'\n", buf_totext);
    530  1.1  christos 	}
    531  1.1  christos 
    532  1.1  christos 	/*
    533  1.1  christos 	 * Try parsing text form RDATA output by dns_rdata_totext() again.
    534  1.1  christos 	 */
    535  1.1  christos 	result = dns_test_rdatafromstring(&rdata2, rdata->rdclass, rdata->type,
    536  1.1  christos 					  buf_fromtext, sizeof(buf_fromtext),
    537  1.1  christos 					  buf_totext, false);
    538  1.1  christos 	if (debug && result != ISC_R_SUCCESS) {
    539  1.1  christos 		fprintf(stdout, "# result = %s\n", isc_result_totext(result));
    540  1.1  christos 		fprintf(stdout, "# '%s'\n", buf_fromtext);
    541  1.1  christos 	}
    542  1.1  christos 	assert_int_equal(result, ISC_R_SUCCESS);
    543  1.1  christos 	assert_int_equal(rdata2.length, rdata->length);
    544  1.1  christos 	assert_memory_equal(buf_fromtext, rdata->data, rdata->length);
    545  1.1  christos }
    546  1.1  christos 
    547  1.1  christos /*
    548  1.1  christos  * Test whether converting rdata to multi-line text form and then parsing the
    549  1.1  christos  * result of that conversion again results in the same uncompressed wire form.
    550  1.1  christos  * This checks whether multi-line totext_*() output is parsable by fromtext_*()
    551  1.1  christos  * for given RR class and type.
    552  1.1  christos  *
    553  1.1  christos  * This function is called for every input RDATA which is successfully parsed
    554  1.1  christos  * by check_wire_ok_single() and whose type is not a meta-type.
    555  1.1  christos  */
    556  1.1  christos static void
    557  1.1  christos check_multiline_text_conversions(dns_rdata_t *rdata) {
    558  1.1  christos 	char buf_totext[1024] = { 0 };
    559  1.1  christos 	unsigned char buf_fromtext[1024];
    560  1.1  christos 	isc_result_t result;
    561  1.1  christos 	isc_buffer_t target;
    562  1.1  christos 	dns_rdata_t rdata2 = DNS_RDATA_INIT;
    563  1.1  christos 	unsigned int flags;
    564  1.1  christos 
    565  1.1  christos 	/*
    566  1.1  christos 	 * Convert uncompressed wire form RDATA into multi-line text form.
    567  1.1  christos 	 * This conversion must succeed since input RDATA was successfully
    568  1.1  christos 	 * parsed by check_wire_ok_single().
    569  1.1  christos 	 */
    570  1.1  christos 	isc_buffer_init(&target, buf_totext, sizeof(buf_totext));
    571  1.1  christos 	flags = dns_master_styleflags(&dns_master_style_default);
    572  1.1  christos 	result = dns_rdata_tofmttext(rdata, dns_rootname, flags, 80 - 32, 4,
    573  1.1  christos 				     "\n", &target);
    574  1.1  christos 	detect_uncleared_libcrypto_error();
    575  1.1  christos 	assert_int_equal(result, ISC_R_SUCCESS);
    576  1.1  christos 	/*
    577  1.1  christos 	 * Ensure buf_totext is properly NUL terminated as
    578  1.1  christos 	 * dns_rdata_tofmttext() may attempt different output formats
    579  1.1  christos 	 * writing into the apparently unused part of the buffer.
    580  1.1  christos 	 */
    581  1.1  christos 	isc_buffer_putuint8(&target, 0);
    582  1.1  christos 	if (debug) {
    583  1.1  christos 		fprintf(stdout, "#'%s'\n", buf_totext);
    584  1.1  christos 	}
    585  1.1  christos 
    586  1.1  christos 	/*
    587  1.1  christos 	 * Try parsing multi-line text form RDATA output by
    588  1.1  christos 	 * dns_rdata_tofmttext() again.
    589  1.1  christos 	 */
    590  1.1  christos 	result = dns_test_rdatafromstring(&rdata2, rdata->rdclass, rdata->type,
    591  1.1  christos 					  buf_fromtext, sizeof(buf_fromtext),
    592  1.1  christos 					  buf_totext, false);
    593  1.1  christos 	assert_int_equal(result, ISC_R_SUCCESS);
    594  1.1  christos 	assert_int_equal(rdata2.length, rdata->length);
    595  1.1  christos 	assert_memory_equal(buf_fromtext, rdata->data, rdata->length);
    596  1.1  christos }
    597  1.1  christos 
    598  1.1  christos /*
    599  1.1  christos  * Test whether supplied wire form RDATA is properly handled as being either
    600  1.1  christos  * valid or invalid for an RR of given rdclass and type.
    601  1.1  christos  */
    602  1.1  christos static void
    603  1.1  christos check_wire_ok_single(const wire_ok_t *wire_ok, dns_rdataclass_t rdclass,
    604  1.1  christos 		     dns_rdatatype_t type, size_t structsize) {
    605  1.1  christos 	unsigned char buf[1024], buf_towire[1024];
    606  1.1  christos 	isc_result_t result;
    607  1.1  christos 	dns_rdata_t rdata = DNS_RDATA_INIT;
    608  1.1  christos 	size_t length = 0;
    609  1.1  christos 
    610  1.1  christos 	/*
    611  1.1  christos 	 * Try converting wire data into uncompressed wire form.
    612  1.1  christos 	 */
    613  1.1  christos 	result = wire_to_rdata(wire_ok->data, wire_ok->len, rdclass, type, buf,
    614  1.1  christos 			       sizeof(buf), &rdata);
    615  1.1  christos 	/*
    616  1.1  christos 	 * Check whether result is as expected.
    617  1.1  christos 	 */
    618  1.1  christos 	if (wire_ok->ok) {
    619  1.1  christos 		assert_int_equal(result, ISC_R_SUCCESS);
    620  1.1  christos 	} else {
    621  1.1  christos 		assert_int_not_equal(result, ISC_R_SUCCESS);
    622  1.1  christos 	}
    623  1.1  christos 
    624  1.1  christos 	if (result != ISC_R_SUCCESS) {
    625  1.1  christos 		return;
    626  1.1  christos 	}
    627  1.1  christos 
    628  1.1  christos 	/*
    629  1.1  christos 	 * If data was parsed correctly, perform two-way conversion checks
    630  1.1  christos 	 * between uncompressed wire form and type-specific struct.
    631  1.1  christos 	 *
    632  1.1  christos 	 * If the RR type is not a meta-type, additionally perform two-way
    633  1.1  christos 	 * conversion checks between:
    634  1.1  christos 	 *
    635  1.1  christos 	 *   - uncompressed wire form and text form,
    636  1.1  christos 	 *   - uncompressed wire form and multi-line text form.
    637  1.1  christos 	 */
    638  1.1  christos 	check_struct_conversions(&rdata, structsize, wire_ok->loop);
    639  1.1  christos 	if (!dns_rdatatype_ismeta(rdata.type)) {
    640  1.1  christos 		check_text_conversions(&rdata);
    641  1.1  christos 		check_multiline_text_conversions(&rdata);
    642  1.1  christos 	}
    643  1.1  christos 
    644  1.1  christos 	/*
    645  1.1  christos 	 * Ensure that fromwire_*() output is valid input for towire_*().
    646  1.1  christos 	 */
    647  1.1  christos 	result = rdata_towire(&rdata, buf_towire, sizeof(buf_towire), &length);
    648  1.1  christos 	assert_int_equal(result, ISC_R_SUCCESS);
    649  1.1  christos 	assert_int_equal(rdata.length, length);
    650  1.1  christos 	assert_memory_equal(rdata.data, buf_towire, length);
    651  1.1  christos 
    652  1.1  christos 	/*
    653  1.1  christos 	 * Test that additionaldata_*() succeeded.
    654  1.1  christos 	 */
    655  1.1  christos 	result = rdata_additionadata(&rdata);
    656  1.1  christos 	assert_int_equal(result, ISC_R_SUCCESS);
    657  1.1  christos 
    658  1.1  christos 	/*
    659  1.1  christos 	 * Exercise checknames_*().
    660  1.1  christos 	 */
    661  1.1  christos 	rdata_checknames(&rdata);
    662  1.1  christos }
    663  1.1  christos 
    664  1.1  christos /*
    665  1.1  christos  * Test fromtext_*() and totext_*() routines for given RR class and type for
    666  1.1  christos  * each text form RDATA in the supplied array.  See the comment for
    667  1.1  christos  * check_text_ok_single() for an explanation of how exactly these routines are
    668  1.1  christos  * tested.
    669  1.1  christos  */
    670  1.1  christos static void
    671  1.1  christos check_text_ok(const text_ok_t *text_ok, dns_rdataclass_t rdclass,
    672  1.1  christos 	      dns_rdatatype_t type, size_t structsize) {
    673  1.1  christos 	size_t i;
    674  1.1  christos 
    675  1.1  christos 	/*
    676  1.1  christos 	 * Check all entries in the supplied array.
    677  1.1  christos 	 */
    678  1.1  christos 	for (i = 0; text_ok[i].text_in != NULL; i++) {
    679  1.1  christos 		check_text_ok_single(&text_ok[i], rdclass, type, structsize);
    680  1.1  christos 	}
    681  1.1  christos }
    682  1.1  christos 
    683  1.1  christos /*
    684  1.1  christos  * For each wire form RDATA in the supplied array, check whether it is properly
    685  1.1  christos  * handled as being either valid or invalid for an RR of given rdclass and
    686  1.1  christos  * type, then check whether trying to process a zero-length wire data buffer
    687  1.1  christos  * yields the expected result.  This checks whether the fromwire_*() routine
    688  1.1  christos  * for given RR class and type behaves as expected.
    689  1.1  christos  */
    690  1.1  christos static void
    691  1.1  christos check_wire_ok(const wire_ok_t *wire_ok, bool empty_ok, dns_rdataclass_t rdclass,
    692  1.1  christos 	      dns_rdatatype_t type, size_t structsize) {
    693  1.1  christos 	wire_ok_t empty_wire = WIRE_TEST(empty_ok, 0);
    694  1.1  christos 	size_t i;
    695  1.1  christos 
    696  1.1  christos 	/*
    697  1.1  christos 	 * Check all entries in the supplied array.
    698  1.1  christos 	 */
    699  1.1  christos 	for (i = 0; wire_ok[i].len != 0; i++) {
    700  1.1  christos 		if (debug) {
    701  1.1  christos 			fprintf(stderr, "calling check_wire_ok_single on %zu\n",
    702  1.1  christos 				i);
    703  1.1  christos 		}
    704  1.1  christos 		check_wire_ok_single(&wire_ok[i], rdclass, type, structsize);
    705  1.1  christos 	}
    706  1.1  christos 
    707  1.1  christos 	/*
    708  1.1  christos 	 * Check empty wire data.
    709  1.1  christos 	 */
    710  1.1  christos 	check_wire_ok_single(&empty_wire, rdclass, type, structsize);
    711  1.1  christos }
    712  1.1  christos 
    713  1.1  christos /*
    714  1.1  christos  * Check that two records compare as expected with dns_rdata_compare().
    715  1.1  christos  */
    716  1.1  christos static void
    717  1.1  christos check_compare_ok_single(const compare_ok_t *compare_ok,
    718  1.1  christos 			dns_rdataclass_t rdclass, dns_rdatatype_t type) {
    719  1.1  christos 	dns_rdata_t rdata1 = DNS_RDATA_INIT, rdata2 = DNS_RDATA_INIT;
    720  1.1  christos 	unsigned char buf1[1024], buf2[1024];
    721  1.1  christos 	isc_result_t result;
    722  1.1  christos 	int answer;
    723  1.1  christos 
    724  1.1  christos 	result = dns_test_rdatafromstring(&rdata1, rdclass, type, buf1,
    725  1.1  christos 					  sizeof(buf1), compare_ok->text1,
    726  1.1  christos 					  false);
    727  1.1  christos 	if (result != ISC_R_SUCCESS) {
    728  1.1  christos 		fail_msg("# line %d: '%s': expected success, got failure",
    729  1.1  christos 			 compare_ok->lineno, compare_ok->text1);
    730  1.1  christos 	}
    731  1.1  christos 
    732  1.1  christos 	result = dns_test_rdatafromstring(&rdata2, rdclass, type, buf2,
    733  1.1  christos 					  sizeof(buf2), compare_ok->text2,
    734  1.1  christos 					  false);
    735  1.1  christos 
    736  1.1  christos 	if (result != ISC_R_SUCCESS) {
    737  1.1  christos 		fail_msg("# line %d: '%s': expected success, got failure",
    738  1.1  christos 			 compare_ok->lineno, compare_ok->text2);
    739  1.1  christos 	}
    740  1.1  christos 
    741  1.1  christos 	answer = dns_rdata_compare(&rdata1, &rdata2);
    742  1.1  christos 	detect_uncleared_libcrypto_error();
    743  1.1  christos 	if (compare_ok->answer == 0 && answer != 0) {
    744  1.1  christos 		fail_msg("# line %d: dns_rdata_compare('%s', '%s'): "
    745  1.1  christos 			 "expected equal, got %s",
    746  1.1  christos 			 compare_ok->lineno, compare_ok->text1,
    747  1.1  christos 			 compare_ok->text2,
    748  1.1  christos 			 (answer > 0) ? "greater than" : "less than");
    749  1.1  christos 	}
    750  1.1  christos 	if (compare_ok->answer < 0 && answer >= 0) {
    751  1.1  christos 		fail_msg("# line %d: dns_rdata_compare('%s', '%s'): "
    752  1.1  christos 			 "expected less than, got %s",
    753  1.1  christos 			 compare_ok->lineno, compare_ok->text1,
    754  1.1  christos 			 compare_ok->text2,
    755  1.1  christos 			 (answer == 0) ? "equal" : "greater than");
    756  1.1  christos 	}
    757  1.1  christos 	if (compare_ok->answer > 0 && answer <= 0) {
    758  1.1  christos 		fail_msg("line %d: dns_rdata_compare('%s', '%s'): "
    759  1.1  christos 			 "expected greater than, got %s",
    760  1.1  christos 			 compare_ok->lineno, compare_ok->text1,
    761  1.1  christos 			 compare_ok->text2,
    762  1.1  christos 			 (answer == 0) ? "equal" : "less than");
    763  1.1  christos 	}
    764  1.1  christos }
    765  1.1  christos 
    766  1.1  christos /*
    767  1.1  christos  * Check that all the records sets in compare_ok compare as expected
    768  1.1  christos  * with dns_rdata_compare().
    769  1.1  christos  */
    770  1.1  christos static void
    771  1.1  christos check_compare_ok(const compare_ok_t *compare_ok, dns_rdataclass_t rdclass,
    772  1.1  christos 		 dns_rdatatype_t type) {
    773  1.1  christos 	size_t i;
    774  1.1  christos 	/*
    775  1.1  christos 	 * Check all entries in the supplied array.
    776  1.1  christos 	 */
    777  1.1  christos 	for (i = 0; compare_ok[i].text1 != NULL; i++) {
    778  1.1  christos 		check_compare_ok_single(&compare_ok[i], rdclass, type);
    779  1.1  christos 	}
    780  1.1  christos }
    781  1.1  christos 
    782  1.1  christos /*
    783  1.1  christos  * Test whether supplied sets of text form and/or wire form RDATA are handled
    784  1.1  christos  * as expected.
    785  1.1  christos  *
    786  1.1  christos  * The empty_ok argument denotes whether an attempt to parse a zero-length wire
    787  1.1  christos  * data buffer should succeed or not (it is valid for some RR types).  There is
    788  1.1  christos  * no point in performing a similar check for empty text form RDATA, because
    789  1.1  christos  * dns_rdata_fromtext() returns ISC_R_UNEXPECTEDEND before calling fromtext_*()
    790  1.1  christos  * for the given RR class and type.
    791  1.1  christos  */
    792  1.1  christos static void
    793  1.1  christos check_rdata(const text_ok_t *text_ok, const wire_ok_t *wire_ok,
    794  1.1  christos 	    const compare_ok_t *compare_ok, bool empty_ok,
    795  1.1  christos 	    dns_rdataclass_t rdclass, dns_rdatatype_t type, size_t structsize) {
    796  1.1  christos 	if (text_ok != NULL) {
    797  1.1  christos 		check_text_ok(text_ok, rdclass, type, structsize);
    798  1.1  christos 	}
    799  1.1  christos 	if (wire_ok != NULL) {
    800  1.1  christos 		check_wire_ok(wire_ok, empty_ok, rdclass, type, structsize);
    801  1.1  christos 	}
    802  1.1  christos 	if (compare_ok != NULL) {
    803  1.1  christos 		check_compare_ok(compare_ok, rdclass, type);
    804  1.1  christos 	}
    805  1.1  christos }
    806  1.1  christos 
    807  1.1  christos /*
    808  1.1  christos  * Check presentation vs unknown format of the record.
    809  1.1  christos  */
    810  1.1  christos static void
    811  1.1  christos check_textvsunknown_single(const textvsunknown_t *textvsunknown,
    812  1.1  christos 			   dns_rdataclass_t rdclass, dns_rdatatype_t type) {
    813  1.1  christos 	dns_rdata_t rdata1 = DNS_RDATA_INIT, rdata2 = DNS_RDATA_INIT;
    814  1.1  christos 	unsigned char buf1[1024], buf2[1024];
    815  1.1  christos 	isc_result_t result;
    816  1.1  christos 
    817  1.1  christos 	result = dns_test_rdatafromstring(&rdata1, rdclass, type, buf1,
    818  1.1  christos 					  sizeof(buf1), textvsunknown->text1,
    819  1.1  christos 					  false);
    820  1.1  christos 	if (debug && result != ISC_R_SUCCESS) {
    821  1.1  christos 		fprintf(stdout, "# '%s'\n", textvsunknown->text1);
    822  1.1  christos 		fprintf(stdout, "# result=%s\n", isc_result_totext(result));
    823  1.1  christos 	}
    824  1.1  christos 	assert_int_equal(result, ISC_R_SUCCESS);
    825  1.1  christos 	result = dns_test_rdatafromstring(&rdata2, rdclass, type, buf2,
    826  1.1  christos 					  sizeof(buf2), textvsunknown->text2,
    827  1.1  christos 					  false);
    828  1.1  christos 	if (debug && result != ISC_R_SUCCESS) {
    829  1.1  christos 		fprintf(stdout, "# '%s'\n", textvsunknown->text2);
    830  1.1  christos 		fprintf(stdout, "# result=%s\n", isc_result_totext(result));
    831  1.1  christos 	}
    832  1.1  christos 	assert_int_equal(result, ISC_R_SUCCESS);
    833  1.1  christos 	if (debug && rdata1.length != rdata2.length) {
    834  1.1  christos 		fprintf(stdout, "# '%s'\n", textvsunknown->text1);
    835  1.1  christos 		fprintf(stdout, "# rdata1.length (%u) != rdata2.length (%u)\n",
    836  1.1  christos 			rdata1.length, rdata2.length);
    837  1.1  christos 	}
    838  1.1  christos 	assert_int_equal(rdata1.length, rdata2.length);
    839  1.1  christos 	if (debug && memcmp(rdata1.data, rdata2.data, rdata1.length) != 0) {
    840  1.1  christos 		unsigned int i;
    841  1.1  christos 		fprintf(stdout, "# '%s'\n", textvsunknown->text1);
    842  1.1  christos 		for (i = 0; i < rdata1.length; i++) {
    843  1.1  christos 			if (rdata1.data[i] != rdata2.data[i]) {
    844  1.1  christos 				fprintf(stderr, "# %u: %02x != %02x\n", i,
    845  1.1  christos 					rdata1.data[i], rdata2.data[i]);
    846  1.1  christos 			}
    847  1.1  christos 		}
    848  1.1  christos 	}
    849  1.1  christos 	assert_memory_equal(rdata1.data, rdata2.data, rdata1.length);
    850  1.1  christos }
    851  1.1  christos 
    852  1.1  christos static void
    853  1.1  christos check_textvsunknown(const textvsunknown_t *textvsunknown,
    854  1.1  christos 		    dns_rdataclass_t rdclass, dns_rdatatype_t type) {
    855  1.1  christos 	size_t i;
    856  1.1  christos 
    857  1.1  christos 	/*
    858  1.1  christos 	 * Check all entries in the supplied array.
    859  1.1  christos 	 */
    860  1.1  christos 	for (i = 0; textvsunknown[i].text1 != NULL; i++) {
    861  1.1  christos 		check_textvsunknown_single(&textvsunknown[i], rdclass, type);
    862  1.1  christos 	}
    863  1.1  christos }
    864  1.1  christos 
    865  1.1  christos /*
    866  1.1  christos  * Common tests for RR types based on KEY that require key data:
    867  1.1  christos  *
    868  1.1  christos  *   - CDNSKEY (RFC 7344)
    869  1.1  christos  *   - DNSKEY (RFC 4034)
    870  1.1  christos  *   - RKEY (draft-reid-dnsext-rkey-00)
    871  1.1  christos  */
    872  1.1  christos static void
    873  1.1  christos key_required(void **state, dns_rdatatype_t type, size_t size) {
    874  1.1  christos 	wire_ok_t wire_ok[] = { /*
    875  1.1  christos 				 * RDATA must be at least 5 octets in size:
    876  1.1  christos 				 *
    877  1.1  christos 				 *   - 2 octets for Flags,
    878  1.1  christos 				 *   - 1 octet for Protocol,
    879  1.1  christos 				 *   - 1 octet for Algorithm,
    880  1.1  christos 				 *   - Public Key must not be empty.
    881  1.1  christos 				 *
    882  1.1  christos 				 * RFC 2535 section 3.1.2 allows the Public Key
    883  1.1  christos 				 * to be empty if bits 0-1 of Flags are both
    884  1.1  christos 				 * set, but that only applies to KEY records:
    885  1.1  christos 				 * for the RR types tested here, the Public Key
    886  1.1  christos 				 * must not be empty.
    887  1.1  christos 				 */
    888  1.1  christos 				WIRE_INVALID(0x00),
    889  1.1  christos 				WIRE_INVALID(0x00, 0x00),
    890  1.1  christos 				WIRE_INVALID(0x00, 0x00, 0x00),
    891  1.1  christos 				WIRE_INVALID(0xc0, 0x00, 0x00, 0x00),
    892  1.1  christos 				WIRE_INVALID(0x00, 0x00, 0x00, 0x00),
    893  1.1  christos 				WIRE_VALID(0x00, 0x00, 0x00, 0x00, 0x00),
    894  1.1  christos 				WIRE_SENTINEL()
    895  1.1  christos 	};
    896  1.1  christos 
    897  1.1  christos 	UNUSED(state);
    898  1.1  christos 
    899  1.1  christos 	check_rdata(NULL, wire_ok, NULL, false, dns_rdataclass_in, type, size);
    900  1.1  christos }
    901  1.1  christos 
    902  1.1  christos /* APL RDATA manipulations */
    903  1.1  christos ISC_RUN_TEST_IMPL(apl) {
    904  1.1  christos 	text_ok_t text_ok[] = {
    905  1.1  christos 		/* empty list */
    906  1.1  christos 		TEXT_VALID(""),
    907  1.1  christos 		/* min,max prefix IPv4 */
    908  1.1  christos 		TEXT_VALID("1:0.0.0.0/0"), TEXT_VALID("1:127.0.0.1/32"),
    909  1.1  christos 		/* min,max prefix IPv6 */
    910  1.1  christos 		TEXT_VALID("2:::/0"), TEXT_VALID("2:::1/128"),
    911  1.1  christos 		/* negated */
    912  1.1  christos 		TEXT_VALID("!1:0.0.0.0/0"), TEXT_VALID("!1:127.0.0.1/32"),
    913  1.1  christos 		TEXT_VALID("!2:::/0"), TEXT_VALID("!2:::1/128"),
    914  1.1  christos 		/* bits set after prefix length - not disallowed */
    915  1.1  christos 		TEXT_VALID("1:127.0.0.0/0"), TEXT_VALID("2:8000::/0"),
    916  1.1  christos 		/* multiple */
    917  1.1  christos 		TEXT_VALID("1:0.0.0.0/0 1:127.0.0.1/32"),
    918  1.1  christos 		TEXT_VALID("1:0.0.0.0/0 !1:127.0.0.1/32"),
    919  1.1  christos 		/* family 0, prefix 0, positive */
    920  1.1  christos 		TEXT_VALID("\\# 4 00000000"),
    921  1.1  christos 		/* family 0, prefix 0, negative */
    922  1.1  christos 		TEXT_VALID("\\# 4 00000080"),
    923  1.1  christos 		/* prefix too long */
    924  1.1  christos 		TEXT_INVALID("1:0.0.0.0/33"), TEXT_INVALID("2:::/129"),
    925  1.1  christos 		/*
    926  1.1  christos 		 * Sentinel.
    927  1.1  christos 		 */
    928  1.1  christos 		TEXT_SENTINEL()
    929  1.1  christos 	};
    930  1.1  christos 	wire_ok_t wire_ok[] = { /* zero length */
    931  1.1  christos 				WIRE_VALID(),
    932  1.1  christos 				/* prefix too big IPv4 */
    933  1.1  christos 				WIRE_INVALID(0x00, 0x01, 33U, 0x00),
    934  1.1  christos 				/* prefix too big IPv6 */
    935  1.1  christos 				WIRE_INVALID(0x00, 0x02, 129U, 0x00),
    936  1.1  christos 				/* trailing zero octet in afdpart */
    937  1.1  christos 				WIRE_INVALID(0x00, 0x00, 0x00, 0x01, 0x00),
    938  1.1  christos 				/*
    939  1.1  christos 				 * Sentinel.
    940  1.1  christos 				 */
    941  1.1  christos 				WIRE_SENTINEL()
    942  1.1  christos 	};
    943  1.1  christos 
    944  1.1  christos 	check_rdata(text_ok, wire_ok, NULL, true, dns_rdataclass_in,
    945  1.1  christos 		    dns_rdatatype_apl, sizeof(dns_rdata_in_apl_t));
    946  1.1  christos }
    947  1.1  christos 
    948  1.1  christos /*
    949  1.1  christos  * http://broadband-forum.org/ftp/pub/approved-specs/af-saa-0069.000.pdf
    950  1.1  christos  *
    951  1.1  christos  * ATMA RRs have the following RDATA format:
    952  1.1  christos  *
    953  1.1  christos  *                                           1  1  1  1  1  1
    954  1.1  christos  *             0  1  2  3  4  5  6  7  8  9  0  1  2  3  4  5
    955  1.1  christos  *          +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    956  1.1  christos  *          |          FORMAT       |                       |
    957  1.1  christos  *          +--+--+--+--+--+--+--+--+                       |
    958  1.1  christos  *          /                    ADDRESS                    /
    959  1.1  christos  *          |                                               |
    960  1.1  christos  *          +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
    961  1.1  christos  *
    962  1.1  christos  * The fields have the following meaning:
    963  1.1  christos  *
    964  1.1  christos  * * FORMAT: One octet that indicates the format of ADDRESS. The two
    965  1.1  christos  *   possible values for FORMAT are value 0 indicating ATM End System Address
    966  1.1  christos  *   (AESA) format and value 1 indicating E.164 format.
    967  1.1  christos  *
    968  1.1  christos  * * ADDRESS: Variable length string of octets containing the ATM address of
    969  1.1  christos  *   the node to which this RR pertains.
    970  1.1  christos  *
    971  1.1  christos  * When the format value is 0, indicating that the address is in AESA format,
    972  1.1  christos  * the address is coded as described in ISO 8348/AD 2 using the preferred
    973  1.1  christos  * binary encoding of the ISO NSAP format. When the format value is 1,
    974  1.1  christos  * indicating that the address is in E.164 format, the Address/Number Digits
    975  1.1  christos  * appear in the order in which they would be entered on a numeric keypad.
    976  1.1  christos  * Digits are coded in IA5 characters with the leftmost bit of each digit set
    977  1.1  christos  * to 0.  This ATM address appears in ATM End System Address Octets field (AESA
    978  1.1  christos  * format) or the Address/Number Digits field (E.164 format) of the Called
    979  1.1  christos  * party number information element [ATMUNI3.1]. Subaddress information is
    980  1.1  christos  * intentionally not included because E.164 subaddress information is used for
    981  1.1  christos  * routing.
    982  1.1  christos  *
    983  1.1  christos  * ATMA RRs cause no additional section processing.
    984  1.1  christos  */
    985  1.1  christos ISC_RUN_TEST_IMPL(atma) {
    986  1.1  christos 	text_ok_t text_ok[] = { TEXT_VALID("00"),
    987  1.1  christos 				TEXT_VALID_CHANGED("0.0", "00"),
    988  1.1  christos 				/*
    989  1.1  christos 				 * multiple consecutive periods
    990  1.1  christos 				 */
    991  1.1  christos 				TEXT_INVALID("0..0"),
    992  1.1  christos 				/*
    993  1.1  christos 				 * trailing period
    994  1.1  christos 				 */
    995  1.1  christos 				TEXT_INVALID("00."),
    996  1.1  christos 				/*
    997  1.1  christos 				 * leading period
    998  1.1  christos 				 */
    999  1.1  christos 				TEXT_INVALID(".00"),
   1000  1.1  christos 				/*
   1001  1.1  christos 				 * Not full octets.
   1002  1.1  christos 				 */
   1003  1.1  christos 				TEXT_INVALID("000"),
   1004  1.1  christos 				/*
   1005  1.1  christos 				 * E.164
   1006  1.1  christos 				 */
   1007  1.1  christos 				TEXT_VALID("+61200000000"),
   1008  1.1  christos 				/*
   1009  1.1  christos 				 * E.164 with periods
   1010  1.1  christos 				 */
   1011  1.1  christos 				TEXT_VALID_CHANGED("+61.2.0000.0000", "+6120000"
   1012  1.1  christos 								      "0000"),
   1013  1.1  christos 				/*
   1014  1.1  christos 				 * E.164 with period at end
   1015  1.1  christos 				 */
   1016  1.1  christos 				TEXT_INVALID("+61200000000."),
   1017  1.1  christos 				/*
   1018  1.1  christos 				 * E.164 with multiple consecutive periods
   1019  1.1  christos 				 */
   1020  1.1  christos 				TEXT_INVALID("+612..00000000"),
   1021  1.1  christos 				/*
   1022  1.1  christos 				 * E.164 with period before the leading digit.
   1023  1.1  christos 				 */
   1024  1.1  christos 				TEXT_INVALID("+.61200000000"),
   1025  1.1  christos 				/*
   1026  1.1  christos 				 * Sentinel.
   1027  1.1  christos 				 */
   1028  1.1  christos 				TEXT_SENTINEL() };
   1029  1.1  christos 	wire_ok_t wire_ok[] = {
   1030  1.1  christos 		/*
   1031  1.1  christos 		 * Too short.
   1032  1.1  christos 		 */
   1033  1.1  christos 		WIRE_INVALID(0x00), WIRE_INVALID(0x01),
   1034  1.1  christos 		/*
   1035  1.1  christos 		 * all digits
   1036  1.1  christos 		 */
   1037  1.1  christos 		WIRE_VALID(0x01, '6', '1', '2', '0', '0', '0'),
   1038  1.1  christos 		/*
   1039  1.1  christos 		 * non digit
   1040  1.1  christos 		 */
   1041  1.1  christos 		WIRE_INVALID(0x01, '+', '6', '1', '2', '0', '0', '0'),
   1042  1.1  christos 		/*
   1043  1.1  christos 		 * Sentinel.
   1044  1.1  christos 		 */
   1045  1.1  christos 		WIRE_SENTINEL()
   1046  1.1  christos 	};
   1047  1.1  christos 
   1048  1.1  christos 	check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
   1049  1.1  christos 		    dns_rdatatype_atma, sizeof(dns_rdata_in_atma_t));
   1050  1.1  christos }
   1051  1.1  christos 
   1052  1.1  christos /* AMTRELAY RDATA manipulations */
   1053  1.1  christos ISC_RUN_TEST_IMPL(amtrelay) {
   1054  1.1  christos 	text_ok_t text_ok[] = {
   1055  1.1  christos 		TEXT_INVALID(""), TEXT_INVALID("0"), TEXT_INVALID("0 0"),
   1056  1.1  christos 		/* gateway type 0 */
   1057  1.1  christos 		TEXT_VALID("0 0 0"), TEXT_VALID("0 1 0"),
   1058  1.1  christos 		TEXT_INVALID("0 2 0"),	 /* discovery out of range */
   1059  1.1  christos 		TEXT_VALID("255 1 0"),	 /* max precedence */
   1060  1.1  christos 		TEXT_INVALID("256 1 0"), /* precedence out of range */
   1061  1.1  christos 
   1062  1.1  christos 		/* IPv4 gateway */
   1063  1.1  christos 		TEXT_INVALID("0 0 1"), /* no address */
   1064  1.1  christos 		TEXT_VALID("0 0 1 0.0.0.0"),
   1065  1.1  christos 		TEXT_INVALID("0 0 1 0.0.0.0 x"), /* extra */
   1066  1.1  christos 		TEXT_INVALID("0 0 1 0.0.0.0.0"), /* bad address */
   1067  1.1  christos 		TEXT_INVALID("0 0 1 ::"),	 /* bad address */
   1068  1.1  christos 		TEXT_INVALID("0 0 1 ."),	 /* bad address */
   1069  1.1  christos 
   1070  1.1  christos 		/* IPv6 gateway */
   1071  1.1  christos 		TEXT_INVALID("0 0 2"), /* no address */
   1072  1.1  christos 		TEXT_VALID("0 0 2 ::"), TEXT_INVALID("0 0 2 :: xx"), /* extra */
   1073  1.1  christos 		TEXT_INVALID("0 0 2 0.0.0.0"), /* bad address */
   1074  1.1  christos 		TEXT_INVALID("0 0 2 ."),       /* bad address */
   1075  1.1  christos 
   1076  1.1  christos 		/* hostname gateway */
   1077  1.1  christos 		TEXT_INVALID("0 0 3"), /* no name */
   1078  1.1  christos 		/* IPv4 is a valid name */
   1079  1.1  christos 		TEXT_VALID_CHANGED("0 0 3 0.0.0.0", "0 0 3 0.0.0.0."),
   1080  1.1  christos 		/* IPv6 is a valid name */
   1081  1.1  christos 		TEXT_VALID_CHANGED("0 0 3 ::", "0 0 3 ::."),
   1082  1.1  christos 		TEXT_VALID_CHANGED("0 0 3 example", "0 0 3 example."),
   1083  1.1  christos 		TEXT_VALID("0 0 3 example."),
   1084  1.1  christos 		TEXT_INVALID("0 0 3 example. x"), /* extra */
   1085  1.1  christos 
   1086  1.1  christos 		/* unknown gateway */
   1087  1.1  christos 		TEXT_VALID("\\# 2 0004"), TEXT_VALID("\\# 2 0084"),
   1088  1.1  christos 		TEXT_VALID("\\# 2 007F"), TEXT_VALID("\\# 3 000400"),
   1089  1.1  christos 		TEXT_VALID("\\# 3 008400"), TEXT_VALID("\\# 3 00FF00"),
   1090  1.1  christos 
   1091  1.1  christos 		/*
   1092  1.1  christos 		 * Sentinel.
   1093  1.1  christos 		 */
   1094  1.1  christos 		TEXT_SENTINEL()
   1095  1.1  christos 	};
   1096  1.1  christos 	wire_ok_t wire_ok[] = {
   1097  1.1  christos 		WIRE_INVALID(0x00), WIRE_VALID(0x00, 0x00),
   1098  1.1  christos 		WIRE_VALID(0x00, 0x80), WIRE_INVALID(0x00, 0x00, 0x00),
   1099  1.1  christos 		WIRE_INVALID(0x00, 0x80, 0x00),
   1100  1.1  christos 
   1101  1.1  christos 		WIRE_INVALID(0x00, 0x01), WIRE_INVALID(0x00, 0x01, 0x00),
   1102  1.1  christos 		WIRE_INVALID(0x00, 0x01, 0x00, 0x00),
   1103  1.1  christos 		WIRE_INVALID(0x00, 0x01, 0x00, 0x00, 0x00),
   1104  1.1  christos 		WIRE_VALID(0x00, 0x01, 0x00, 0x00, 0x00, 0x00),
   1105  1.1  christos 		WIRE_INVALID(0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00),
   1106  1.1  christos 
   1107  1.1  christos 		WIRE_INVALID(0x00, 0x02), WIRE_INVALID(0x00, 0x02, 0x00),
   1108  1.1  christos 		WIRE_VALID(0x00, 0x02, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06,
   1109  1.1  christos 			   0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13, 0x14,
   1110  1.1  christos 			   0x15),
   1111  1.1  christos 		WIRE_INVALID(0x00, 0x02, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
   1112  1.1  christos 			     0x06, 0x07, 0x08, 0x09, 0x10, 0x11, 0x12, 0x13,
   1113  1.1  christos 			     0x14, 0x15, 0x16),
   1114  1.1  christos 
   1115  1.1  christos 		WIRE_INVALID(0x00, 0x03), WIRE_VALID(0x00, 0x03, 0x00),
   1116  1.1  christos 		WIRE_INVALID(0x00, 0x03, 0x00, 0x00), /* extra */
   1117  1.1  christos 
   1118  1.1  christos 		WIRE_VALID(0x00, 0x04), WIRE_VALID(0x00, 0x04, 0x00),
   1119  1.1  christos 		/*
   1120  1.1  christos 		 * Sentinel.
   1121  1.1  christos 		 */
   1122  1.1  christos 		WIRE_SENTINEL()
   1123  1.1  christos 	};
   1124  1.1  christos 
   1125  1.1  christos 	check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
   1126  1.1  christos 		    dns_rdatatype_amtrelay, sizeof(dns_rdata_amtrelay_t));
   1127  1.1  christos }
   1128  1.1  christos 
   1129  1.1  christos ISC_RUN_TEST_IMPL(cdnskey) {
   1130  1.1  christos 	key_required(state, dns_rdatatype_cdnskey, sizeof(dns_rdata_cdnskey_t));
   1131  1.1  christos }
   1132  1.1  christos 
   1133  1.1  christos /*
   1134  1.1  christos  * CSYNC tests.
   1135  1.1  christos  *
   1136  1.1  christos  * RFC 7477:
   1137  1.1  christos  *
   1138  1.1  christos  * 2.1.  The CSYNC Resource Record Format
   1139  1.1  christos  *
   1140  1.1  christos  * 2.1.1.  The CSYNC Resource Record Wire Format
   1141  1.1  christos  *
   1142  1.1  christos  *    The CSYNC RDATA consists of the following fields:
   1143  1.1  christos  *
   1144  1.1  christos  *                           1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
   1145  1.1  christos  *       0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   1146  1.1  christos  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1147  1.1  christos  *      |                          SOA Serial                           |
   1148  1.1  christos  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1149  1.1  christos  *      |       Flags                   |            Type Bit Map       /
   1150  1.1  christos  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1151  1.1  christos  *      /                     Type Bit Map (continued)                  /
   1152  1.1  christos  *      +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1153  1.1  christos  *
   1154  1.1  christos  * 2.1.1.1.  The SOA Serial Field
   1155  1.1  christos  *
   1156  1.1  christos  *    The SOA Serial field contains a copy of the 32-bit SOA serial number
   1157  1.1  christos  *    from the child zone.  If the soaminimum flag is set, parental agents
   1158  1.1  christos  *    querying children's authoritative servers MUST NOT act on data from
   1159  1.1  christos  *    zones advertising an SOA serial number less than this value.  See
   1160  1.1  christos  *    [RFC1982] for properly implementing "less than" logic.  If the
   1161  1.1  christos  *    soaminimum flag is not set, parental agents MUST ignore the value in
   1162  1.1  christos  *    the SOA Serial field.  Clients can set the field to any value if the
   1163  1.1  christos  *    soaminimum flag is unset, such as the number zero.
   1164  1.1  christos  *
   1165  1.1  christos  * (...)
   1166  1.1  christos  *
   1167  1.1  christos  * 2.1.1.2.  The Flags Field
   1168  1.1  christos  *
   1169  1.1  christos  *    The Flags field contains 16 bits of boolean flags that define
   1170  1.1  christos  *    operations that affect the processing of the CSYNC record.  The flags
   1171  1.1  christos  *    defined in this document are as follows:
   1172  1.1  christos  *
   1173  1.1  christos  *       0x00 0x01: "immediate"
   1174  1.1  christos  *
   1175  1.1  christos  *       0x00 0x02: "soaminimum"
   1176  1.1  christos  *
   1177  1.1  christos  *    The definitions for how the flags are to be used can be found in
   1178  1.1  christos  *    Section 3.
   1179  1.1  christos  *
   1180  1.1  christos  *    The remaining flags are reserved for use by future specifications.
   1181  1.1  christos  *    Undefined flags MUST be set to 0 by CSYNC publishers.  Parental
   1182  1.1  christos  *    agents MUST NOT process a CSYNC record if it contains a 1 value for a
   1183  1.1  christos  *    flag that is unknown to or unsupported by the parental agent.
   1184  1.1  christos  *
   1185  1.1  christos  * 2.1.1.2.1.  The Type Bit Map Field
   1186  1.1  christos  *
   1187  1.1  christos  *    The Type Bit Map field indicates the record types to be processed by
   1188  1.1  christos  *    the parental agent, according to the procedures in Section 3.  The
   1189  1.1  christos  *    Type Bit Map field is encoded in the same way as the Type Bit Map
   1190  1.1  christos  *    field of the NSEC record, described in [RFC4034], Section 4.1.2.  If
   1191  1.1  christos  *    a bit has been set that a parental agent implementation does not
   1192  1.1  christos  *    understand, the parental agent MUST NOT act upon the record.
   1193  1.1  christos  *    Specifically, a parental agent must not simply copy the data, and it
   1194  1.1  christos  *    must understand the semantics associated with a bit in the Type Bit
   1195  1.1  christos  *    Map field that has been set to 1.
   1196  1.1  christos  */
   1197  1.1  christos ISC_RUN_TEST_IMPL(csync) {
   1198  1.1  christos 	text_ok_t text_ok[] = { TEXT_INVALID(""),
   1199  1.1  christos 				TEXT_INVALID("0"),
   1200  1.1  christos 				TEXT_VALID("0 0"),
   1201  1.1  christos 				TEXT_VALID("0 0 A"),
   1202  1.1  christos 				TEXT_VALID("0 0 NS"),
   1203  1.1  christos 				TEXT_VALID("0 0 AAAA"),
   1204  1.1  christos 				TEXT_VALID("0 0 A AAAA"),
   1205  1.1  christos 				TEXT_VALID("0 0 A NS AAAA"),
   1206  1.1  christos 				TEXT_INVALID("0 0 A NS AAAA BOGUS"),
   1207  1.1  christos 				TEXT_SENTINEL() };
   1208  1.1  christos 	wire_ok_t wire_ok[] = {
   1209  1.1  christos 		/*
   1210  1.1  christos 		 * Short.
   1211  1.1  christos 		 */
   1212  1.1  christos 		WIRE_INVALID(0x00),
   1213  1.1  christos 		/*
   1214  1.1  christos 		 * Short.
   1215  1.1  christos 		 */
   1216  1.1  christos 		WIRE_INVALID(0x00, 0x00),
   1217  1.1  christos 		/*
   1218  1.1  christos 		 * Short.
   1219  1.1  christos 		 */
   1220  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00),
   1221  1.1  christos 		/*
   1222  1.1  christos 		 * Short.
   1223  1.1  christos 		 */
   1224  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x00),
   1225  1.1  christos 		/*
   1226  1.1  christos 		 * Short.
   1227  1.1  christos 		 */
   1228  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x00, 0x00),
   1229  1.1  christos 		/*
   1230  1.1  christos 		 * Serial + flags only.
   1231  1.1  christos 		 */
   1232  1.1  christos 		WIRE_VALID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
   1233  1.1  christos 		/*
   1234  1.1  christos 		 * Bad type map.
   1235  1.1  christos 		 */
   1236  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
   1237  1.1  christos 		/*
   1238  1.1  christos 		 * Bad type map.
   1239  1.1  christos 		 */
   1240  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
   1241  1.1  christos 		/*
   1242  1.1  christos 		 * Good type map.
   1243  1.1  christos 		 */
   1244  1.1  christos 		WIRE_VALID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
   1245  1.1  christos 			   0x02),
   1246  1.1  christos 		/*
   1247  1.1  christos 		 * Sentinel.
   1248  1.1  christos 		 */
   1249  1.1  christos 		WIRE_SENTINEL()
   1250  1.1  christos 	};
   1251  1.1  christos 
   1252  1.1  christos 	check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
   1253  1.1  christos 		    dns_rdatatype_csync, sizeof(dns_rdata_csync_t));
   1254  1.1  christos }
   1255  1.1  christos 
   1256  1.1  christos ISC_RUN_TEST_IMPL(dnskey) {
   1257  1.1  christos 	key_required(state, dns_rdatatype_dnskey, sizeof(dns_rdata_dnskey_t));
   1258  1.1  christos }
   1259  1.1  christos 
   1260  1.1  christos /*
   1261  1.1  christos  * DOA tests.
   1262  1.1  christos  *
   1263  1.1  christos  * draft-durand-doa-over-dns-03:
   1264  1.1  christos  *
   1265  1.1  christos  * 3.2.  DOA RDATA Wire Format
   1266  1.1  christos  *
   1267  1.1  christos  *        +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
   1268  1.1  christos  *     0: |                                                               |
   1269  1.1  christos  *        |                        DOA-ENTERPRISE                         |
   1270  1.1  christos  *        |                                                               |
   1271  1.1  christos  *        +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
   1272  1.1  christos  *     4: |                                                               |
   1273  1.1  christos  *        |                           DOA-TYPE                            |
   1274  1.1  christos  *        |                                                               |
   1275  1.1  christos  *        +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
   1276  1.1  christos  *     8: |         DOA-LOCATION          |         DOA-MEDIA-TYPE        /
   1277  1.1  christos  *        +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
   1278  1.1  christos  *    10: /                                                               /
   1279  1.1  christos  *        /                  DOA-MEDIA-TYPE (continued)                   /
   1280  1.1  christos  *        /                                                               /
   1281  1.1  christos  *        +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
   1282  1.1  christos  *        /                                                               /
   1283  1.1  christos  *        /                           DOA-DATA                            /
   1284  1.1  christos  *        /                                                               /
   1285  1.1  christos  *        +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
   1286  1.1  christos  *
   1287  1.1  christos  *    DOA-ENTERPRISE: a 32-bit unsigned integer in network order.
   1288  1.1  christos  *
   1289  1.1  christos  *    DOA-TYPE: a 32-bit unsigned integer in network order.
   1290  1.1  christos  *
   1291  1.1  christos  *    DOA-LOCATION: an 8-bit unsigned integer.
   1292  1.1  christos  *
   1293  1.1  christos  *    DOA-MEDIA-TYPE: A <character-string> (see [RFC1035]).  The first
   1294  1.1  christos  *    octet of the <character-string> contains the number of characters to
   1295  1.1  christos  *    follow.
   1296  1.1  christos  *
   1297  1.1  christos  *    DOA-DATA: A variable length blob of binary data.  The length of the
   1298  1.1  christos  *    DOA-DATA is not contained within the wire format of the RR and has to
   1299  1.1  christos  *    be computed from the RDLENGTH of the entire RR once other fields have
   1300  1.1  christos  *    been taken into account.
   1301  1.1  christos  *
   1302  1.1  christos  * 3.3.  DOA RDATA Presentation Format
   1303  1.1  christos  *
   1304  1.1  christos  *    The DOA-ENTERPRISE field is presented as an unsigned 32-bit decimal
   1305  1.1  christos  *    integer with range 0 - 4,294,967,295.
   1306  1.1  christos  *
   1307  1.1  christos  *    The DOA-TYPE field is presented as an unsigned 32-bit decimal integer
   1308  1.1  christos  *    with range 0 - 4,294,967,295.
   1309  1.1  christos  *
   1310  1.1  christos  *    The DOA-LOCATION field is presented as an unsigned 8-bit decimal
   1311  1.1  christos  *    integer with range 0 - 255.
   1312  1.1  christos  *
   1313  1.1  christos  *    The DOA-MEDIA-TYPE field is presented as a single <character-string>.
   1314  1.1  christos  *
   1315  1.1  christos  *    The DOA-DATA is presented as Base64 encoded data [RFC4648] unless the
   1316  1.1  christos  *    DOA-DATA is empty in which case it is presented as a single dash
   1317  1.1  christos  *    character ("-", ASCII 45).  White space is permitted within Base64
   1318  1.1  christos  *    data.
   1319  1.1  christos  */
   1320  1.1  christos ISC_RUN_TEST_IMPL(doa) {
   1321  1.1  christos 	text_ok_t text_ok[] = {
   1322  1.1  christos 		/*
   1323  1.1  christos 		 * Valid, non-empty DOA-DATA.
   1324  1.1  christos 		 */
   1325  1.1  christos 		TEXT_VALID("0 0 1 \"text/plain\" Zm9v"),
   1326  1.1  christos 		/*
   1327  1.1  christos 		 * Valid, non-empty DOA-DATA with whitespace in between.
   1328  1.1  christos 		 */
   1329  1.1  christos 		TEXT_VALID_CHANGED("0 0 1 \"text/plain\" Zm 9v", "0 0 1 "
   1330  1.1  christos 								 "\"text/"
   1331  1.1  christos 								 "plain\" "
   1332  1.1  christos 								 "Zm9v"),
   1333  1.1  christos 		/*
   1334  1.1  christos 		 * Valid, unquoted DOA-MEDIA-TYPE, non-empty DOA-DATA.
   1335  1.1  christos 		 */
   1336  1.1  christos 		TEXT_VALID_CHANGED("0 0 1 text/plain Zm9v", "0 0 1 "
   1337  1.1  christos 							    "\"text/plain\" "
   1338  1.1  christos 							    "Zm9v"),
   1339  1.1  christos 		/*
   1340  1.1  christos 		 * Invalid, quoted non-empty DOA-DATA.
   1341  1.1  christos 		 */
   1342  1.1  christos 		TEXT_INVALID("0 0 1 \"text/plain\" \"Zm9v\""),
   1343  1.1  christos 		/*
   1344  1.1  christos 		 * Valid, empty DOA-DATA.
   1345  1.1  christos 		 */
   1346  1.1  christos 		TEXT_VALID("0 0 1 \"text/plain\" -"),
   1347  1.1  christos 		/*
   1348  1.1  christos 		 * Invalid, quoted empty DOA-DATA.
   1349  1.1  christos 		 */
   1350  1.1  christos 		TEXT_INVALID("0 0 1 \"text/plain\" \"-\""),
   1351  1.1  christos 		/*
   1352  1.1  christos 		 * Invalid, missing "-" in empty DOA-DATA.
   1353  1.1  christos 		 */
   1354  1.1  christos 		TEXT_INVALID("0 0 1 \"text/plain\""),
   1355  1.1  christos 		/*
   1356  1.1  christos 		 * Valid, undefined DOA-LOCATION.
   1357  1.1  christos 		 */
   1358  1.1  christos 		TEXT_VALID("0 0 100 \"text/plain\" Zm9v"),
   1359  1.1  christos 		/*
   1360  1.1  christos 		 * Invalid, DOA-LOCATION too big.
   1361  1.1  christos 		 */
   1362  1.1  christos 		TEXT_INVALID("0 0 256 \"text/plain\" ZM9v"),
   1363  1.1  christos 		/*
   1364  1.1  christos 		 * Valid, empty DOA-MEDIA-TYPE, non-empty DOA-DATA.
   1365  1.1  christos 		 */
   1366  1.1  christos 		TEXT_VALID("0 0 2 \"\" aHR0cHM6Ly93d3cuaXNjLm9yZy8="),
   1367  1.1  christos 		/*
   1368  1.1  christos 		 * Valid, empty DOA-MEDIA-TYPE, empty DOA-DATA.
   1369  1.1  christos 		 */
   1370  1.1  christos 		TEXT_VALID("0 0 1 \"\" -"),
   1371  1.1  christos 		/*
   1372  1.1  christos 		 * Valid, DOA-MEDIA-TYPE with a space.
   1373  1.1  christos 		 */
   1374  1.1  christos 		TEXT_VALID("0 0 1 \"plain text\" Zm9v"),
   1375  1.1  christos 		/*
   1376  1.1  christos 		 * Invalid, missing DOA-MEDIA-TYPE.
   1377  1.1  christos 		 */
   1378  1.1  christos 		TEXT_INVALID("1234567890 1234567890 1"),
   1379  1.1  christos 		/*
   1380  1.1  christos 		 * Valid, DOA-DATA over 255 octets.
   1381  1.1  christos 		 */
   1382  1.1  christos 		TEXT_VALID("1234567890 1234567890 1 \"image/gif\" "
   1383  1.1  christos 			   "R0lGODlhKAAZAOMCAGZmZgBmmf///zOZzMz//5nM/zNmmWbM"
   1384  1.1  christos 			   "/5nMzMzMzACZ/////////////////////yH5BAEKAA8ALAAA"
   1385  1.1  christos 			   "AAAoABkAAATH8IFJK5U2a4337F5ogRkpnoCJrly7PrCKyh8c"
   1386  1.1  christos 			   "3HgAhzT35MDbbtO7/IJIHbGiOiaTxVTpSVWWLqNq1UVyapNS"
   1387  1.1  christos 			   "1wd3OAxug0LhnCubcVhsxysQnOt4ATpvvzHlFzl1AwODhWeF"
   1388  1.1  christos 			   "AgRpen5/UhheAYMFdUB4SFcpGEGGdQeCAqBBLTuSk30EeXd9"
   1389  1.1  christos 			   "pEsAbKGxjHqDSE0Sp6ixN4N1BJmbc7lIhmsBich1awPAjkY1"
   1390  1.1  christos 			   "SZR8bJWrz382SGqIBQQFQd4IsUTaX+ceuudPEQA7"),
   1391  1.1  christos 		/*
   1392  1.1  christos 		 * Invalid, bad Base64 in DOA-DATA.
   1393  1.1  christos 		 */
   1394  1.1  christos 		TEXT_INVALID("1234567890 1234567890 1 \"image/gif\" R0lGODl"),
   1395  1.1  christos 		/*
   1396  1.1  christos 		 * Sentinel.
   1397  1.1  christos 		 */
   1398  1.1  christos 		TEXT_SENTINEL()
   1399  1.1  christos 	};
   1400  1.1  christos 	wire_ok_t wire_ok[] = {
   1401  1.1  christos 		/*
   1402  1.1  christos 		 * Valid, empty DOA-MEDIA-TYPE, empty DOA-DATA.
   1403  1.1  christos 		 */
   1404  1.1  christos 		WIRE_VALID(0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x01,
   1405  1.1  christos 			   0x00),
   1406  1.1  christos 		/*
   1407  1.1  christos 		 * Invalid, missing DOA-MEDIA-TYPE.
   1408  1.1  christos 		 */
   1409  1.1  christos 		WIRE_INVALID(0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78,
   1410  1.1  christos 			     0x01),
   1411  1.1  christos 		/*
   1412  1.1  christos 		 * Invalid, malformed DOA-MEDIA-TYPE length.
   1413  1.1  christos 		 */
   1414  1.1  christos 		WIRE_INVALID(0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78,
   1415  1.1  christos 			     0x01, 0xff),
   1416  1.1  christos 		/*
   1417  1.1  christos 		 * Valid, empty DOA-DATA.
   1418  1.1  christos 		 */
   1419  1.1  christos 		WIRE_VALID(0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x01,
   1420  1.1  christos 			   0x03, 0x66, 0x6f, 0x6f),
   1421  1.1  christos 		/*
   1422  1.1  christos 		 * Valid, non-empty DOA-DATA.
   1423  1.1  christos 		 */
   1424  1.1  christos 		WIRE_VALID(0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x01,
   1425  1.1  christos 			   0x03, 0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72),
   1426  1.1  christos 		/*
   1427  1.1  christos 		 * Valid, DOA-DATA over 255 octets.
   1428  1.1  christos 		 */
   1429  1.1  christos 		WIRE_VALID(0x12, 0x34, 0x56, 0x78, 0x12, 0x34, 0x56, 0x78, 0x01,
   1430  1.1  christos 			   0x06, 0x62, 0x69, 0x6e, 0x61, 0x72, 0x79, 0x00, 0x66,
   1431  1.1  christos 			   0x99, 0xff, 0xff, 0xff, 0x33, 0x99, 0xcc, 0xcc, 0xff,
   1432  1.1  christos 			   0xff, 0x99, 0xcc, 0xff, 0x33, 0x66, 0x99, 0x66, 0xcc,
   1433  1.1  christos 			   0xff, 0x99, 0xcc, 0xcc, 0xcc, 0xcc, 0xcc, 0x00, 0x99,
   1434  1.1  christos 			   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
   1435  1.1  christos 			   0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x21, 0xf9,
   1436  1.1  christos 			   0x04, 0x01, 0x0a, 0x00, 0x0f, 0x00, 0x2c, 0x00, 0x00,
   1437  1.1  christos 			   0x00, 0x00, 0x28, 0x00, 0x19, 0x00, 0x00, 0x04, 0xc7,
   1438  1.1  christos 			   0xf0, 0x81, 0x49, 0x2b, 0x95, 0x36, 0x6b, 0x8d, 0xf7,
   1439  1.1  christos 			   0xec, 0x5e, 0x68, 0x81, 0x19, 0x29, 0x9e, 0x80, 0x89,
   1440  1.1  christos 			   0xae, 0x5c, 0xbb, 0x3e, 0xb0, 0x8a, 0xca, 0x1f, 0x1c,
   1441  1.1  christos 			   0xdc, 0x78, 0x00, 0x87, 0x34, 0xf7, 0xe4, 0xc0, 0xdb,
   1442  1.1  christos 			   0x6e, 0xd3, 0xbb, 0xfc, 0x82, 0x48, 0x1d, 0xb1, 0xa2,
   1443  1.1  christos 			   0x3a, 0x26, 0x93, 0xc5, 0x54, 0xe9, 0x49, 0x55, 0x96,
   1444  1.1  christos 			   0x2e, 0xa3, 0x6a, 0xd5, 0x45, 0x72, 0x6a, 0x93, 0x52,
   1445  1.1  christos 			   0xd7, 0x07, 0x77, 0x38, 0x0c, 0x6e, 0x83, 0x42, 0xe1,
   1446  1.1  christos 			   0x9c, 0x2b, 0x9b, 0x71, 0x58, 0x6c, 0xc7, 0x2b, 0x10,
   1447  1.1  christos 			   0x9c, 0xeb, 0x78, 0x01, 0x3a, 0x6f, 0xbf, 0x31, 0xe5,
   1448  1.1  christos 			   0x17, 0x39, 0x75, 0x03, 0x03, 0x83, 0x85, 0x67, 0x85,
   1449  1.1  christos 			   0x02, 0x04, 0x69, 0x7a, 0x7e, 0x7f, 0x52, 0x18, 0x5e,
   1450  1.1  christos 			   0x01, 0x83, 0x05, 0x75, 0x40, 0x78, 0x48, 0x57, 0x29,
   1451  1.1  christos 			   0x18, 0x41, 0x86, 0x75, 0x07, 0x82, 0x02, 0xa0, 0x41,
   1452  1.1  christos 			   0x2d, 0x3b, 0x92, 0x93, 0x7d, 0x04, 0x79, 0x77, 0x7d,
   1453  1.1  christos 			   0xa4, 0x4b, 0x00, 0x6c, 0xa1, 0xb1, 0x8c, 0x7a, 0x83,
   1454  1.1  christos 			   0x48, 0x4d, 0x12, 0xa7, 0xa8, 0xb1, 0x37, 0x83, 0x75,
   1455  1.1  christos 			   0x04, 0x99, 0x9b, 0x73, 0xb9, 0x48, 0x86, 0x6b, 0x01,
   1456  1.1  christos 			   0x89, 0xc8, 0x75, 0x6b, 0x03, 0xc0, 0x8e, 0x46, 0x35,
   1457  1.1  christos 			   0x49, 0x94, 0x7c, 0x6c, 0x95, 0xab, 0xcf, 0x7f, 0x36,
   1458  1.1  christos 			   0x48, 0x6a, 0x88, 0x05, 0x04, 0x05, 0x41, 0xde, 0x08,
   1459  1.1  christos 			   0xb1, 0x44, 0xda, 0x5f, 0xe7, 0x1e, 0xba, 0xe7, 0x4f,
   1460  1.1  christos 			   0x11, 0x00, 0x3b),
   1461  1.1  christos 		/*
   1462  1.1  christos 		 * Sentinel.
   1463  1.1  christos 		 */
   1464  1.1  christos 		WIRE_SENTINEL()
   1465  1.1  christos 	};
   1466  1.1  christos 
   1467  1.1  christos 	check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
   1468  1.1  christos 		    dns_rdatatype_doa, sizeof(dns_rdata_doa_t));
   1469  1.1  christos }
   1470  1.1  christos 
   1471  1.1  christos /*
   1472  1.1  christos  * DS tests.
   1473  1.1  christos  *
   1474  1.1  christos  * RFC 4034:
   1475  1.1  christos  *
   1476  1.1  christos  * 5.1.  DS RDATA Wire Format
   1477  1.1  christos  *
   1478  1.1  christos  *    The RDATA for a DS RR consists of a 2 octet Key Tag field, a 1 octet
   1479  1.1  christos  *    Algorithm field, a 1 octet Digest Type field, and a Digest field.
   1480  1.1  christos  *
   1481  1.1  christos  *                         1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
   1482  1.1  christos  *     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   1483  1.1  christos  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1484  1.1  christos  *    |           Key Tag             |  Algorithm    |  Digest Type  |
   1485  1.1  christos  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1486  1.1  christos  *    /                                                               /
   1487  1.1  christos  *    /                            Digest                             /
   1488  1.1  christos  *    /                                                               /
   1489  1.1  christos  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   1490  1.1  christos  *
   1491  1.1  christos  * 5.1.1.  The Key Tag Field
   1492  1.1  christos  *
   1493  1.1  christos  *    The Key Tag field lists the key tag of the DNSKEY RR referred to by
   1494  1.1  christos  *    the DS record, in network byte order.
   1495  1.1  christos  *
   1496  1.1  christos  *    The Key Tag used by the DS RR is identical to the Key Tag used by
   1497  1.1  christos  *    RRSIG RRs.  Appendix B describes how to compute a Key Tag.
   1498  1.1  christos  *
   1499  1.1  christos  * 5.1.2.  The Algorithm Field
   1500  1.1  christos  *
   1501  1.1  christos  *    The Algorithm field lists the algorithm number of the DNSKEY RR
   1502  1.1  christos  *    referred to by the DS record.
   1503  1.1  christos  *
   1504  1.1  christos  *    The algorithm number used by the DS RR is identical to the algorithm
   1505  1.1  christos  *    number used by RRSIG and DNSKEY RRs.  Appendix A.1 lists the
   1506  1.1  christos  *    algorithm number types.
   1507  1.1  christos  *
   1508  1.1  christos  * 5.1.3.  The Digest Type Field
   1509  1.1  christos  *
   1510  1.1  christos  *    The DS RR refers to a DNSKEY RR by including a digest of that DNSKEY
   1511  1.1  christos  *    RR.  The Digest Type field identifies the algorithm used to construct
   1512  1.1  christos  *    the digest.  Appendix A.2 lists the possible digest algorithm types.
   1513  1.1  christos  *
   1514  1.1  christos  * 5.1.4.  The Digest Field
   1515  1.1  christos  *
   1516  1.1  christos  *    The DS record refers to a DNSKEY RR by including a digest of that
   1517  1.1  christos  *    DNSKEY RR.
   1518  1.1  christos  *
   1519  1.1  christos  *    The digest is calculated by concatenating the canonical form of the
   1520  1.1  christos  *    fully qualified owner name of the DNSKEY RR with the DNSKEY RDATA,
   1521  1.1  christos  *    and then applying the digest algorithm.
   1522  1.1  christos  *
   1523  1.1  christos  *      digest = digest_algorithm( DNSKEY owner name | DNSKEY RDATA);
   1524  1.1  christos  *
   1525  1.1  christos  *       "|" denotes concatenation
   1526  1.1  christos  *
   1527  1.1  christos  *      DNSKEY RDATA = Flags | Protocol | Algorithm | Public Key.
   1528  1.1  christos  *
   1529  1.1  christos  *    The size of the digest may vary depending on the digest algorithm and
   1530  1.1  christos  *    DNSKEY RR size.  As of the time of this writing, the only defined
   1531  1.1  christos  *    digest algorithm is SHA-1, which produces a 20 octet digest.
   1532  1.1  christos  */
   1533  1.1  christos ISC_RUN_TEST_IMPL(ds) {
   1534  1.1  christos 	text_ok_t text_ok[] = {
   1535  1.1  christos 		/*
   1536  1.1  christos 		 * Invalid, empty record.
   1537  1.1  christos 		 */
   1538  1.1  christos 		TEXT_INVALID(""),
   1539  1.1  christos 		/*
   1540  1.1  christos 		 * Invalid, no algorithm.
   1541  1.1  christos 		 */
   1542  1.1  christos 		TEXT_INVALID("0"),
   1543  1.1  christos 		/*
   1544  1.1  christos 		 * Invalid, no digest type.
   1545  1.1  christos 		 */
   1546  1.1  christos 		TEXT_INVALID("0 0"),
   1547  1.1  christos 		/*
   1548  1.1  christos 		 * Invalid, no digest.
   1549  1.1  christos 		 */
   1550  1.1  christos 		TEXT_INVALID("0 0 0"),
   1551  1.1  christos 		/*
   1552  1.1  christos 		 * Valid, 1-octet digest for a reserved digest type.
   1553  1.1  christos 		 */
   1554  1.1  christos 		TEXT_VALID("0 0 0 00"),
   1555  1.1  christos 		/*
   1556  1.1  christos 		 * Invalid, short SHA-1 digest.
   1557  1.1  christos 		 */
   1558  1.1  christos 		TEXT_INVALID("0 0 1 00"),
   1559  1.1  christos 		TEXT_INVALID("0 0 1 4FDCE83016EDD29077621FE568F8DADDB5809B"),
   1560  1.1  christos 		/*
   1561  1.1  christos 		 * Valid, 20-octet SHA-1 digest.
   1562  1.1  christos 		 */
   1563  1.1  christos 		TEXT_VALID("0 0 1 4FDCE83016EDD29077621FE568F8DADDB5809B6A"),
   1564  1.1  christos 		/*
   1565  1.1  christos 		 * Invalid, excessively long SHA-1 digest.
   1566  1.1  christos 		 */
   1567  1.1  christos 		TEXT_INVALID("0 0 1 4FDCE83016EDD29077621FE568F8DADDB5809B"
   1568  1.1  christos 			     "6A00"),
   1569  1.1  christos 		/*
   1570  1.1  christos 		 * Invalid, short SHA-256 digest.
   1571  1.1  christos 		 */
   1572  1.1  christos 		TEXT_INVALID("0 0 2 00"),
   1573  1.1  christos 		TEXT_INVALID("0 0 2 D001BD422FFDA9B745425B71DC17D007E69186"
   1574  1.1  christos 			     "9BD59C5F237D9BF85434C313"),
   1575  1.1  christos 		/*
   1576  1.1  christos 		 * Valid, 32-octet SHA-256 digest.
   1577  1.1  christos 		 */
   1578  1.1  christos 		TEXT_VALID_CHANGED("0 0 2 "
   1579  1.1  christos 				   "D001BD422FFDA9B745425B71DC17D007E691869B"
   1580  1.1  christos 				   "D59C5F237D9BF85434C3133F",
   1581  1.1  christos 				   "0 0 2 "
   1582  1.1  christos 				   "D001BD422FFDA9B745425B71DC17D007E691869B"
   1583  1.1  christos 				   "D59C5F237D9BF854 34C3133F"),
   1584  1.1  christos 		/*
   1585  1.1  christos 		 * Invalid, excessively long SHA-256 digest.
   1586  1.1  christos 		 */
   1587  1.1  christos 		TEXT_INVALID("0 0 2 D001BD422FFDA9B745425B71DC17D007E69186"
   1588  1.1  christos 			     "9BD59C5F237D9BF85434C3133F00"),
   1589  1.1  christos 		/*
   1590  1.1  christos 		 * Valid, GOST is no longer supported, hence no length checks.
   1591  1.1  christos 		 */
   1592  1.1  christos 		TEXT_VALID("0 0 3 00"),
   1593  1.1  christos 		/*
   1594  1.1  christos 		 * Invalid, short SHA-384 digest.
   1595  1.1  christos 		 */
   1596  1.1  christos 		TEXT_INVALID("0 0 4 00"),
   1597  1.1  christos 		TEXT_INVALID("0 0 4 AC748D6C5AA652904A8763D64B7DFFFFA98152"
   1598  1.1  christos 			     "BE12128D238BEBB4814B648F5A841E15CAA2DE348891"
   1599  1.1  christos 			     "A37A699F65E5"),
   1600  1.1  christos 		/*
   1601  1.1  christos 		 * Valid, 48-octet SHA-384 digest.
   1602  1.1  christos 		 */
   1603  1.1  christos 		TEXT_VALID_CHANGED("0 0 4 "
   1604  1.1  christos 				   "AC748D6C5AA652904A8763D64B7DFFFFA98152BE"
   1605  1.1  christos 				   "12128D238BEBB4814B648F5A841E15CAA2DE348891A"
   1606  1.1  christos 				   "37A"
   1607  1.1  christos 				   "699F65E54D",
   1608  1.1  christos 				   "0 0 4 "
   1609  1.1  christos 				   "AC748D6C5AA652904A8763D64B7DFFFFA98152BE"
   1610  1.1  christos 				   "12128D238BEBB481 "
   1611  1.1  christos 				   "4B648F5A841E15CAA2DE348891A37A"
   1612  1.1  christos 				   "699F65E54D"),
   1613  1.1  christos 		/*
   1614  1.1  christos 		 * Invalid, excessively long SHA-384 digest.
   1615  1.1  christos 		 */
   1616  1.1  christos 		TEXT_INVALID("0 0 4 AC748D6C5AA652904A8763D64B7DFFFFA98152"
   1617  1.1  christos 			     "BE12128D238BEBB4814B648F5A841E15CAA2DE348891"
   1618  1.1  christos 			     "A37A699F65E54D00"),
   1619  1.1  christos 		/*
   1620  1.1  christos 		 * Valid, 1-octet digest for an unassigned digest type.
   1621  1.1  christos 		 */
   1622  1.1  christos 		TEXT_VALID("0 0 5 00"),
   1623  1.1  christos 		/*
   1624  1.1  christos 		 * Sentinel.
   1625  1.1  christos 		 */
   1626  1.1  christos 		TEXT_SENTINEL()
   1627  1.1  christos 	};
   1628  1.1  christos 	wire_ok_t wire_ok[] = {
   1629  1.1  christos 		/*
   1630  1.1  christos 		 * Invalid, truncated key tag.
   1631  1.1  christos 		 */
   1632  1.1  christos 		WIRE_INVALID(0x00),
   1633  1.1  christos 		/*
   1634  1.1  christos 		 * Invalid, no algorithm.
   1635  1.1  christos 		 */
   1636  1.1  christos 		WIRE_INVALID(0x00, 0x00),
   1637  1.1  christos 		/*
   1638  1.1  christos 		 * Invalid, no digest type.
   1639  1.1  christos 		 */
   1640  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00),
   1641  1.1  christos 		/*
   1642  1.1  christos 		 * Invalid, no digest.
   1643  1.1  christos 		 */
   1644  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x00),
   1645  1.1  christos 		/*
   1646  1.1  christos 		 * Valid, 1-octet digest for a reserved digest type.
   1647  1.1  christos 		 */
   1648  1.1  christos 		WIRE_VALID(0x00, 0x00, 0x00, 0x00, 0x00),
   1649  1.1  christos 		/*
   1650  1.1  christos 		 * Invalid, short SHA-1 digest.
   1651  1.1  christos 		 */
   1652  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x01, 0x00),
   1653  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x01, 0x4F, 0xDC, 0xE8, 0x30,
   1654  1.1  christos 			     0x16, 0xED, 0xD2, 0x90, 0x77, 0x62, 0x1F, 0xE5,
   1655  1.1  christos 			     0x68, 0xF8, 0xDA, 0xDD, 0xB5, 0x80, 0x9B),
   1656  1.1  christos 		/*
   1657  1.1  christos 		 * Valid, 20-octet SHA-1 digest.
   1658  1.1  christos 		 */
   1659  1.1  christos 		WIRE_VALID(0x00, 0x00, 0x00, 0x01, 0x4F, 0xDC, 0xE8, 0x30, 0x16,
   1660  1.1  christos 			   0xED, 0xD2, 0x90, 0x77, 0x62, 0x1F, 0xE5, 0x68, 0xF8,
   1661  1.1  christos 			   0xDA, 0xDD, 0xB5, 0x80, 0x9B, 0x6A),
   1662  1.1  christos 		/*
   1663  1.1  christos 		 * Invalid, excessively long SHA-1 digest.
   1664  1.1  christos 		 */
   1665  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x01, 0x4F, 0xDC, 0xE8, 0x30,
   1666  1.1  christos 			     0x16, 0xED, 0xD2, 0x90, 0x77, 0x62, 0x1F, 0xE5,
   1667  1.1  christos 			     0x68, 0xF8, 0xDA, 0xDD, 0xB5, 0x80, 0x9B, 0x6A,
   1668  1.1  christos 			     0x00),
   1669  1.1  christos 		/*
   1670  1.1  christos 		 * Invalid, short SHA-256 digest.
   1671  1.1  christos 		 */
   1672  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x02, 0x00),
   1673  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x02, 0xD0, 0x01, 0xBD, 0x42,
   1674  1.1  christos 			     0x2F, 0xFD, 0xA9, 0xB7, 0x45, 0x42, 0x5B, 0x71,
   1675  1.1  christos 			     0xDC, 0x17, 0xD0, 0x07, 0xE6, 0x91, 0x86, 0x9B,
   1676  1.1  christos 			     0xD5, 0x9C, 0x5F, 0x23, 0x7D, 0x9B, 0xF8, 0x54,
   1677  1.1  christos 			     0x34, 0xC3, 0x13),
   1678  1.1  christos 		/*
   1679  1.1  christos 		 * Valid, 32-octet SHA-256 digest.
   1680  1.1  christos 		 */
   1681  1.1  christos 		WIRE_VALID(0x00, 0x00, 0x00, 0x02, 0xD0, 0x01, 0xBD, 0x42, 0x2F,
   1682  1.1  christos 			   0xFD, 0xA9, 0xB7, 0x45, 0x42, 0x5B, 0x71, 0xDC, 0x17,
   1683  1.1  christos 			   0xD0, 0x07, 0xE6, 0x91, 0x86, 0x9B, 0xD5, 0x9C, 0x5F,
   1684  1.1  christos 			   0x23, 0x7D, 0x9B, 0xF8, 0x54, 0x34, 0xC3, 0x13,
   1685  1.1  christos 			   0x3F),
   1686  1.1  christos 		/*
   1687  1.1  christos 		 * Invalid, excessively long SHA-256 digest.
   1688  1.1  christos 		 */
   1689  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x02, 0xD0, 0x01, 0xBD, 0x42,
   1690  1.1  christos 			     0x2F, 0xFD, 0xA9, 0xB7, 0x45, 0x42, 0x5B, 0x71,
   1691  1.1  christos 			     0xDC, 0x17, 0xD0, 0x07, 0xE6, 0x91, 0x86, 0x9B,
   1692  1.1  christos 			     0xD5, 0x9C, 0x5F, 0x23, 0x7D, 0x9B, 0xF8, 0x54,
   1693  1.1  christos 			     0x34, 0xC3, 0x13, 0x3F, 0x00),
   1694  1.1  christos 		/*
   1695  1.1  christos 		 * Valid, GOST is no longer supported, hence no length checks.
   1696  1.1  christos 		 */
   1697  1.1  christos 		WIRE_VALID(0x00, 0x00, 0x00, 0x03, 0x00),
   1698  1.1  christos 		/*
   1699  1.1  christos 		 * Invalid, short SHA-384 digest.
   1700  1.1  christos 		 */
   1701  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x04, 0x00),
   1702  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x04, 0xAC, 0x74, 0x8D, 0x6C,
   1703  1.1  christos 			     0x5A, 0xA6, 0x52, 0x90, 0x4A, 0x87, 0x63, 0xD6,
   1704  1.1  christos 			     0x4B, 0x7D, 0xFF, 0xFF, 0xA9, 0x81, 0x52, 0xBE,
   1705  1.1  christos 			     0x12, 0x12, 0x8D, 0x23, 0x8B, 0xEB, 0xB4, 0x81,
   1706  1.1  christos 			     0x4B, 0x64, 0x8F, 0x5A, 0x84, 0x1E, 0x15, 0xCA,
   1707  1.1  christos 			     0xA2, 0xDE, 0x34, 0x88, 0x91, 0xA3, 0x7A, 0x69,
   1708  1.1  christos 			     0x9F, 0x65, 0xE5),
   1709  1.1  christos 		/*
   1710  1.1  christos 		 * Valid, 48-octet SHA-384 digest.
   1711  1.1  christos 		 */
   1712  1.1  christos 		WIRE_VALID(0x00, 0x00, 0x00, 0x04, 0xAC, 0x74, 0x8D, 0x6C, 0x5A,
   1713  1.1  christos 			   0xA6, 0x52, 0x90, 0x4A, 0x87, 0x63, 0xD6, 0x4B, 0x7D,
   1714  1.1  christos 			   0xFF, 0xFF, 0xA9, 0x81, 0x52, 0xBE, 0x12, 0x12, 0x8D,
   1715  1.1  christos 			   0x23, 0x8B, 0xEB, 0xB4, 0x81, 0x4B, 0x64, 0x8F, 0x5A,
   1716  1.1  christos 			   0x84, 0x1E, 0x15, 0xCA, 0xA2, 0xDE, 0x34, 0x88, 0x91,
   1717  1.1  christos 			   0xA3, 0x7A, 0x69, 0x9F, 0x65, 0xE5, 0x4D),
   1718  1.1  christos 		/*
   1719  1.1  christos 		 * Invalid, excessively long SHA-384 digest.
   1720  1.1  christos 		 */
   1721  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x04, 0xAC, 0x74, 0x8D, 0x6C,
   1722  1.1  christos 			     0x5A, 0xA6, 0x52, 0x90, 0x4A, 0x87, 0x63, 0xD6,
   1723  1.1  christos 			     0x4B, 0x7D, 0xFF, 0xFF, 0xA9, 0x81, 0x52, 0xBE,
   1724  1.1  christos 			     0x12, 0x12, 0x8D, 0x23, 0x8B, 0xEB, 0xB4, 0x81,
   1725  1.1  christos 			     0x4B, 0x64, 0x8F, 0x5A, 0x84, 0x1E, 0x15, 0xCA,
   1726  1.1  christos 			     0xA2, 0xDE, 0x34, 0x88, 0x91, 0xA3, 0x7A, 0x69,
   1727  1.1  christos 			     0x9F, 0x65, 0xE5, 0x4D, 0x00),
   1728  1.1  christos 		WIRE_VALID(0x00, 0x00, 0x04, 0x00, 0x00),
   1729  1.1  christos 		/*
   1730  1.1  christos 		 * Sentinel.
   1731  1.1  christos 		 */
   1732  1.1  christos 		WIRE_SENTINEL()
   1733  1.1  christos 	};
   1734  1.1  christos 
   1735  1.1  christos 	check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
   1736  1.1  christos 		    dns_rdatatype_ds, sizeof(dns_rdata_ds_t));
   1737  1.1  christos }
   1738  1.1  christos 
   1739  1.1  christos /*
   1740  1.1  christos  * EDNS Client Subnet tests.
   1741  1.1  christos  *
   1742  1.1  christos  * RFC 7871:
   1743  1.1  christos  *
   1744  1.1  christos  * 6.  Option Format
   1745  1.1  christos  *
   1746  1.1  christos  *    This protocol uses an EDNS0 [RFC6891] option to include client
   1747  1.1  christos  *    address information in DNS messages.  The option is structured as
   1748  1.1  christos  *    follows:
   1749  1.1  christos  *
   1750  1.1  christos  *                 +0 (MSB)                            +1 (LSB)
   1751  1.1  christos  *       +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
   1752  1.1  christos  *    0: |                          OPTION-CODE                          |
   1753  1.1  christos  *       +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
   1754  1.1  christos  *    2: |                         OPTION-LENGTH                         |
   1755  1.1  christos  *       +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
   1756  1.1  christos  *    4: |                            FAMILY                             |
   1757  1.1  christos  *       +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
   1758  1.1  christos  *    6: |     SOURCE PREFIX-LENGTH      |     SCOPE PREFIX-LENGTH       |
   1759  1.1  christos  *       +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
   1760  1.1  christos  *    8: |                           ADDRESS...                          /
   1761  1.1  christos  *       +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
   1762  1.1  christos  *
   1763  1.1  christos  *    o  (Defined in [RFC6891]) OPTION-CODE, 2 octets, for ECS is 8 (0x00
   1764  1.1  christos  *       0x08).
   1765  1.1  christos  *
   1766  1.1  christos  *    o  (Defined in [RFC6891]) OPTION-LENGTH, 2 octets, contains the
   1767  1.1  christos  *       length of the payload (everything after OPTION-LENGTH) in octets.
   1768  1.1  christos  *
   1769  1.1  christos  *    o  FAMILY, 2 octets, indicates the family of the address contained in
   1770  1.1  christos  *       the option, using address family codes as assigned by IANA in
   1771  1.1  christos  *       Address Family Numbers [Address_Family_Numbers].
   1772  1.1  christos  *
   1773  1.1  christos  *    The format of the address part depends on the value of FAMILY.  This
   1774  1.1  christos  *    document only defines the format for FAMILY 1 (IPv4) and FAMILY 2
   1775  1.1  christos  *    (IPv6), which are as follows:
   1776  1.1  christos  *
   1777  1.1  christos  *    o  SOURCE PREFIX-LENGTH, an unsigned octet representing the leftmost
   1778  1.1  christos  *       number of significant bits of ADDRESS to be used for the lookup.
   1779  1.1  christos  *       In responses, it mirrors the same value as in the queries.
   1780  1.1  christos  *
   1781  1.1  christos  *    o  SCOPE PREFIX-LENGTH, an unsigned octet representing the leftmost
   1782  1.1  christos  *       number of significant bits of ADDRESS that the response covers.
   1783  1.1  christos  *       In queries, it MUST be set to 0.
   1784  1.1  christos  *
   1785  1.1  christos  *    o  ADDRESS, variable number of octets, contains either an IPv4 or
   1786  1.1  christos  *       IPv6 address, depending on FAMILY, which MUST be truncated to the
   1787  1.1  christos  *       number of bits indicated by the SOURCE PREFIX-LENGTH field,
   1788  1.1  christos  *       padding with 0 bits to pad to the end of the last octet needed.
   1789  1.1  christos  *
   1790  1.1  christos  *    o  A server receiving an ECS option that uses either too few or too
   1791  1.1  christos  *       many ADDRESS octets, or that has non-zero ADDRESS bits set beyond
   1792  1.1  christos  *       SOURCE PREFIX-LENGTH, SHOULD return FORMERR to reject the packet,
   1793  1.1  christos  *       as a signal to the software developer making the request to fix
   1794  1.1  christos  *       their implementation.
   1795  1.1  christos  *
   1796  1.1  christos  *    All fields are in network byte order ("big-endian", per [RFC1700],
   1797  1.1  christos  *    Data Notation).
   1798  1.1  christos  */
   1799  1.1  christos ISC_RUN_TEST_IMPL(edns_client_subnet) {
   1800  1.1  christos 	wire_ok_t wire_ok[] = {
   1801  1.1  christos 		/*
   1802  1.1  christos 		 * Option code with no content.
   1803  1.1  christos 		 */
   1804  1.1  christos 		WIRE_INVALID(0x00, 0x08, 0x00, 0x00),
   1805  1.1  christos 		/*
   1806  1.1  christos 		 * Option code family 0, source 0, scope 0.
   1807  1.1  christos 		 */
   1808  1.1  christos 		WIRE_VALID(0x00, 0x08, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00),
   1809  1.1  christos 		/*
   1810  1.1  christos 		 * Option code family 1 (IPv4), source 0, scope 0.
   1811  1.1  christos 		 */
   1812  1.1  christos 		WIRE_VALID(0x00, 0x08, 0x00, 0x04, 0x00, 0x01, 0x00, 0x00),
   1813  1.1  christos 		/*
   1814  1.1  christos 		 * Option code family 2 (IPv6) , source 0, scope 0.
   1815  1.1  christos 		 */
   1816  1.1  christos 		WIRE_VALID(0x00, 0x08, 0x00, 0x04, 0x00, 0x02, 0x00, 0x00),
   1817  1.1  christos 		/*
   1818  1.1  christos 		 * Extra octet.
   1819  1.1  christos 		 */
   1820  1.1  christos 		WIRE_INVALID(0x00, 0x08, 0x00, 0x05, 0x00, 0x00, 0x00, 0x00,
   1821  1.1  christos 			     0x00),
   1822  1.1  christos 		/*
   1823  1.1  christos 		 * Source too long for IPv4.
   1824  1.1  christos 		 */
   1825  1.1  christos 		WIRE_INVALID(0x00, 0x08, 0x00, 8, 0x00, 0x01, 33, 0x00, 0x00,
   1826  1.1  christos 			     0x00, 0x00, 0x00),
   1827  1.1  christos 		/*
   1828  1.1  christos 		 * Source too long for IPv6.
   1829  1.1  christos 		 */
   1830  1.1  christos 		WIRE_INVALID(0x00, 0x08, 0x00, 20, 0x00, 0x02, 129, 0x00, 0x00,
   1831  1.1  christos 			     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1832  1.1  christos 			     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
   1833  1.1  christos 		/*
   1834  1.1  christos 		 * Scope too long for IPv4.
   1835  1.1  christos 		 */
   1836  1.1  christos 		WIRE_INVALID(0x00, 0x08, 0x00, 8, 0x00, 0x01, 0x00, 33, 0x00,
   1837  1.1  christos 			     0x00, 0x00, 0x00),
   1838  1.1  christos 		/*
   1839  1.1  christos 		 * Scope too long for IPv6.
   1840  1.1  christos 		 */
   1841  1.1  christos 		WIRE_INVALID(0x00, 0x08, 0x00, 20, 0x00, 0x02, 0x00, 129, 0x00,
   1842  1.1  christos 			     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1843  1.1  christos 			     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
   1844  1.1  christos 		/*
   1845  1.1  christos 		 * When family=0, source and scope should be 0.
   1846  1.1  christos 		 */
   1847  1.1  christos 		WIRE_VALID(0x00, 0x08, 0x00, 4, 0x00, 0x00, 0x00, 0x00),
   1848  1.1  christos 		/*
   1849  1.1  christos 		 * When family=0, source and scope should be 0.
   1850  1.1  christos 		 */
   1851  1.1  christos 		WIRE_INVALID(0x00, 0x08, 0x00, 5, 0x00, 0x00, 0x01, 0x00, 0x00),
   1852  1.1  christos 		/*
   1853  1.1  christos 		 * When family=0, source and scope should be 0.
   1854  1.1  christos 		 */
   1855  1.1  christos 		WIRE_INVALID(0x00, 0x08, 0x00, 5, 0x00, 0x00, 0x00, 0x01, 0x00),
   1856  1.1  christos 		/*
   1857  1.1  christos 		 * Length too short for source IPv4.
   1858  1.1  christos 		 */
   1859  1.1  christos 		WIRE_INVALID(0x00, 0x08, 0x00, 7, 0x00, 0x01, 32, 0x00, 0x00,
   1860  1.1  christos 			     0x00, 0x00),
   1861  1.1  christos 		/*
   1862  1.1  christos 		 * Length too short for source IPv6.
   1863  1.1  christos 		 */
   1864  1.1  christos 		WIRE_INVALID(0x00, 0x08, 0x00, 19, 0x00, 0x02, 128, 0x00, 0x00,
   1865  1.1  christos 			     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   1866  1.1  christos 			     0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
   1867  1.1  christos 		/*
   1868  1.1  christos 		 * Sentinel.
   1869  1.1  christos 		 */
   1870  1.1  christos 		WIRE_SENTINEL()
   1871  1.1  christos 	};
   1872  1.1  christos 
   1873  1.1  christos 	check_rdata(NULL, wire_ok, NULL, true, dns_rdataclass_in,
   1874  1.1  christos 		    dns_rdatatype_opt, sizeof(dns_rdata_opt_t));
   1875  1.1  christos }
   1876  1.1  christos 
   1877  1.1  christos /*
   1878  1.1  christos  * http://ana-3.lcs.mit.edu/~jnc/nimrod/dns.txt
   1879  1.1  christos  *
   1880  1.1  christos  * The RDATA portion of both the NIMLOC and EID records contains
   1881  1.1  christos  * uninterpreted binary data.  The representation in the text master file
   1882  1.1  christos  * is an even number of hex characters (0 to 9, a to f), case is not
   1883  1.1  christos  * significant.  For readability, whitespace may be included in the value
   1884  1.1  christos  * field and should be ignored when reading a master file.
   1885  1.1  christos  */
   1886  1.1  christos ISC_RUN_TEST_IMPL(eid) {
   1887  1.1  christos 	text_ok_t text_ok[] = { TEXT_VALID("AABBCC"),
   1888  1.1  christos 				TEXT_VALID_CHANGED("AA bb cc", "AABBCC"),
   1889  1.1  christos 				TEXT_INVALID("aab"),
   1890  1.1  christos 				/*
   1891  1.1  christos 				 * Sentinel.
   1892  1.1  christos 				 */
   1893  1.1  christos 				TEXT_SENTINEL() };
   1894  1.1  christos 	wire_ok_t wire_ok[] = { WIRE_VALID(0x00), WIRE_VALID(0xAA, 0xBB, 0xCC),
   1895  1.1  christos 				/*
   1896  1.1  christos 				 * Sentinel.
   1897  1.1  christos 				 */
   1898  1.1  christos 				WIRE_SENTINEL() };
   1899  1.1  christos 
   1900  1.1  christos 	check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
   1901  1.1  christos 		    dns_rdatatype_eid, sizeof(dns_rdata_in_eid_t));
   1902  1.1  christos }
   1903  1.1  christos 
   1904  1.1  christos /*
   1905  1.1  christos  * test that an oversized HIP record will be rejected
   1906  1.1  christos  */
   1907  1.1  christos ISC_RUN_TEST_IMPL(hip) {
   1908  1.1  christos 	text_ok_t text_ok[] = {
   1909  1.1  christos 		/* RFC 8005 examples. */
   1910  1.1  christos 		TEXT_VALID_LOOP(0, "2 200100107B1A74DF365639CC39F1D578 "
   1911  1.1  christos 				   "AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cI"
   1912  1.1  christos 				   "vM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbW"
   1913  1.1  christos 				   "Iy87UOoJTwkUs7lBu+Upr1gsNrut79ryra+b"
   1914  1.1  christos 				   "SRGQb1slImA8YVJyuIDsj7kwzG7jnERNqnWx"
   1915  1.1  christos 				   "Z48AWkskmdHaVDP4BcelrTI3rMXdXF5D"),
   1916  1.1  christos 		TEXT_VALID_LOOP(1, "2 200100107B1A74DF365639CC39F1D578 "
   1917  1.1  christos 				   "AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cI"
   1918  1.1  christos 				   "vM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbW"
   1919  1.1  christos 				   "Iy87UOoJTwkUs7lBu+Upr1gsNrut79ryra+b"
   1920  1.1  christos 				   "SRGQb1slImA8YVJyuIDsj7kwzG7jnERNqnWx"
   1921  1.1  christos 				   "Z48AWkskmdHaVDP4BcelrTI3rMXdXF5D "
   1922  1.1  christos 				   "rvs1.example.com."),
   1923  1.1  christos 		TEXT_VALID_LOOP(2, "2 200100107B1A74DF365639CC39F1D578 "
   1924  1.1  christos 				   "AwEAAbdxyhNuSutc5EMzxTs9LBPCIkOFH8cI"
   1925  1.1  christos 				   "vM4p9+LrV4e19WzK00+CI6zBCQTdtWsuxKbW"
   1926  1.1  christos 				   "Iy87UOoJTwkUs7lBu+Upr1gsNrut79ryra+b"
   1927  1.1  christos 				   "SRGQb1slImA8YVJyuIDsj7kwzG7jnERNqnWx"
   1928  1.1  christos 				   "Z48AWkskmdHaVDP4BcelrTI3rMXdXF5D "
   1929  1.1  christos 				   "rvs1.example.com. rvs2.example.com."),
   1930  1.1  christos 		/*
   1931  1.1  christos 		 * Sentinel.
   1932  1.1  christos 		 */
   1933  1.1  christos 		TEXT_SENTINEL()
   1934  1.1  christos 	};
   1935  1.1  christos 	unsigned char hipwire[DNS_RDATA_MAXLENGTH] = { 0x01, 0x00, 0x00, 0x01,
   1936  1.1  christos 						       0x00, 0x00, 0x04, 0x41,
   1937  1.1  christos 						       0x42, 0x43, 0x44, 0x00 };
   1938  1.1  christos 	unsigned char buf[1024 * 1024];
   1939  1.1  christos 	dns_rdata_t rdata = DNS_RDATA_INIT;
   1940  1.1  christos 	isc_result_t result;
   1941  1.1  christos 	size_t i;
   1942  1.1  christos 
   1943  1.1  christos 	/*
   1944  1.1  christos 	 * Fill the rest of input buffer with compression pointers.
   1945  1.1  christos 	 */
   1946  1.1  christos 	for (i = 12; i < sizeof(hipwire) - 2; i += 2) {
   1947  1.1  christos 		hipwire[i] = 0xc0;
   1948  1.1  christos 		hipwire[i + 1] = 0x06;
   1949  1.1  christos 	}
   1950  1.1  christos 
   1951  1.1  christos 	result = wire_to_rdata(hipwire, sizeof(hipwire), dns_rdataclass_in,
   1952  1.1  christos 			       dns_rdatatype_hip, buf, sizeof(buf), &rdata);
   1953  1.1  christos 	assert_int_equal(result, DNS_R_FORMERR);
   1954  1.1  christos 	check_text_ok(text_ok, dns_rdataclass_in, dns_rdatatype_hip,
   1955  1.1  christos 		      sizeof(dns_rdata_hip_t));
   1956  1.1  christos }
   1957  1.1  christos 
   1958  1.1  christos /*
   1959  1.1  christos  * ISDN tests.
   1960  1.1  christos  *
   1961  1.1  christos  * RFC 1183:
   1962  1.1  christos  *
   1963  1.1  christos  * 3.2. The ISDN RR
   1964  1.1  christos  *
   1965  1.1  christos  *    The ISDN RR is defined with mnemonic ISDN and type code 20 (decimal).
   1966  1.1  christos  *
   1967  1.1  christos  *    An ISDN (Integrated Service Digital Network) number is simply a
   1968  1.1  christos  *    telephone number.  The intent of the members of the CCITT is to
   1969  1.1  christos  *    upgrade all telephone and data network service to a common service.
   1970  1.1  christos  *
   1971  1.1  christos  *    The numbering plan (E.163/E.164) is the same as the familiar
   1972  1.1  christos  *    international plan for POTS (an un-official acronym, meaning Plain
   1973  1.1  christos  *    Old Telephone Service).  In E.166, CCITT says "An E.163/E.164
   1974  1.1  christos  *    telephony subscriber may become an ISDN subscriber without a number
   1975  1.1  christos  *    change."
   1976  1.1  christos  *
   1977  1.1  christos  *    ISDN has the following format:
   1978  1.1  christos  *
   1979  1.1  christos  *    <owner> <ttl> <class> ISDN <ISDN-address> <sa>
   1980  1.1  christos  *
   1981  1.1  christos  *    The <ISDN-address> field is required; <sa> is optional.
   1982  1.1  christos  *
   1983  1.1  christos  *    <ISDN-address> identifies the ISDN number of <owner> and DDI (Direct
   1984  1.1  christos  *    Dial In) if any, as defined by E.164 [8] and E.163 [7], the ISDN and
   1985  1.1  christos  *    PSTN (Public Switched Telephone Network) numbering plan.  E.163
   1986  1.1  christos  *    defines the country codes, and E.164 the form of the addresses.  Its
   1987  1.1  christos  *    format in master files is a <character-string> syntactically
   1988  1.1  christos  *    identical to that used in TXT and HINFO.
   1989  1.1  christos  *
   1990  1.1  christos  *    <sa> specifies the subaddress (SA).  The format of <sa> in master
   1991  1.1  christos  *    files is a <character-string> syntactically identical to that used in
   1992  1.1  christos  *    TXT and HINFO.
   1993  1.1  christos  *
   1994  1.1  christos  *    The format of ISDN is class insensitive.  ISDN RRs cause no
   1995  1.1  christos  *    additional section processing.
   1996  1.1  christos  *
   1997  1.1  christos  *    The <ISDN-address> is a string of characters, normally decimal
   1998  1.1  christos  *    digits, beginning with the E.163 country code and ending with the DDI
   1999  1.1  christos  *    if any.  Note that ISDN, in Q.931, permits any IA5 character in the
   2000  1.1  christos  *    general case.
   2001  1.1  christos  *
   2002  1.1  christos  *    The <sa> is a string of hexadecimal digits.  For digits 0-9, the
   2003  1.1  christos  *    concrete encoding in the Q.931 call setup information element is
   2004  1.1  christos  *    identical to BCD.
   2005  1.1  christos  *
   2006  1.1  christos  *    For example:
   2007  1.1  christos  *
   2008  1.1  christos  *    Relay.Prime.COM.   IN   ISDN      150862028003217
   2009  1.1  christos  *    sh.Prime.COM.      IN   ISDN      150862028003217 004
   2010  1.1  christos  *
   2011  1.1  christos  *    (Note: "1" is the country code for the North American Integrated
   2012  1.1  christos  *    Numbering Area, i.e., the system of "area codes" familiar to people
   2013  1.1  christos  *    in those countries.)
   2014  1.1  christos  *
   2015  1.1  christos  *    The RR data is the ASCII representation of the digits.  It is encoded
   2016  1.1  christos  *    as one or two <character-string>s, i.e., count followed by
   2017  1.1  christos  *    characters.
   2018  1.1  christos  */
   2019  1.1  christos ISC_RUN_TEST_IMPL(isdn) {
   2020  1.1  christos 	wire_ok_t wire_ok[] = { /*
   2021  1.1  christos 				 * "".
   2022  1.1  christos 				 */
   2023  1.1  christos 				WIRE_VALID(0x00),
   2024  1.1  christos 				/*
   2025  1.1  christos 				 * "\001".
   2026  1.1  christos 				 */
   2027  1.1  christos 				WIRE_VALID(0x01, 0x01),
   2028  1.1  christos 				/*
   2029  1.1  christos 				 * "\001" "".
   2030  1.1  christos 				 */
   2031  1.1  christos 				WIRE_VALID(0x01, 0x01, 0x00),
   2032  1.1  christos 				/*
   2033  1.1  christos 				 * "\001" "\001".
   2034  1.1  christos 				 */
   2035  1.1  christos 				WIRE_VALID(0x01, 0x01, 0x01, 0x01),
   2036  1.1  christos 				/*
   2037  1.1  christos 				 * Sentinel.
   2038  1.1  christos 				 */
   2039  1.1  christos 				WIRE_SENTINEL()
   2040  1.1  christos 	};
   2041  1.1  christos 
   2042  1.1  christos 	check_rdata(NULL, wire_ok, NULL, false, dns_rdataclass_in,
   2043  1.1  christos 		    dns_rdatatype_isdn, sizeof(dns_rdata_isdn_t));
   2044  1.1  christos }
   2045  1.1  christos 
   2046  1.1  christos /*
   2047  1.1  christos  * KEY tests.
   2048  1.1  christos  */
   2049  1.1  christos ISC_RUN_TEST_IMPL(key) {
   2050  1.1  christos 	wire_ok_t wire_ok[] = { /*
   2051  1.1  christos 				 * RDATA is comprised of:
   2052  1.1  christos 				 *
   2053  1.1  christos 				 *   - 2 octets for Flags,
   2054  1.1  christos 				 *   - 1 octet for Protocol,
   2055  1.1  christos 				 *   - 1 octet for Algorithm,
   2056  1.1  christos 				 *   - variable number of octets for Public Key.
   2057  1.1  christos 				 *
   2058  1.1  christos 				 * RFC 2535 section 3.1.2 states that if bits
   2059  1.1  christos 				 * 0-1 of Flags are both set, the RR stops after
   2060  1.1  christos 				 * the algorithm octet and thus its length must
   2061  1.1  christos 				 * be 4 octets.  In any other case, though, the
   2062  1.1  christos 				 * Public Key part must not be empty.
   2063  1.1  christos 				 */
   2064  1.1  christos 				WIRE_INVALID(0x00),
   2065  1.1  christos 				WIRE_INVALID(0x00, 0x00),
   2066  1.1  christos 				WIRE_INVALID(0x00, 0x00, 0x00),
   2067  1.1  christos 				WIRE_VALID(0xc0, 0x00, 0x00, 0x00),
   2068  1.1  christos 				WIRE_INVALID(0xc0, 0x00, 0x00, 0x00, 0x00),
   2069  1.1  christos 				WIRE_INVALID(0x00, 0x00, 0x00, 0x00),
   2070  1.1  christos 				WIRE_VALID(0x00, 0x00, 0x00, 0x00, 0x00),
   2071  1.1  christos 				WIRE_SENTINEL()
   2072  1.1  christos 	};
   2073  1.1  christos 
   2074  1.1  christos 	check_rdata(NULL, wire_ok, NULL, false, dns_rdataclass_in,
   2075  1.1  christos 		    dns_rdatatype_key, sizeof(dns_rdata_key_t));
   2076  1.1  christos }
   2077  1.1  christos 
   2078  1.1  christos /*
   2079  1.1  christos  * LOC tests.
   2080  1.1  christos  */
   2081  1.1  christos ISC_RUN_TEST_IMPL(loc) {
   2082  1.1  christos 	text_ok_t text_ok[] = {
   2083  1.1  christos 		TEXT_VALID_CHANGED("0 N 0 E 0", "0 0 0.000 N 0 0 0.000 E 0.00m "
   2084  1.1  christos 						"1m 10000m 10m"),
   2085  1.1  christos 		TEXT_VALID_CHANGED("0 S 0 W 0", "0 0 0.000 N 0 0 0.000 E 0.00m "
   2086  1.1  christos 						"1m 10000m 10m"),
   2087  1.1  christos 		TEXT_VALID_CHANGED("0 0 N 0 0 E 0", "0 0 0.000 N 0 0 0.000 E "
   2088  1.1  christos 						    "0.00m 1m 10000m 10m"),
   2089  1.1  christos 		TEXT_VALID_CHANGED("0 0 0 N 0 0 0 E 0",
   2090  1.1  christos 				   "0 0 0.000 N 0 0 0.000 E 0.00m 1m 10000m "
   2091  1.1  christos 				   "10m"),
   2092  1.1  christos 		TEXT_VALID_CHANGED("0 0 0 N 0 0 0 E 0",
   2093  1.1  christos 				   "0 0 0.000 N 0 0 0.000 E 0.00m 1m 10000m "
   2094  1.1  christos 				   "10m"),
   2095  1.1  christos 		TEXT_VALID_CHANGED("0 0 0. N 0 0 0. E 0",
   2096  1.1  christos 				   "0 0 0.000 N 0 0 0.000 E 0.00m 1m 10000m "
   2097  1.1  christos 				   "10m"),
   2098  1.1  christos 		TEXT_VALID_CHANGED("0 0 .0 N 0 0 .0 E 0",
   2099  1.1  christos 				   "0 0 0.000 N 0 0 0.000 E 0.00m 1m 10000m "
   2100  1.1  christos 				   "10m"),
   2101  1.1  christos 		TEXT_INVALID("0 North 0 East 0"),
   2102  1.1  christos 		TEXT_INVALID("0 South 0 West 0"),
   2103  1.1  christos 		TEXT_INVALID("0 0 . N 0 0 0. E 0"),
   2104  1.1  christos 		TEXT_INVALID("0 0 0. N 0 0 . E 0"),
   2105  1.1  christos 		TEXT_INVALID("0 0 0. N 0 0 0. E m"),
   2106  1.1  christos 		TEXT_INVALID("0 0 0. N 0 0 0. E 0 ."),
   2107  1.1  christos 		TEXT_INVALID("0 0 0. N 0 0 0. E 0 m"),
   2108  1.1  christos 		TEXT_INVALID("0 0 0. N 0 0 0. E 0 0 ."),
   2109  1.1  christos 		TEXT_INVALID("0 0 0. N 0 0 0. E 0 0 m"),
   2110  1.1  christos 		TEXT_INVALID("0 0 0. N 0 0 0. E 0 0 0 ."),
   2111  1.1  christos 		TEXT_INVALID("0 0 0. N 0 0 0. E 0 0 0 m"),
   2112  1.1  christos 		TEXT_VALID_CHANGED("90 N 180 E 0", "90 0 0.000 N 180 0 0.000 E "
   2113  1.1  christos 						   "0.00m 1m 10000m 10m"),
   2114  1.1  christos 		TEXT_INVALID("90 1 N 180 E 0"),
   2115  1.1  christos 		TEXT_INVALID("90 0 1 N 180 E 0"),
   2116  1.1  christos 		TEXT_INVALID("90 N 180 1 E 0"),
   2117  1.1  christos 		TEXT_INVALID("90 N 180 0 1 E 0"),
   2118  1.1  christos 		TEXT_VALID_CHANGED("90 S 180 W 0", "90 0 0.000 S 180 0 0.000 W "
   2119  1.1  christos 						   "0.00m 1m 10000m 10m"),
   2120  1.1  christos 		TEXT_INVALID("90 1 S 180 W 0"),
   2121  1.1  christos 		TEXT_INVALID("90 0 1 S 180 W 0"),
   2122  1.1  christos 		TEXT_INVALID("90 S 180 1 W 0"),
   2123  1.1  christos 		TEXT_INVALID("90 S 180 0 1 W 0"),
   2124  1.1  christos 		TEXT_INVALID("0 0 0.000 E 0 0 0.000 E -0.95m 1m 10000m 10m"),
   2125  1.1  christos 		TEXT_VALID("0 0 0.000 N 0 0 0.000 E -0.95m 1m 10000m 10m"),
   2126  1.1  christos 		TEXT_VALID("0 0 0.000 N 0 0 0.000 E -0.05m 1m 10000m 10m"),
   2127  1.1  christos 		TEXT_VALID("0 0 0.000 N 0 0 0.000 E -100000.00m 1m 10000m 10m"),
   2128  1.1  christos 		TEXT_VALID("0 0 0.000 N 0 0 0.000 E 42849672.95m 1m 10000m "
   2129  1.1  christos 			   "10m"),
   2130  1.1  christos 		/*
   2131  1.1  christos 		 * Sentinel.
   2132  1.1  christos 		 */
   2133  1.1  christos 		TEXT_SENTINEL()
   2134  1.1  christos 	};
   2135  1.1  christos 
   2136  1.1  christos 	check_rdata(text_ok, 0, NULL, false, dns_rdataclass_in,
   2137  1.1  christos 		    dns_rdatatype_loc, sizeof(dns_rdata_loc_t));
   2138  1.1  christos }
   2139  1.1  christos 
   2140  1.1  christos /*
   2141  1.1  christos  * http://ana-3.lcs.mit.edu/~jnc/nimrod/dns.txt
   2142  1.1  christos  *
   2143  1.1  christos  * The RDATA portion of both the NIMLOC and EID records contains
   2144  1.1  christos  * uninterpreted binary data.  The representation in the text master file
   2145  1.1  christos  * is an even number of hex characters (0 to 9, a to f), case is not
   2146  1.1  christos  * significant.  For readability, whitespace may be included in the value
   2147  1.1  christos  * field and should be ignored when reading a master file.
   2148  1.1  christos  */
   2149  1.1  christos ISC_RUN_TEST_IMPL(nimloc) {
   2150  1.1  christos 	text_ok_t text_ok[] = { TEXT_VALID("AABBCC"),
   2151  1.1  christos 				TEXT_VALID_CHANGED("AA bb cc", "AABBCC"),
   2152  1.1  christos 				TEXT_INVALID("aab"),
   2153  1.1  christos 				/*
   2154  1.1  christos 				 * Sentinel.
   2155  1.1  christos 				 */
   2156  1.1  christos 				TEXT_SENTINEL() };
   2157  1.1  christos 	wire_ok_t wire_ok[] = { WIRE_VALID(0x00), WIRE_VALID(0xAA, 0xBB, 0xCC),
   2158  1.1  christos 				/*
   2159  1.1  christos 				 * Sentinel.
   2160  1.1  christos 				 */
   2161  1.1  christos 				WIRE_SENTINEL() };
   2162  1.1  christos 
   2163  1.1  christos 	check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
   2164  1.1  christos 		    dns_rdatatype_nimloc, sizeof(dns_rdata_in_nimloc_t));
   2165  1.1  christos }
   2166  1.1  christos 
   2167  1.1  christos /*
   2168  1.1  christos  * NSEC tests.
   2169  1.1  christos  *
   2170  1.1  christos  * RFC 4034:
   2171  1.1  christos  *
   2172  1.1  christos  * 4.1.  NSEC RDATA Wire Format
   2173  1.1  christos  *
   2174  1.1  christos  *   The RDATA of the NSEC RR is as shown below:
   2175  1.1  christos  *
   2176  1.1  christos  *                         1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
   2177  1.1  christos  *     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   2178  1.1  christos  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   2179  1.1  christos  *    /                      Next Domain Name                         /
   2180  1.1  christos  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   2181  1.1  christos  *    /                       Type Bit Maps                           /
   2182  1.1  christos  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   2183  1.1  christos  *
   2184  1.1  christos  * 4.1.1.  The Next Domain Name Field
   2185  1.1  christos  *
   2186  1.1  christos  *    The Next Domain field contains the next owner name (in the canonical
   2187  1.1  christos  *    ordering of the zone) that has authoritative data or contains a
   2188  1.1  christos  *    delegation point NS RRset; see Section 6.1 for an explanation of
   2189  1.1  christos  *    canonical ordering.  The value of the Next Domain Name field in the
   2190  1.1  christos  *    last NSEC record in the zone is the name of the zone apex (the owner
   2191  1.1  christos  *    name of the zone's SOA RR).  This indicates that the owner name of
   2192  1.1  christos  *    the NSEC RR is the last name in the canonical ordering of the zone.
   2193  1.1  christos  *
   2194  1.1  christos  *    A sender MUST NOT use DNS name compression on the Next Domain Name
   2195  1.1  christos  *    field when transmitting an NSEC RR.
   2196  1.1  christos  *
   2197  1.1  christos  *    Owner names of RRsets for which the given zone is not authoritative
   2198  1.1  christos  *    (such as glue records) MUST NOT be listed in the Next Domain Name
   2199  1.1  christos  *    unless at least one authoritative RRset exists at the same owner
   2200  1.1  christos  *    name.
   2201  1.1  christos  *
   2202  1.1  christos  * 4.1.2.  The Type Bit Maps Field
   2203  1.1  christos  *
   2204  1.1  christos  *    The Type Bit Maps field identifies the RRset types that exist at the
   2205  1.1  christos  *    NSEC RR's owner name.
   2206  1.1  christos  *
   2207  1.1  christos  *    The RR type space is split into 256 window blocks, each representing
   2208  1.1  christos  *    the low-order 8 bits of the 16-bit RR type space.  Each block that
   2209  1.1  christos  *    has at least one active RR type is encoded using a single octet
   2210  1.1  christos  *    window number (from 0 to 255), a single octet bitmap length (from 1
   2211  1.1  christos  *    to 32) indicating the number of octets used for the window block's
   2212  1.1  christos  *    bitmap, and up to 32 octets (256 bits) of bitmap.
   2213  1.1  christos  *
   2214  1.1  christos  *    Blocks are present in the NSEC RR RDATA in increasing numerical
   2215  1.1  christos  *    order.
   2216  1.1  christos  *
   2217  1.1  christos  *       Type Bit Maps Field = ( Window Block # | Bitmap Length | Bitmap )+
   2218  1.1  christos  *
   2219  1.1  christos  *       where "|" denotes concatenation.
   2220  1.1  christos  *
   2221  1.1  christos  *    Each bitmap encodes the low-order 8 bits of RR types within the
   2222  1.1  christos  *    window block, in network bit order.  The first bit is bit 0.  For
   2223  1.1  christos  *    window block 0, bit 1 corresponds to RR type 1 (A), bit 2 corresponds
   2224  1.1  christos  *    to RR type 2 (NS), and so forth.  For window block 1, bit 1
   2225  1.1  christos  *    corresponds to RR type 257, and bit 2 to RR type 258.  If a bit is
   2226  1.1  christos  *    set, it indicates that an RRset of that type is present for the NSEC
   2227  1.1  christos  *    RR's owner name.  If a bit is clear, it indicates that no RRset of
   2228  1.1  christos  *    that type is present for the NSEC RR's owner name.
   2229  1.1  christos  *
   2230  1.1  christos  *    Bits representing pseudo-types MUST be clear, as they do not appear
   2231  1.1  christos  *    in zone data.  If encountered, they MUST be ignored upon being read.
   2232  1.1  christos  */
   2233  1.1  christos ISC_RUN_TEST_IMPL(nsec) {
   2234  1.1  christos 	text_ok_t text_ok[] = { TEXT_INVALID(""), TEXT_INVALID("."),
   2235  1.1  christos 				TEXT_VALID(". RRSIG"), TEXT_SENTINEL() };
   2236  1.1  christos 	wire_ok_t wire_ok[] = { WIRE_INVALID(0x00), WIRE_INVALID(0x00, 0x00),
   2237  1.1  christos 				WIRE_INVALID(0x00, 0x00, 0x00),
   2238  1.1  christos 				WIRE_VALID(0x00, 0x00, 0x01, 0x02),
   2239  1.1  christos 				WIRE_SENTINEL() };
   2240  1.1  christos 
   2241  1.1  christos 	check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
   2242  1.1  christos 		    dns_rdatatype_nsec, sizeof(dns_rdata_nsec_t));
   2243  1.1  christos }
   2244  1.1  christos 
   2245  1.1  christos /*
   2246  1.1  christos  * NSEC3 tests.
   2247  1.1  christos  *
   2248  1.1  christos  * RFC 5155.
   2249  1.1  christos  */
   2250  1.1  christos ISC_RUN_TEST_IMPL(nsec3) {
   2251  1.1  christos 	text_ok_t text_ok[] = { TEXT_INVALID(""),
   2252  1.1  christos 				TEXT_INVALID("."),
   2253  1.1  christos 				TEXT_INVALID(". RRSIG"),
   2254  1.1  christos 				TEXT_INVALID("1 0 10 76931F"),
   2255  1.1  christos 				TEXT_INVALID("1 0 10 76931F "
   2256  1.1  christos 					     "IMQ912BREQP1POLAH3RMONG&"
   2257  1.1  christos 					     "UED541AS"),
   2258  1.1  christos 				TEXT_INVALID("1 0 10 76931F "
   2259  1.1  christos 					     "IMQ912BREQP1POLAH3RMONGAUED541AS "
   2260  1.1  christos 					     "A RRSIG BADTYPE"),
   2261  1.1  christos 				TEXT_VALID("1 0 10 76931F "
   2262  1.1  christos 					   "AJHVGTICN6K0VDA53GCHFMT219SRRQLM A "
   2263  1.1  christos 					   "RRSIG"),
   2264  1.1  christos 				TEXT_VALID("1 0 10 76931F "
   2265  1.1  christos 					   "AJHVGTICN6K0VDA53GCHFMT219SRRQLM"),
   2266  1.1  christos 				TEXT_VALID("1 0 10 - "
   2267  1.1  christos 					   "AJHVGTICN6K0VDA53GCHFMT219SRRQLM"),
   2268  1.1  christos 				TEXT_SENTINEL() };
   2269  1.1  christos 
   2270  1.1  christos 	check_rdata(text_ok, NULL, NULL, false, dns_rdataclass_in,
   2271  1.1  christos 		    dns_rdatatype_nsec3, sizeof(dns_rdata_nsec3_t));
   2272  1.1  christos }
   2273  1.1  christos 
   2274  1.1  christos /* NXT RDATA manipulations */
   2275  1.1  christos ISC_RUN_TEST_IMPL(nxt) {
   2276  1.1  christos 	compare_ok_t compare_ok[] = {
   2277  1.1  christos 		COMPARE("a. A SIG", "a. A SIG", 0),
   2278  1.1  christos 		/*
   2279  1.1  christos 		 * Records that differ only in the case of the next
   2280  1.1  christos 		 * name should be equal.
   2281  1.1  christos 		 */
   2282  1.1  christos 		COMPARE("A. A SIG", "a. A SIG", 0),
   2283  1.1  christos 		/*
   2284  1.1  christos 		 * Sorting on name field.
   2285  1.1  christos 		 */
   2286  1.1  christos 		COMPARE("A. A SIG", "b. A SIG", -1),
   2287  1.1  christos 		COMPARE("b. A SIG", "A. A SIG", 1),
   2288  1.1  christos 		/* bit map differs */
   2289  1.1  christos 		COMPARE("b. A SIG", "b. A AAAA SIG", -1),
   2290  1.1  christos 		/* order of bit map does not matter */
   2291  1.1  christos 		COMPARE("b. A SIG AAAA", "b. A AAAA SIG", 0), COMPARE_SENTINEL()
   2292  1.1  christos 	};
   2293  1.1  christos 
   2294  1.1  christos 	check_rdata(NULL, NULL, compare_ok, false, dns_rdataclass_in,
   2295  1.1  christos 		    dns_rdatatype_nxt, sizeof(dns_rdata_nxt_t));
   2296  1.1  christos }
   2297  1.1  christos 
   2298  1.1  christos ISC_RUN_TEST_IMPL(rkey) {
   2299  1.1  christos 	text_ok_t text_ok[] = { /*
   2300  1.1  christos 				 * Valid, flags set to 0 and a key is present.
   2301  1.1  christos 				 */
   2302  1.1  christos 				TEXT_VALID("0 0 0 aaaa"),
   2303  1.1  christos 				/*
   2304  1.1  christos 				 * Invalid, non-zero flags.
   2305  1.1  christos 				 */
   2306  1.1  christos 				TEXT_INVALID("1 0 0 aaaa"),
   2307  1.1  christos 				TEXT_INVALID("65535 0 0 aaaa"),
   2308  1.1  christos 				/*
   2309  1.1  christos 				 * Sentinel.
   2310  1.1  christos 				 */
   2311  1.1  christos 				TEXT_SENTINEL()
   2312  1.1  christos 	};
   2313  1.1  christos 	wire_ok_t wire_ok[] = { /*
   2314  1.1  christos 				 * Valid, flags set to 0 and a key is present.
   2315  1.1  christos 				 */
   2316  1.1  christos 				WIRE_VALID(0x00, 0x00, 0x00, 0x00, 0x00),
   2317  1.1  christos 				/*
   2318  1.1  christos 				 * Invalid, non-zero flags.
   2319  1.1  christos 				 */
   2320  1.1  christos 				WIRE_INVALID(0x00, 0x01, 0x00, 0x00, 0x00),
   2321  1.1  christos 				WIRE_INVALID(0xff, 0xff, 0x00, 0x00, 0x00),
   2322  1.1  christos 				/*
   2323  1.1  christos 				 * Sentinel.
   2324  1.1  christos 				 */
   2325  1.1  christos 				WIRE_SENTINEL()
   2326  1.1  christos 	};
   2327  1.1  christos 	key_required(state, dns_rdatatype_rkey, sizeof(dns_rdata_rkey_t));
   2328  1.1  christos 	check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
   2329  1.1  christos 		    dns_rdatatype_rkey, sizeof(dns_rdata_rkey_t));
   2330  1.1  christos }
   2331  1.1  christos 
   2332  1.1  christos /* SSHFP RDATA manipulations */
   2333  1.1  christos ISC_RUN_TEST_IMPL(sshfp) {
   2334  1.1  christos 	text_ok_t text_ok[] = { TEXT_INVALID(""),     /* too short */
   2335  1.1  christos 				TEXT_INVALID("0"),    /* reserved, too short */
   2336  1.1  christos 				TEXT_VALID("0 0"),    /* no finger print */
   2337  1.1  christos 				TEXT_VALID("0 0 AA"), /* reserved */
   2338  1.1  christos 				TEXT_INVALID("0 1 AA"), /* too short SHA 1
   2339  1.1  christos 							 * digest */
   2340  1.1  christos 				TEXT_INVALID("0 2 AA"), /* too short SHA 256
   2341  1.1  christos 							 * digest */
   2342  1.1  christos 				TEXT_VALID("0 3 AA"),	/* unknown finger print
   2343  1.1  christos 							 * type */
   2344  1.1  christos 				/* good length SHA 1 digest */
   2345  1.1  christos 				TEXT_VALID("1 1 "
   2346  1.1  christos 					   "00112233445566778899AABBCCDDEEFF171"
   2347  1.1  christos 					   "81920"),
   2348  1.1  christos 				/* good length SHA 256 digest */
   2349  1.1  christos 				TEXT_VALID("4 2 "
   2350  1.1  christos 					   "A87F1B687AC0E57D2A081A2F282672334D9"
   2351  1.1  christos 					   "0ED316D2B818CA9580EA3 84D92401"),
   2352  1.1  christos 				/*
   2353  1.1  christos 				 * totext splits the fingerprint into chunks and
   2354  1.1  christos 				 * emits uppercase hex.
   2355  1.1  christos 				 */
   2356  1.1  christos 				TEXT_VALID_CHANGED("1 2 "
   2357  1.1  christos 						   "00112233445566778899aabbccd"
   2358  1.1  christos 						   "deeff "
   2359  1.1  christos 						   "00112233445566778899AABBCCD"
   2360  1.1  christos 						   "DEEFF",
   2361  1.1  christos 						   "1 2 "
   2362  1.1  christos 						   "00112233445566778899AABBCCD"
   2363  1.1  christos 						   "DEEFF"
   2364  1.1  christos 						   "00112233445566778899AABB "
   2365  1.1  christos 						   "CCDDEEFF"),
   2366  1.1  christos 				TEXT_SENTINEL() };
   2367  1.1  christos 	wire_ok_t wire_ok[] = {
   2368  1.1  christos 		WIRE_INVALID(0x00),	      /* reserved too short */
   2369  1.1  christos 		WIRE_VALID(0x00, 0x00),	      /* reserved no finger print */
   2370  1.1  christos 		WIRE_VALID(0x00, 0x00, 0x00), /* reserved */
   2371  1.1  christos 
   2372  1.1  christos 		/* too short SHA 1 digests */
   2373  1.1  christos 		WIRE_INVALID(0x00, 0x01), WIRE_INVALID(0x00, 0x01, 0x00),
   2374  1.1  christos 		WIRE_INVALID(0x00, 0x01, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
   2375  1.1  christos 			     0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD,
   2376  1.1  christos 			     0xEE, 0xFF, 0x17, 0x18, 0x19),
   2377  1.1  christos 		/* good length SHA 1 digest */
   2378  1.1  christos 		WIRE_VALID(0x00, 0x01, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66,
   2379  1.1  christos 			   0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
   2380  1.1  christos 			   0x17, 0x18, 0x19, 0x20),
   2381  1.1  christos 		/* too long SHA 1 digest */
   2382  1.1  christos 		WIRE_INVALID(0x00, 0x01, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
   2383  1.1  christos 			     0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD,
   2384  1.1  christos 			     0xEE, 0xFF, 0x17, 0x18, 0x19, 0x20, 0x21),
   2385  1.1  christos 		/* too short SHA 256 digests */
   2386  1.1  christos 		WIRE_INVALID(0x00, 0x02), WIRE_INVALID(0x00, 0x02, 0x00),
   2387  1.1  christos 		WIRE_INVALID(0x00, 0x02, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
   2388  1.1  christos 			     0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD,
   2389  1.1  christos 			     0xEE, 0xFF, 0x17, 0x18, 0x19, 0x20, 0x21, 0x22,
   2390  1.1  christos 			     0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x30,
   2391  1.1  christos 			     0x31),
   2392  1.1  christos 		/* good length SHA 256 digest */
   2393  1.1  christos 		WIRE_VALID(0x00, 0x02, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66,
   2394  1.1  christos 			   0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF,
   2395  1.1  christos 			   0x17, 0x18, 0x19, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25,
   2396  1.1  christos 			   0x26, 0x27, 0x28, 0x29, 0x30, 0x31, 0x32),
   2397  1.1  christos 		/* too long SHA 256 digest */
   2398  1.1  christos 		WIRE_INVALID(0x00, 0x02, 0x00, 0x11, 0x22, 0x33, 0x44, 0x55,
   2399  1.1  christos 			     0x66, 0x77, 0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD,
   2400  1.1  christos 			     0xEE, 0xFF, 0x17, 0x18, 0x19, 0x20, 0x21, 0x22,
   2401  1.1  christos 			     0x23, 0x24, 0x25, 0x26, 0x27, 0x28, 0x29, 0x30,
   2402  1.1  christos 			     0x31, 0x32, 0x33),
   2403  1.1  christos 		/* unknown digest, * no fingerprint */
   2404  1.1  christos 		WIRE_VALID(0x00, 0x03), WIRE_VALID(0x00, 0x03, 0x00), /* unknown
   2405  1.1  christos 								       * digest
   2406  1.1  christos 								       */
   2407  1.1  christos 		WIRE_SENTINEL()
   2408  1.1  christos 	};
   2409  1.1  christos 
   2410  1.1  christos 	check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
   2411  1.1  christos 		    dns_rdatatype_sshfp, sizeof(dns_rdata_sshfp_t));
   2412  1.1  christos }
   2413  1.1  christos 
   2414  1.1  christos /*
   2415  1.1  christos  * WKS tests.
   2416  1.1  christos  *
   2417  1.1  christos  * RFC 1035:
   2418  1.1  christos  *
   2419  1.1  christos  * 3.4.2. WKS RDATA format
   2420  1.1  christos  *
   2421  1.1  christos  *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
   2422  1.1  christos  *     |                    ADDRESS                    |
   2423  1.1  christos  *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
   2424  1.1  christos  *     |       PROTOCOL        |                       |
   2425  1.1  christos  *     +--+--+--+--+--+--+--+--+                       |
   2426  1.1  christos  *     |                                               |
   2427  1.1  christos  *     /                   <BIT MAP>                   /
   2428  1.1  christos  *     /                                               /
   2429  1.1  christos  *     +--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+--+
   2430  1.1  christos  *
   2431  1.1  christos  * where:
   2432  1.1  christos  *
   2433  1.1  christos  * ADDRESS         An 32 bit Internet address
   2434  1.1  christos  *
   2435  1.1  christos  * PROTOCOL        An 8 bit IP protocol number
   2436  1.1  christos  *
   2437  1.1  christos  * <BIT MAP>       A variable length bit map.  The bit map must be a
   2438  1.1  christos  *                 multiple of 8 bits long.
   2439  1.1  christos  *
   2440  1.1  christos  * The WKS record is used to describe the well known services supported by
   2441  1.1  christos  * a particular protocol on a particular internet address.  The PROTOCOL
   2442  1.1  christos  * field specifies an IP protocol number, and the bit map has one bit per
   2443  1.1  christos  * port of the specified protocol.  The first bit corresponds to port 0,
   2444  1.1  christos  * the second to port 1, etc.  If the bit map does not include a bit for a
   2445  1.1  christos  * protocol of interest, that bit is assumed zero.  The appropriate values
   2446  1.1  christos  * and mnemonics for ports and protocols are specified in [RFC-1010].
   2447  1.1  christos  *
   2448  1.1  christos  * For example, if PROTOCOL=TCP (6), the 26th bit corresponds to TCP port
   2449  1.1  christos  * 25 (SMTP).  If this bit is set, a SMTP server should be listening on TCP
   2450  1.1  christos  * port 25; if zero, SMTP service is not supported on the specified
   2451  1.1  christos  * address.
   2452  1.1  christos  */
   2453  1.1  christos ISC_RUN_TEST_IMPL(wks) {
   2454  1.1  christos 	text_ok_t text_ok[] = { /*
   2455  1.1  christos 				 * Valid, IPv4 address in dotted-quad form.
   2456  1.1  christos 				 */
   2457  1.1  christos 				TEXT_VALID("127.0.0.1 6"),
   2458  1.1  christos 				/*
   2459  1.1  christos 				 * Invalid, IPv4 address not in dotted-quad
   2460  1.1  christos 				 * form.
   2461  1.1  christos 				 */
   2462  1.1  christos 				TEXT_INVALID("127.1 6"),
   2463  1.1  christos 				/*
   2464  1.1  christos 				 * Sentinel.
   2465  1.1  christos 				 */
   2466  1.1  christos 				TEXT_SENTINEL()
   2467  1.1  christos 	};
   2468  1.1  christos 	wire_ok_t wire_ok[] = { /*
   2469  1.1  christos 				 * Too short.
   2470  1.1  christos 				 */
   2471  1.1  christos 				WIRE_INVALID(0x00, 0x08, 0x00, 0x00),
   2472  1.1  christos 				/*
   2473  1.1  christos 				 * Minimal TCP.
   2474  1.1  christos 				 */
   2475  1.1  christos 				WIRE_VALID(0x00, 0x08, 0x00, 0x00, 6),
   2476  1.1  christos 				/*
   2477  1.1  christos 				 * Minimal UDP.
   2478  1.1  christos 				 */
   2479  1.1  christos 				WIRE_VALID(0x00, 0x08, 0x00, 0x00, 17),
   2480  1.1  christos 				/*
   2481  1.1  christos 				 * Minimal other.
   2482  1.1  christos 				 */
   2483  1.1  christos 				WIRE_VALID(0x00, 0x08, 0x00, 0x00, 1),
   2484  1.1  christos 				/*
   2485  1.1  christos 				 * Sentinel.
   2486  1.1  christos 				 */
   2487  1.1  christos 				WIRE_SENTINEL()
   2488  1.1  christos 	};
   2489  1.1  christos 
   2490  1.1  christos 	check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
   2491  1.1  christos 		    dns_rdatatype_wks, sizeof(dns_rdata_in_wks_t));
   2492  1.1  christos }
   2493  1.1  christos 
   2494  1.1  christos ISC_RUN_TEST_IMPL(https_svcb) {
   2495  1.1  christos 	/*
   2496  1.1  christos 	 * Known keys: mandatory, apln, no-default-alpn, port,
   2497  1.1  christos 	 *             ipv4hint, port, ipv6hint, dohpath.
   2498  1.1  christos 	 */
   2499  1.1  christos 	text_ok_t text_ok[] = {
   2500  1.1  christos 		/* unknown key invalid */
   2501  1.1  christos 		TEXT_INVALID("1 . unknown="),
   2502  1.1  christos 		/* no domain */
   2503  1.1  christos 		TEXT_INVALID("0"),
   2504  1.1  christos 		/* minimal record */
   2505  1.1  christos 		TEXT_VALID_LOOP(0, "0 ."),
   2506  1.1  christos 		/* Alias form requires SvcFieldValue to be empty */
   2507  1.1  christos 		TEXT_INVALID("0 . alpn=\"h2\""),
   2508  1.1  christos 		/* no "key" prefix */
   2509  1.1  christos 		TEXT_INVALID("2 svc.example.net. 0=\"2222\""),
   2510  1.1  christos 		/* no key value */
   2511  1.1  christos 		TEXT_INVALID("2 svc.example.net. key"),
   2512  1.1  christos 		/* no key value */
   2513  1.1  christos 		TEXT_INVALID("2 svc.example.net. key=\"2222\""),
   2514  1.1  christos 		/* zero pad invalid */
   2515  1.1  christos 		TEXT_INVALID("2 svc.example.net. key07=\"2222\""),
   2516  1.1  christos 		TEXT_VALID_LOOP(1, "2 svc.example.net. key8=\"2222\""),
   2517  1.1  christos 		TEXT_VALID_LOOPCHG(1, "2 svc.example.net. key8=2222",
   2518  1.1  christos 				   "2 svc.example.net. key8=\"2222\""),
   2519  1.1  christos 		TEXT_VALID_LOOPCHG(1, "2 svc.example.net. alpn=h2",
   2520  1.1  christos 				   "2 svc.example.net. alpn=\"h2\""),
   2521  1.1  christos 		TEXT_VALID_LOOPCHG(1, "2 svc.example.net. alpn=h3",
   2522  1.1  christos 				   "2 svc.example.net. alpn=\"h3\""),
   2523  1.1  christos 		/* alpn has 2 sub field "h2" and "h3" */
   2524  1.1  christos 		TEXT_VALID_LOOPCHG(1, "2 svc.example.net. alpn=h2,h3",
   2525  1.1  christos 				   "2 svc.example.net. alpn=\"h2,h3\""),
   2526  1.1  christos 		/* apln has 2 sub fields "h1,h2" and "h3" (comma escaped) */
   2527  1.1  christos 		TEXT_VALID_LOOPCHG(1, "2 svc.example.net. alpn=h1\\\\,h2,h3",
   2528  1.1  christos 				   "2 svc.example.net. alpn=\"h1\\\\,h2,h3\""),
   2529  1.1  christos 		TEXT_VALID_LOOP(1, "2 svc.example.net. port=50"),
   2530  1.1  christos 		/* no-default-alpn, alpn is required */
   2531  1.1  christos 		TEXT_INVALID("2 svc.example.net. no-default-alpn"),
   2532  1.1  christos 		/* no-default-alpn with alpn present */
   2533  1.1  christos 		TEXT_VALID_LOOPCHG(
   2534  1.1  christos 			2, "2 svc.example.net. no-default-alpn alpn=h2",
   2535  1.1  christos 			"2 svc.example.net. alpn=\"h2\" no-default-alpn"),
   2536  1.1  christos 		/* empty hint */
   2537  1.1  christos 		TEXT_INVALID("2 svc.example.net. ipv4hint="),
   2538  1.1  christos 		TEXT_VALID_LOOP(1, "2 svc.example.net. "
   2539  1.1  christos 				   "ipv4hint=10.50.0.1,10.50.0.2"),
   2540  1.1  christos 		/* empty hint */
   2541  1.1  christos 		TEXT_INVALID("2 svc.example.net. ipv6hint="),
   2542  1.1  christos 		TEXT_VALID_LOOP(1, "2 svc.example.net. ipv6hint=::1,2002::1"),
   2543  1.1  christos 		TEXT_VALID_LOOP(1, "2 svc.example.net. ech=abcdefghijkl"),
   2544  1.1  christos 		/* bad base64 */
   2545  1.1  christos 		TEXT_INVALID("2 svc.example.net. ech=abcdefghijklm"),
   2546  1.1  christos 		TEXT_VALID_LOOP(1, "2 svc.example.net. key8=\"2222\""),
   2547  1.1  christos 		/* Out of key order on input (alpn == key1). */
   2548  1.1  christos 		TEXT_VALID_LOOPCHG(2,
   2549  1.1  christos 				   "2 svc.example.net. key8=\"2222\" alpn=h2",
   2550  1.1  christos 				   "2 svc.example.net. alpn=\"h2\" "
   2551  1.1  christos 				   "key8=\"2222\""),
   2552  1.1  christos 		TEXT_VALID_LOOP(1, "2 svc.example.net. key65535=\"2222\""),
   2553  1.1  christos 		TEXT_INVALID("2 svc.example.net. key65536=\"2222\""),
   2554  1.1  christos 		TEXT_VALID_LOOP(1, "2 svc.example.net. key10"),
   2555  1.1  christos 		TEXT_VALID_LOOPCHG(1, "2 svc.example.net. key11=",
   2556  1.1  christos 				   "2 svc.example.net. key11"),
   2557  1.1  christos 		TEXT_VALID_LOOPCHG(1, "2 svc.example.net. key12=\"\"",
   2558  1.1  christos 				   "2 svc.example.net. key12"),
   2559  1.1  christos 		/* empty alpn-id sub fields */
   2560  1.1  christos 		TEXT_INVALID("2 svc.example.net. alpn"),
   2561  1.1  christos 		TEXT_INVALID("2 svc.example.net. alpn="),
   2562  1.1  christos 		TEXT_INVALID("2 svc.example.net. alpn=,h1"),
   2563  1.1  christos 		TEXT_INVALID("2 svc.example.net. alpn=h1,"),
   2564  1.1  christos 		TEXT_INVALID("2 svc.example.net. alpn=h1,,h2"),
   2565  1.1  christos 		/* mandatory */
   2566  1.1  christos 		TEXT_VALID_LOOP(2, "2 svc.example.net. mandatory=alpn "
   2567  1.1  christos 				   "alpn=\"h2\""),
   2568  1.1  christos 		TEXT_VALID_LOOP(3, "2 svc.example.net. mandatory=alpn,port "
   2569  1.1  christos 				   "alpn=\"h2\" port=443"),
   2570  1.1  christos 		TEXT_VALID_LOOPCHG(3,
   2571  1.1  christos 				   "2 svc.example.net. mandatory=port,alpn "
   2572  1.1  christos 				   "alpn=\"h2\" port=443",
   2573  1.1  christos 				   "2 svc.example.net. mandatory=alpn,port "
   2574  1.1  christos 				   "alpn=\"h2\" port=443"),
   2575  1.1  christos 		TEXT_INVALID("2 svc.example.net. mandatory=mandatory"),
   2576  1.1  christos 		TEXT_INVALID("2 svc.example.net. mandatory=port"),
   2577  1.1  christos 		TEXT_INVALID("2 svc.example.net. mandatory=,port port=433"),
   2578  1.1  christos 		TEXT_INVALID("2 svc.example.net. mandatory=port, port=433"),
   2579  1.1  christos 		TEXT_INVALID("2 svc.example.net. "
   2580  1.1  christos 			     "mandatory=alpn,,port alpn=h2 port=433"),
   2581  1.1  christos 		/* mandatory w/ unknown key values */
   2582  1.1  christos 		TEXT_VALID_LOOP(2, "2 svc.example.net. mandatory=key8 key8"),
   2583  1.1  christos 		TEXT_VALID_LOOP(3, "2 svc.example.net. mandatory=key8,key9 "
   2584  1.1  christos 				   "key8 key9"),
   2585  1.1  christos 		TEXT_VALID_LOOPCHG(
   2586  1.1  christos 			3, "2 svc.example.net. mandatory=key9,key8 key8 key9",
   2587  1.1  christos 			"2 svc.example.net. mandatory=key8,key9 key8 key9"),
   2588  1.1  christos 		TEXT_INVALID("2 svc.example.net. "
   2589  1.1  christos 			     "mandatory=key8,key8"),
   2590  1.1  christos 		TEXT_INVALID("2 svc.example.net. mandatory=,key8"),
   2591  1.1  christos 		TEXT_INVALID("2 svc.example.net. mandatory=key8,"),
   2592  1.1  christos 		TEXT_INVALID("2 svc.example.net. "
   2593  1.1  christos 			     "mandatory=key8,,key8"),
   2594  1.1  christos 		/* Invalid test vectors */
   2595  1.1  christos 		TEXT_INVALID("1 foo.example.com. ( key123=abc key123=def )"),
   2596  1.1  christos 		TEXT_INVALID("1 foo.example.com. mandatory"),
   2597  1.1  christos 		TEXT_INVALID("1 foo.example.com. alpn"),
   2598  1.1  christos 		TEXT_INVALID("1 foo.example.com. port"),
   2599  1.1  christos 		TEXT_INVALID("1 foo.example.com. ipv4hint"),
   2600  1.1  christos 		TEXT_INVALID("1 foo.example.com. ipv6hint"),
   2601  1.1  christos 		TEXT_INVALID("1 foo.example.com. no-default-alpn=abc"),
   2602  1.1  christos 		TEXT_INVALID("1 foo.example.com. mandatory=key123"),
   2603  1.1  christos 		TEXT_INVALID("1 foo.example.com. mandatory=mandatory"),
   2604  1.1  christos 		TEXT_INVALID("1 foo.example.com. ( mandatory=key123,key123 "
   2605  1.1  christos 			     "key123=abc)"),
   2606  1.1  christos 		/* dohpath tests */
   2607  1.1  christos 		TEXT_VALID_LOOPCHG(1, "1 example.net. dohpath=/{?dns}",
   2608  1.1  christos 				   "1 example.net. key7=\"/{?dns}\""),
   2609  1.1  christos 		TEXT_VALID_LOOPCHG(1, "1 example.net. dohpath=/some/path{?dns}",
   2610  1.1  christos 				   "1 example.net. key7=\"/some/path{?dns}\""),
   2611  1.1  christos 		TEXT_INVALID("1 example.com. dohpath=no-slash"),
   2612  1.1  christos 		TEXT_INVALID("1 example.com. dohpath=/{?notdns}"),
   2613  1.1  christos 		TEXT_INVALID("1 example.com. dohpath=/notvariable"),
   2614  1.1  christos 		TEXT_SENTINEL()
   2615  1.1  christos 
   2616  1.1  christos 	};
   2617  1.1  christos 	wire_ok_t wire_ok[] = {
   2618  1.1  christos 		/*
   2619  1.1  christos 		 * Too short
   2620  1.1  christos 		 */
   2621  1.1  christos 		WIRE_INVALID(0x00, 0x00),
   2622  1.1  christos 		/*
   2623  1.1  christos 		 * Minimal length record.
   2624  1.1  christos 		 */
   2625  1.1  christos 		WIRE_VALID(0x00, 0x00, 0x00),
   2626  1.1  christos 		/*
   2627  1.1  christos 		 * Alias with non-empty SvcFieldValue (key7="").
   2628  1.1  christos 		 */
   2629  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x00, 0x07, 0x00, 0x00),
   2630  1.1  christos 		/*
   2631  1.1  christos 		 * Bad key7= length (longer than rdata).
   2632  1.1  christos 		 */
   2633  1.1  christos 		WIRE_INVALID(0x00, 0x01, 0x00, 0x00, 0x07, 0x00, 0x01),
   2634  1.1  christos 		/*
   2635  1.1  christos 		 * Port (0x03) too small (zero and one octets).
   2636  1.1  christos 		 */
   2637  1.1  christos 		WIRE_INVALID(0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x00),
   2638  1.1  christos 		WIRE_INVALID(0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x01, 0x00),
   2639  1.1  christos 		/* Valid port */
   2640  1.1  christos 		WIRE_VALID_LOOP(1, 0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x02,
   2641  1.1  christos 				0x00, 0x00),
   2642  1.1  christos 		/*
   2643  1.1  christos 		 * Port (0x03) too big (three octets).
   2644  1.1  christos 		 */
   2645  1.1  christos 		WIRE_INVALID(0x00, 0x01, 0x00, 0x00, 0x03, 0x00, 0x03, 0x00,
   2646  1.1  christos 			     0x00, 0x00),
   2647  1.1  christos 		/*
   2648  1.1  christos 		 * Duplicate keys.
   2649  1.1  christos 		 */
   2650  1.1  christos 		WIRE_INVALID(0x01, 0x00, 0x00, 0x00, 0x80, 0x00, 0x00, 0x00,
   2651  1.1  christos 			     0x80, 0x00, 0x00),
   2652  1.1  christos 		/*
   2653  1.1  christos 		 * Out of order keys.
   2654  1.1  christos 		 */
   2655  1.1  christos 		WIRE_INVALID(0x01, 0x01, 0x00, 0x00, 0x81, 0x00, 0x00, 0x00,
   2656  1.1  christos 			     0x80, 0x00, 0x00),
   2657  1.1  christos 		/*
   2658  1.1  christos 		 * Empty of mandatory key list.
   2659  1.1  christos 		 */
   2660  1.1  christos 		WIRE_INVALID(0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00),
   2661  1.1  christos 		/*
   2662  1.1  christos 		 * "mandatory=mandatory" is invalid
   2663  1.1  christos 		 */
   2664  1.1  christos 		WIRE_INVALID(0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00,
   2665  1.1  christos 			     0x00),
   2666  1.1  christos 		/*
   2667  1.1  christos 		 * Out of order mandatory key list.
   2668  1.1  christos 		 */
   2669  1.1  christos 		WIRE_INVALID(0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x04, 0x00,
   2670  1.1  christos 			     0x80, 0x00, 0x71, 0x00, 0x71, 0x00, 0x00, 0x00,
   2671  1.1  christos 			     0x80, 0x00, 0x00),
   2672  1.1  christos 		/*
   2673  1.1  christos 		 * Alpn(0x00 0x01) (length 0x00 0x09) "h1,h2" + "h3"
   2674  1.1  christos 		 */
   2675  1.1  christos 		WIRE_VALID_LOOP(0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x09,
   2676  1.1  christos 				5, 'h', '1', ',', 'h', '2', 2, 'h', '3'),
   2677  1.1  christos 		/*
   2678  1.1  christos 		 * Alpn(0x00 0x01) (length 0x00 0x09) "h1\h2" + "h3"
   2679  1.1  christos 		 */
   2680  1.1  christos 		WIRE_VALID_LOOP(0x01, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x09,
   2681  1.1  christos 				5, 'h', '1', '\\', 'h', '2', 2, 'h', '3'),
   2682  1.1  christos 		/*
   2683  1.1  christos 		 * no-default-alpn (0x00 0x02) without alpn, alpn is required.
   2684  1.1  christos 		 */
   2685  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00),
   2686  1.1  christos 		/*
   2687  1.1  christos 		 * Alpn(0x00 0x01) with zero length elements is invalid
   2688  1.1  christos 		 */
   2689  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x01, 0x00, 0x00, 0x01, 0x00, 0x05,
   2690  1.1  christos 			     0x00, 0x00, 0x00, 0x00, 0x00),
   2691  1.1  christos 		WIRE_SENTINEL()
   2692  1.1  christos 	};
   2693  1.1  christos 	/* Test vectors from RFCXXXX */
   2694  1.1  christos 	textvsunknown_t textvsunknown[] = {
   2695  1.1  christos 		/* AliasForm */
   2696  1.1  christos 		{ "0 foo.example.com", "\\# 19 ( 00 00 03 66 6f 6f 07 65 78 61 "
   2697  1.1  christos 				       "6d 70 6c 65 03 63 6f 6d 00)" },
   2698  1.1  christos 		/* ServiceForm */
   2699  1.1  christos 		{ "1 .", "\\# 3 ( 00 01 00)" },
   2700  1.1  christos 		/* Port example */
   2701  1.1  christos 		{ "16 foo.example.com port=53",
   2702  1.1  christos 		  "\\# 25 ( 00 10 03 66 6f 6f 07 65 78 61 6d 70 6c 65 03 63 6f "
   2703  1.1  christos 		  "6d 00 00 03 00 02 00 35 )" },
   2704  1.1  christos 		/* Unregistered keys with unquoted value. */
   2705  1.1  christos 		{ "1 foo.example.com key667=hello",
   2706  1.1  christos 		  "\\# 28 ( 00 01 03 66 6f 6f 07 65 78 61 6d 70 6c 65 03 63 6f "
   2707  1.1  christos 		  "6d 00 02 9b 00 05 68 65 6c 6c 6f )" },
   2708  1.1  christos 		/*
   2709  1.1  christos 		 * Quoted decimal-escaped character.
   2710  1.1  christos 		 * 1 foo.example.com key667="hello\210qoo"
   2711  1.1  christos 		 */
   2712  1.1  christos 		{ "1 foo.example.com key667=\"hello\\210qoo\"",
   2713  1.1  christos 		  "\\# 32 ( 00 01 03 66 6f 6f 07 65 78 61 6d 70 6c 65 03 63 6f "
   2714  1.1  christos 		  "6d 00 02 9b 00 09 68 65 6c 6c 6f d2 71 6f 6f )" },
   2715  1.1  christos 		/*
   2716  1.1  christos 		 * IPv6 hints example, quoted.
   2717  1.1  christos 		 * 1 foo.example.com ipv6hint="2001:db8::1,2001:db8::53:1"
   2718  1.1  christos 		 */
   2719  1.1  christos 		{ "1 foo.example.com ipv6hint=\"2001:db8::1,2001:db8::53:1\"",
   2720  1.1  christos 		  "\\# 55 ( 00 01 03 66 6f 6f 07 65 78 61 6d 70 6c 65 03 63 6f "
   2721  1.1  christos 		  "6d 00 00 06 00 20 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 "
   2722  1.1  christos 		  "00 01 20 01 0d b8 00 00 00 00 00 00 00 00 00 53 00 01 )" },
   2723  1.1  christos 		/* SvcParamValues and mandatory out of order. */
   2724  1.1  christos 		{ "16 foo.example.org alpn=h2,h3-19 mandatory=ipv4hint,alpn "
   2725  1.1  christos 		  "ipv4hint=192.0.2.1",
   2726  1.1  christos 		  "\\# 48 ( 00 10 03 66 6f 6f 07 65 78 61 6d 70 6c 65 03 6f 72 "
   2727  1.1  christos 		  "67 00 00 00 00 04 00 01 00 04 00 01 00 09 02 68 32 05 68 33 "
   2728  1.1  christos 		  "2d 31 39 00 04 00 04 c0 00 02 01 )" },
   2729  1.1  christos 		/*
   2730  1.1  christos 		 * Quoted ALPN with escaped comma and backslash.
   2731  1.1  christos 		 * 16 foo.example.org alpn="f\\\\oo\\,bar,h2"
   2732  1.1  christos 		 */
   2733  1.1  christos 		{ "16 foo.example.org alpn=\"f\\\\\\\\oo\\\\,bar,h2\"",
   2734  1.1  christos 		  "\\# 35 ( 00 10 03 66 6f 6f 07 65 78 61 6d 70 6c 65 03 6f 72 "
   2735  1.1  christos 		  "67 00 00 01 00 0c 08 66 5c 6f 6f 2c 62 61 72 02 68 32 )" },
   2736  1.1  christos 		/*
   2737  1.1  christos 		 * Unquoted ALPN with escaped comma and backslash.
   2738  1.1  christos 		 * 16 foo.example.org alpn=f\\\092oo\092,bar,h2
   2739  1.1  christos 		 */
   2740  1.1  christos 		{ "16 foo.example.org alpn=f\\\\\\092oo\\092,bar,h2",
   2741  1.1  christos 		  "\\# 35 ( 00 10 03 66 6f 6f 07 65 78 61 6d 70 6c 65 03 6f 72 "
   2742  1.1  christos 		  "67 00 00 01 00 0c 08 66 5c 6f 6f 2c 62 61 72 02 68 32 )" },
   2743  1.1  christos 		{ NULL, NULL }
   2744  1.1  christos 	};
   2745  1.1  christos 
   2746  1.1  christos 	check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
   2747  1.1  christos 		    dns_rdatatype_svcb, sizeof(dns_rdata_in_svcb_t));
   2748  1.1  christos 	check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
   2749  1.1  christos 		    dns_rdatatype_https, sizeof(dns_rdata_in_https_t));
   2750  1.1  christos 
   2751  1.1  christos 	check_textvsunknown(textvsunknown, dns_rdataclass_in,
   2752  1.1  christos 			    dns_rdatatype_svcb);
   2753  1.1  christos 	check_textvsunknown(textvsunknown, dns_rdataclass_in,
   2754  1.1  christos 			    dns_rdatatype_https);
   2755  1.1  christos }
   2756  1.1  christos 
   2757  1.1  christos /*
   2758  1.1  christos  * ZONEMD tests.
   2759  1.1  christos  *
   2760  1.1  christos  * Excerpted from RFC 8976:
   2761  1.1  christos  *
   2762  1.1  christos  * The ZONEMD RDATA wire format is encoded as follows:
   2763  1.1  christos  *
   2764  1.1  christos  *                         1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 3 3
   2765  1.1  christos  *     0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
   2766  1.1  christos  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   2767  1.1  christos  *    |                             Serial                            |
   2768  1.1  christos  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   2769  1.1  christos  *    |    Scheme     |Hash Algorithm |                               |
   2770  1.1  christos  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+                               |
   2771  1.1  christos  *    |                             Digest                            |
   2772  1.1  christos  *    /                                                               /
   2773  1.1  christos  *    /                                                               /
   2774  1.1  christos  *    +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
   2775  1.1  christos  *
   2776  1.1  christos  * 2.2.1.  The Serial Field
   2777  1.1  christos  *
   2778  1.1  christos  *    The Serial field is a 32-bit unsigned integer in network byte order.
   2779  1.1  christos  *    It is the serial number from the zone's SOA record ([RFC1035],
   2780  1.1  christos  *    Section 3.3.13) for which the zone digest was generated.
   2781  1.1  christos  *
   2782  1.1  christos  *    It is included here to clearly bind the ZONEMD RR to a particular
   2783  1.1  christos  *    version of the zone's content.  Without the serial number, a stand-
   2784  1.1  christos  *    alone ZONEMD digest has no obvious association to any particular
   2785  1.1  christos  *    instance of a zone.
   2786  1.1  christos  *
   2787  1.1  christos  * 2.2.2.  The Scheme Field
   2788  1.1  christos  *
   2789  1.1  christos  *    The Scheme field is an 8-bit unsigned integer that identifies the
   2790  1.1  christos  *    methods by which data is collated and presented as input to the
   2791  1.1  christos  *    hashing function.
   2792  1.1  christos  *
   2793  1.1  christos  *    Herein, SIMPLE, with Scheme value 1, is the only standardized Scheme
   2794  1.1  christos  *    defined for ZONEMD records and it MUST be supported by
   2795  1.1  christos  *    implementations.  The "ZONEMD Schemes" registry is further described
   2796  1.1  christos  *    in Section 5.
   2797  1.1  christos  *
   2798  1.1  christos  *    Scheme values 240-254 are allocated for Private Use.
   2799  1.1  christos  *
   2800  1.1  christos  * 2.2.3.  The Hash Algorithm Field
   2801  1.1  christos  *
   2802  1.1  christos  *    The Hash Algorithm field is an 8-bit unsigned integer that identifies
   2803  1.1  christos  *    the cryptographic hash algorithm used to construct the digest.
   2804  1.1  christos  *
   2805  1.1  christos  *    Herein, SHA384 ([RFC6234]), with Hash Algorithm value 1, is the only
   2806  1.1  christos  *    standardized Hash Algorithm defined for ZONEMD records that MUST be
   2807  1.1  christos  *    supported by implementations.  When SHA384 is used, the size of the
   2808  1.1  christos  *    Digest field is 48 octets.  The result of the SHA384 digest algorithm
   2809  1.1  christos  *    MUST NOT be truncated, and the entire 48-octet digest is published in
   2810  1.1  christos  *    the ZONEMD record.
   2811  1.1  christos  *
   2812  1.1  christos  *    SHA512 ([RFC6234]), with Hash Algorithm value 2, is also defined for
   2813  1.1  christos  *    ZONEMD records and SHOULD be supported by implementations.  When
   2814  1.1  christos  *    SHA512 is used, the size of the Digest field is 64 octets.  The
   2815  1.1  christos  *    result of the SHA512 digest algorithm MUST NOT be truncated, and the
   2816  1.1  christos  *    entire 64-octet digest is published in the ZONEMD record.
   2817  1.1  christos  *
   2818  1.1  christos  *    Hash Algorithm values 240-254 are allocated for Private Use.
   2819  1.1  christos  *
   2820  1.1  christos  *    The "ZONEMD Hash Algorithms" registry is further described in
   2821  1.1  christos  *    Section 5.
   2822  1.1  christos  *
   2823  1.1  christos  * 2.2.4.  The Digest Field
   2824  1.1  christos  *
   2825  1.1  christos  *    The Digest field is a variable-length sequence of octets containing
   2826  1.1  christos  *    the output of the hash algorithm.  The length of the Digest field is
   2827  1.1  christos  *    determined by deducting the fixed size of the Serial, Scheme, and
   2828  1.1  christos  *    Hash Algorithm fields from the RDATA size in the ZONEMD RR header.
   2829  1.1  christos  *
   2830  1.1  christos  *    The Digest field MUST NOT be shorter than 12 octets.  Digests for the
   2831  1.1  christos  *    SHA384 and SHA512 hash algorithms specified herein are never
   2832  1.1  christos  *    truncated.  Digests for future hash algorithms MAY be truncated but
   2833  1.1  christos  *    MUST NOT be truncated to a length that results in less than 96 bits
   2834  1.1  christos  *    (12 octets) of equivalent strength.
   2835  1.1  christos  *
   2836  1.1  christos  *    Section 3 describes how to calculate the digest for a zone.
   2837  1.1  christos  *    Section 4 describes how to use the digest to verify the contents of a
   2838  1.1  christos  *    zone.
   2839  1.1  christos  *
   2840  1.1  christos  */
   2841  1.1  christos 
   2842  1.1  christos ISC_RUN_TEST_IMPL(zonemd) {
   2843  1.1  christos 	text_ok_t text_ok[] = {
   2844  1.1  christos 		TEXT_INVALID(""),
   2845  1.1  christos 		/* No digest scheme or digest type*/
   2846  1.1  christos 		TEXT_INVALID("0"),
   2847  1.1  christos 		/* No digest type */
   2848  1.1  christos 		TEXT_INVALID("0 0"),
   2849  1.1  christos 		/* No digest */
   2850  1.1  christos 		TEXT_INVALID("0 0 0"),
   2851  1.1  christos 		/* No digest */
   2852  1.1  christos 		TEXT_INVALID("99999999 0 0"),
   2853  1.1  christos 		/* No digest */
   2854  1.1  christos 		TEXT_INVALID("2019020700 0 0"),
   2855  1.1  christos 		/* Digest too short */
   2856  1.1  christos 		TEXT_INVALID("2019020700 1 1 DEADBEEF"),
   2857  1.1  christos 		/* Digest too short */
   2858  1.1  christos 		TEXT_INVALID("2019020700 1 2 DEADBEEF"),
   2859  1.1  christos 		/* Digest too short */
   2860  1.1  christos 		TEXT_INVALID("2019020700 1 3 DEADBEEFDEADBEEFDEADBE"),
   2861  1.1  christos 		/* Digest type unknown */
   2862  1.1  christos 		TEXT_VALID("2019020700 1 3 DEADBEEFDEADBEEFDEADBEEF"),
   2863  1.1  christos 		/* Digest type max */
   2864  1.1  christos 		TEXT_VALID("2019020700 1 255 DEADBEEFDEADBEEFDEADBEEF"),
   2865  1.1  christos 		/* Digest type too big */
   2866  1.1  christos 		TEXT_INVALID("2019020700 0 256 DEADBEEFDEADBEEFDEADBEEF"),
   2867  1.1  christos 		/* Scheme max */
   2868  1.1  christos 		TEXT_VALID("2019020700 255 3 DEADBEEFDEADBEEFDEADBEEF"),
   2869  1.1  christos 		/* Scheme too big */
   2870  1.1  christos 		TEXT_INVALID("2019020700 256 3 DEADBEEFDEADBEEFDEADBEEF"),
   2871  1.1  christos 		/* SHA384 */
   2872  1.1  christos 		TEXT_VALID("2019020700 1 1 "
   2873  1.1  christos 			   "7162D2BB75C047A53DE98767C9192BEB"
   2874  1.1  christos 			   "14DB01E7E2267135DAF0230A 19BA4A31"
   2875  1.1  christos 			   "6AF6BF64AA5C7BAE24B2992850300509"),
   2876  1.1  christos 		/* SHA512 */
   2877  1.1  christos 		TEXT_VALID("2019020700 1 2 "
   2878  1.1  christos 			   "08CFA1115C7B948C4163A901270395EA"
   2879  1.1  christos 			   "226A930CD2CBCF2FA9A5E6EB 85F37C8A"
   2880  1.1  christos 			   "4E114D884E66F176EAB121CB02DB7D65"
   2881  1.1  christos 			   "2E0CC4827E7A3204 F166B47E5613FD27"),
   2882  1.1  christos 		/* SHA384 too short and with private scheme */
   2883  1.1  christos 		TEXT_INVALID("2021042801 0 1 "
   2884  1.1  christos 			     "7162D2BB75C047A53DE98767C9192BEB"
   2885  1.1  christos 			     "6AF6BF64AA5C7BAE24B2992850300509"),
   2886  1.1  christos 		/* SHA512 too short and with private scheme */
   2887  1.1  christos 		TEXT_INVALID("2021042802 5 2 "
   2888  1.1  christos 			     "A897B40072ECAE9E4CA3F1F227DE8F5E"
   2889  1.1  christos 			     "480CDEBB16DFC64C1C349A7B5F6C71AB"
   2890  1.1  christos 			     "E8A88B76EF0BA1604EC25752E946BF98"),
   2891  1.1  christos 		TEXT_SENTINEL()
   2892  1.1  christos 	};
   2893  1.1  christos 	wire_ok_t wire_ok[] = {
   2894  1.1  christos 		/*
   2895  1.1  christos 		 * Short.
   2896  1.1  christos 		 */
   2897  1.1  christos 		WIRE_INVALID(0x00),
   2898  1.1  christos 		/*
   2899  1.1  christos 		 * Short.
   2900  1.1  christos 		 */
   2901  1.1  christos 		WIRE_INVALID(0x00, 0x00),
   2902  1.1  christos 		/*
   2903  1.1  christos 		 * Short.
   2904  1.1  christos 		 */
   2905  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00),
   2906  1.1  christos 		/*
   2907  1.1  christos 		 * Short.
   2908  1.1  christos 		 */
   2909  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x00),
   2910  1.1  christos 		/*
   2911  1.1  christos 		 * Short.
   2912  1.1  christos 		 */
   2913  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x00, 0x00),
   2914  1.1  christos 		/*
   2915  1.1  christos 		 * Short.
   2916  1.1  christos 		 */
   2917  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00),
   2918  1.1  christos 		/*
   2919  1.1  christos 		 * Short 11-octet digest.
   2920  1.1  christos 		 */
   2921  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   2922  1.1  christos 			     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   2923  1.1  christos 			     0x00),
   2924  1.1  christos 		/*
   2925  1.1  christos 		 * Minimal, 12-octet hash for an undefined digest type.
   2926  1.1  christos 		 */
   2927  1.1  christos 		WIRE_VALID(0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   2928  1.1  christos 			   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   2929  1.1  christos 			   0x00),
   2930  1.1  christos 		/*
   2931  1.1  christos 		 * SHA-384 is defined, so we insist there be a digest of
   2932  1.1  christos 		 * the expected length.
   2933  1.1  christos 		 */
   2934  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00,
   2935  1.1  christos 			     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
   2936  1.1  christos 			     0x00, 0x00),
   2937  1.1  christos 		/*
   2938  1.1  christos 		 * 48-octet digest, valid for SHA-384.
   2939  1.1  christos 		 */
   2940  1.1  christos 		WIRE_VALID(0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0xde, 0xad, 0xbe,
   2941  1.1  christos 			   0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce,
   2942  1.1  christos 			   0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe,
   2943  1.1  christos 			   0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce,
   2944  1.1  christos 			   0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe,
   2945  1.1  christos 			   0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa,
   2946  1.1  christos 			   0xce),
   2947  1.1  christos 		/*
   2948  1.1  christos 		 * 56-octet digest, too long for SHA-384.
   2949  1.1  christos 		 */
   2950  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x00, 0x01, 0x01, 0xde, 0xad,
   2951  1.1  christos 			     0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
   2952  1.1  christos 			     0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce,
   2953  1.1  christos 			     0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad,
   2954  1.1  christos 			     0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
   2955  1.1  christos 			     0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce,
   2956  1.1  christos 			     0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad,
   2957  1.1  christos 			     0xbe, 0xef, 0xfa, 0xce),
   2958  1.1  christos 		/*
   2959  1.1  christos 		 * 56-octet digest, too short for SHA-512
   2960  1.1  christos 		 */
   2961  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0xde, 0xad,
   2962  1.1  christos 			     0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
   2963  1.1  christos 			     0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce,
   2964  1.1  christos 			     0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad,
   2965  1.1  christos 			     0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
   2966  1.1  christos 			     0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce,
   2967  1.1  christos 			     0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad,
   2968  1.1  christos 			     0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad),
   2969  1.1  christos 		/*
   2970  1.1  christos 		 * 64-octet digest, just right for SHA-512
   2971  1.1  christos 		 */
   2972  1.1  christos 		WIRE_VALID(0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0xde, 0xad, 0xbe,
   2973  1.1  christos 			   0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce,
   2974  1.1  christos 			   0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe,
   2975  1.1  christos 			   0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce,
   2976  1.1  christos 			   0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe,
   2977  1.1  christos 			   0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce,
   2978  1.1  christos 			   0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe,
   2979  1.1  christos 			   0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef),
   2980  1.1  christos 		/*
   2981  1.1  christos 		 * 72-octet digest, too long for SHA-512
   2982  1.1  christos 		 */
   2983  1.1  christos 		WIRE_INVALID(0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0xde, 0xad,
   2984  1.1  christos 			     0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
   2985  1.1  christos 			     0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce,
   2986  1.1  christos 			     0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad,
   2987  1.1  christos 			     0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
   2988  1.1  christos 			     0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce,
   2989  1.1  christos 			     0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad,
   2990  1.1  christos 			     0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef,
   2991  1.1  christos 			     0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce,
   2992  1.1  christos 			     0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce),
   2993  1.1  christos 		/*
   2994  1.1  christos 		 * 56-octet digest, valid for an undefined digest type.
   2995  1.1  christos 		 */
   2996  1.1  christos 		WIRE_VALID(0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0xde, 0xad, 0xbe,
   2997  1.1  christos 			   0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce,
   2998  1.1  christos 			   0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe,
   2999  1.1  christos 			   0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce,
   3000  1.1  christos 			   0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe,
   3001  1.1  christos 			   0xef, 0xfa, 0xce, 0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce,
   3002  1.1  christos 			   0xde, 0xad, 0xbe, 0xef, 0xfa, 0xce),
   3003  1.1  christos 		/*
   3004  1.1  christos 		 * Sentinel.
   3005  1.1  christos 		 */
   3006  1.1  christos 		WIRE_SENTINEL()
   3007  1.1  christos 	};
   3008  1.1  christos 
   3009  1.1  christos 	check_rdata(text_ok, wire_ok, NULL, false, dns_rdataclass_in,
   3010  1.1  christos 		    dns_rdatatype_zonemd, sizeof(dns_rdata_zonemd_t));
   3011  1.1  christos }
   3012  1.1  christos 
   3013  1.1  christos ISC_RUN_TEST_IMPL(atcname) {
   3014  1.1  christos 	unsigned int i;
   3015  1.1  christos 
   3016  1.1  christos #define UNR "# Unexpected result from dns_rdatatype_atcname for type %u\n"
   3017  1.1  christos 	for (i = 0; i < 0xffffU; i++) {
   3018  1.1  christos 		bool tf = dns_rdatatype_atcname((dns_rdatatype_t)i);
   3019  1.1  christos 		switch (i) {
   3020  1.1  christos 		case dns_rdatatype_nsec:
   3021  1.1  christos 		case dns_rdatatype_key:
   3022  1.1  christos 		case dns_rdatatype_rrsig:
   3023  1.1  christos 			if (!tf) {
   3024  1.1  christos 				print_message(UNR, i);
   3025  1.1  christos 			}
   3026  1.1  christos 			assert_true(tf);
   3027  1.1  christos 			break;
   3028  1.1  christos 		default:
   3029  1.1  christos 			if (tf) {
   3030  1.1  christos 				print_message(UNR, i);
   3031  1.1  christos 			}
   3032  1.1  christos 			assert_false(tf);
   3033  1.1  christos 			break;
   3034  1.1  christos 		}
   3035  1.1  christos 	}
   3036  1.1  christos #undef UNR
   3037  1.1  christos }
   3038  1.1  christos 
   3039  1.1  christos ISC_RUN_TEST_IMPL(atparent) {
   3040  1.1  christos 	unsigned int i;
   3041  1.1  christos 
   3042  1.1  christos #define UNR "# Unexpected result from dns_rdatatype_atparent for type %u\n"
   3043  1.1  christos 	for (i = 0; i < 0xffffU; i++) {
   3044  1.1  christos 		bool tf = dns_rdatatype_atparent((dns_rdatatype_t)i);
   3045  1.1  christos 		switch (i) {
   3046  1.1  christos 		case dns_rdatatype_ds:
   3047  1.1  christos 			if (!tf) {
   3048  1.1  christos 				print_message(UNR, i);
   3049  1.1  christos 			}
   3050  1.1  christos 			assert_true(tf);
   3051  1.1  christos 			break;
   3052  1.1  christos 		default:
   3053  1.1  christos 			if (tf) {
   3054  1.1  christos 				print_message(UNR, i);
   3055  1.1  christos 			}
   3056  1.1  christos 			assert_false(tf);
   3057  1.1  christos 			break;
   3058  1.1  christos 		}
   3059  1.1  christos 	}
   3060  1.1  christos #undef UNR
   3061  1.1  christos }
   3062  1.1  christos 
   3063  1.1  christos ISC_RUN_TEST_IMPL(iszonecutauth) {
   3064  1.1  christos 	unsigned int i;
   3065  1.1  christos #define UNR "# Unexpected result from dns_rdatatype_iszonecutauth for type %u\n"
   3066  1.1  christos 	for (i = 0; i < 0xffffU; i++) {
   3067  1.1  christos 		bool tf = dns_rdatatype_iszonecutauth((dns_rdatatype_t)i);
   3068  1.1  christos 		switch (i) {
   3069  1.1  christos 		case dns_rdatatype_ns:
   3070  1.1  christos 		case dns_rdatatype_ds:
   3071  1.1  christos 		case dns_rdatatype_nsec:
   3072  1.1  christos 		case dns_rdatatype_key:
   3073  1.1  christos 		case dns_rdatatype_rrsig:
   3074  1.1  christos 			if (!tf) {
   3075  1.1  christos 				print_message(UNR, i);
   3076  1.1  christos 			}
   3077  1.1  christos 			assert_true(tf);
   3078  1.1  christos 			break;
   3079  1.1  christos 		default:
   3080  1.1  christos 			if (tf) {
   3081  1.1  christos 				print_message(UNR, i);
   3082  1.1  christos 			}
   3083  1.1  christos 			assert_false(tf);
   3084  1.1  christos 			break;
   3085  1.1  christos 		}
   3086  1.1  christos 	}
   3087  1.1  christos #undef UNR
   3088  1.1  christos }
   3089  1.1  christos 
   3090  1.1  christos ISC_TEST_LIST_START
   3091  1.1  christos 
   3092  1.1  christos /* types */
   3093  1.1  christos ISC_TEST_ENTRY(amtrelay)
   3094  1.1  christos ISC_TEST_ENTRY(apl)
   3095  1.1  christos ISC_TEST_ENTRY(atma)
   3096  1.1  christos ISC_TEST_ENTRY(cdnskey)
   3097  1.1  christos ISC_TEST_ENTRY(csync)
   3098  1.1  christos ISC_TEST_ENTRY(dnskey)
   3099  1.1  christos ISC_TEST_ENTRY(doa)
   3100  1.1  christos ISC_TEST_ENTRY(ds)
   3101  1.1  christos ISC_TEST_ENTRY(eid)
   3102  1.1  christos ISC_TEST_ENTRY(hip)
   3103  1.1  christos ISC_TEST_ENTRY(https_svcb)
   3104  1.1  christos ISC_TEST_ENTRY(isdn)
   3105  1.1  christos ISC_TEST_ENTRY(key)
   3106  1.1  christos ISC_TEST_ENTRY(loc)
   3107  1.1  christos ISC_TEST_ENTRY(nimloc)
   3108  1.1  christos ISC_TEST_ENTRY(nsec)
   3109  1.1  christos ISC_TEST_ENTRY(nsec3)
   3110  1.1  christos ISC_TEST_ENTRY(nxt)
   3111  1.1  christos ISC_TEST_ENTRY(rkey)
   3112  1.1  christos ISC_TEST_ENTRY(sshfp)
   3113  1.1  christos ISC_TEST_ENTRY(wks)
   3114  1.1  christos ISC_TEST_ENTRY(zonemd)
   3115  1.1  christos 
   3116  1.1  christos /* other tests */
   3117  1.1  christos ISC_TEST_ENTRY(edns_client_subnet)
   3118  1.1  christos ISC_TEST_ENTRY(atcname)
   3119  1.1  christos ISC_TEST_ENTRY(atparent)
   3120  1.1  christos ISC_TEST_ENTRY(iszonecutauth)
   3121  1.1  christos ISC_TEST_LIST_END
   3122  1.1  christos 
   3123  1.1  christos ISC_TEST_MAIN
   3124