1/*	$NetBSD: zonekey.c,v 1.1 2024/02/18 20:57:34 christos Exp $	*/
2
3/*
4 * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5 *
6 * SPDX-License-Identifier: MPL-2.0
7 *
8 * This Source Code Form is subject to the terms of the Mozilla Public
9 * License, v. 2.0. If a copy of the MPL was not distributed with this
10 * file, you can obtain one at https://mozilla.org/MPL/2.0/.
11 *
12 * See the COPYRIGHT file distributed with this work for additional
13 * information regarding copyright ownership.
14 */
15
16/*! \file */
17
18#include <stdbool.h>
19
20#include <isc/result.h>
21#include <isc/types.h>
22#include <isc/util.h>
23
24#include <dns/keyvalues.h>
25#include <dns/rdata.h>
26#include <dns/rdatastruct.h>
27#include <dns/types.h>
28#include <dns/zonekey.h>
29
30bool
31dns_zonekey_iszonekey(dns_rdata_t *keyrdata) {
32	isc_result_t result;
33	dns_rdata_dnskey_t key;
34	bool iszonekey = true;
35
36	REQUIRE(keyrdata != NULL);
37
38	result = dns_rdata_tostruct(keyrdata, &key, NULL);
39	if (result != ISC_R_SUCCESS) {
40		return (false);
41	}
42
43	if ((key.flags & DNS_KEYTYPE_NOAUTH) != 0) {
44		iszonekey = false;
45	}
46	if ((key.flags & DNS_KEYFLAG_OWNERMASK) != DNS_KEYOWNER_ZONE) {
47		iszonekey = false;
48	}
49	if (key.protocol != DNS_KEYPROTO_DNSSEC &&
50	    key.protocol != DNS_KEYPROTO_ANY)
51	{
52		iszonekey = false;
53	}
54
55	return (iszonekey);
56}
57