xref: /netbsd-src/external/mpl/dhcp/bind/dist/lib/isc/pk11_result.c (revision 4afad4b7fa6d4a0d3dedf41d1587a7250710ae54)
1 /*	$NetBSD: pk11_result.c,v 1.1 2024/02/18 20:57:50 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 <stddef.h>
17 
18 #include <isc/once.h>
19 #include <isc/util.h>
20 
21 #include <pk11/result.h>
22 
23 static const char *text[PK11_R_NRESULTS] = {
24 	"PKCS#11 initialization failed", /*%< 0 */
25 	"no PKCS#11 provider",		 /*%< 1 */
26 	"PKCS#11 no random service",	 /*%< 2 */
27 	"PKCS#11 no digist service",	 /*%< 3 */
28 	"PKCS#11 no AES service",	 /*%< 4 */
29 };
30 
31 static const char *ids[PK11_R_NRESULTS] = {
32 	"PK11_R_INITFAILED",	  "PK11_R_NOPROVIDER",
33 	"PK11_R_NORANDOMSERVICE", "PK11_R_NODIGESTSERVICE",
34 	"PK11_R_NOAESSERVICE",
35 };
36 
37 #define PK11_RESULT_RESULTSET 2
38 
39 static isc_once_t once = ISC_ONCE_INIT;
40 
41 static void
initialize_action(void)42 initialize_action(void) {
43 	isc_result_t result;
44 
45 	result = isc_result_register(ISC_RESULTCLASS_PK11, PK11_R_NRESULTS,
46 				     text, PK11_RESULT_RESULTSET);
47 	if (result != ISC_R_SUCCESS) {
48 		UNEXPECTED_ERROR(__FILE__, __LINE__,
49 				 "isc_result_register() failed: %u", result);
50 	}
51 
52 	result = isc_result_registerids(ISC_RESULTCLASS_PK11, PK11_R_NRESULTS,
53 					ids, PK11_RESULT_RESULTSET);
54 	if (result != ISC_R_SUCCESS) {
55 		UNEXPECTED_ERROR(__FILE__, __LINE__,
56 				 "isc_result_registerids() failed: %u", result);
57 	}
58 }
59 
60 static void
initialize(void)61 initialize(void) {
62 	RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS);
63 }
64 
65 const char *
pk11_result_totext(isc_result_t result)66 pk11_result_totext(isc_result_t result) {
67 	initialize();
68 
69 	return (isc_result_totext(result));
70 }
71 
72 void
pk11_result_register(void)73 pk11_result_register(void) {
74 	initialize();
75 }
76