xref: /netbsd-src/external/mpl/dhcp/bind/dist/lib/dns/dst_result.c (revision 4afad4b7fa6d4a0d3dedf41d1587a7250710ae54)
1 /*	$NetBSD: dst_result.c,v 1.1 2024/02/18 20:57:31 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 #include <isc/once.h>
17 #include <isc/util.h>
18 
19 #include <dst/result.h>
20 
21 static const char *text[DST_R_NRESULTS] = {
22 	"algorithm is unsupported",		 /*%< 0 */
23 	"crypto failure",			 /*%< 1 */
24 	"built with no crypto support",		 /*%< 2 */
25 	"illegal operation for a null key",	 /*%< 3 */
26 	"public key is invalid",		 /*%< 4 */
27 	"private key is invalid",		 /*%< 5 */
28 	"external key",				 /*%< 6 */
29 	"error occurred writing key to disk",	 /*%< 7 */
30 	"invalid algorithm specific parameter",	 /*%< 8 */
31 	"UNUSED9",				 /*%< 9 */
32 	"UNUSED10",				 /*%< 10 */
33 	"sign failure",				 /*%< 11 */
34 	"UNUSED12",				 /*%< 12 */
35 	"UNUSED13",				 /*%< 13 */
36 	"verify failure",			 /*%< 14 */
37 	"not a public key",			 /*%< 15 */
38 	"not a private key",			 /*%< 16 */
39 	"not a key that can compute a secret",	 /*%< 17 */
40 	"failure computing a shared secret",	 /*%< 18 */
41 	"no randomness available",		 /*%< 19 */
42 	"bad key type",				 /*%< 20 */
43 	"no engine",				 /*%< 21 */
44 	"illegal operation for an external key", /*%< 22 */
45 };
46 
47 static const char *ids[DST_R_NRESULTS] = {
48 	"DST_R_UNSUPPORTEDALG",
49 	"DST_R_CRYPTOFAILURE",
50 	"DST_R_NOCRYPTO",
51 	"DST_R_NULLKEY",
52 	"DST_R_INVALIDPUBLICKEY",
53 	"DST_R_INVALIDPRIVATEKEY",
54 	"UNUSED",
55 	"DST_R_WRITEERROR",
56 	"DST_R_INVALIDPARAM",
57 	"UNUSED",
58 	"UNUSED",
59 	"DST_R_SIGNFAILURE",
60 	"UNUSED",
61 	"UNUSED",
62 	"DST_R_VERIFYFAILURE",
63 	"DST_R_NOTPUBLICKEY",
64 	"DST_R_NOTPRIVATEKEY",
65 	"DST_R_KEYCANNOTCOMPUTESECRET",
66 	"DST_R_COMPUTESECRETFAILURE",
67 	"DST_R_NORANDOMNESS",
68 	"DST_R_BADKEYTYPE",
69 	"DST_R_NOENGINE",
70 	"DST_R_EXTERNALKEY",
71 };
72 
73 #define DST_RESULT_RESULTSET 2
74 
75 static isc_once_t once = ISC_ONCE_INIT;
76 
77 static void
initialize_action(void)78 initialize_action(void) {
79 	isc_result_t result;
80 
81 	result = isc_result_register(ISC_RESULTCLASS_DST, DST_R_NRESULTS, text,
82 				     DST_RESULT_RESULTSET);
83 	if (result != ISC_R_SUCCESS) {
84 		UNEXPECTED_ERROR(__FILE__, __LINE__,
85 				 "isc_result_register() failed: %u", result);
86 	}
87 	result = isc_result_registerids(ISC_RESULTCLASS_DST, DST_R_NRESULTS,
88 					ids, DST_RESULT_RESULTSET);
89 	if (result != ISC_R_SUCCESS) {
90 		UNEXPECTED_ERROR(__FILE__, __LINE__,
91 				 "isc_result_registerids() failed: %u", result);
92 	}
93 }
94 
95 static void
initialize(void)96 initialize(void) {
97 	RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
98 }
99 
100 const char *
dst_result_totext(isc_result_t result)101 dst_result_totext(isc_result_t result) {
102 	initialize();
103 
104 	return (isc_result_totext(result));
105 }
106 
107 void
dst_result_register(void)108 dst_result_register(void) {
109 	initialize();
110 }
111 
112 /*! \file */
113