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 23static 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 31static 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 39static isc_once_t once = ISC_ONCE_INIT; 40 41static void 42initialize_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 60static void 61initialize(void) { 62 RUNTIME_CHECK(isc_once_do(&once, initialize_action) == ISC_R_SUCCESS); 63} 64 65const char * 66pk11_result_totext(isc_result_t result) { 67 initialize(); 68 69 return (isc_result_totext(result)); 70} 71 72void 73pk11_result_register(void) { 74 initialize(); 75} 76