Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
error.c
Go to the documentation of this file.
1/*
2 * Copyright 2015-2018 Yubico AB
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#include "ykyh.h"
18
19#include <stddef.h>
20
21#define ERR(name, desc) \
22 { name, #name, desc }
23
24typedef struct {
26 const char *name;
27 const char *description;
28} err_t;
29
30static const err_t errors[] = {
31 ERR(YKYHR_SUCCESS, "Successful return"),
32 ERR(YKYHR_MEMORY_ERROR, "Error allocating memory"),
33 ERR(YKYHR_PCSC_ERROR, "Error in PCSC call"),
34 ERR(YKYHR_GENERIC_ERROR, "Something went wrong"),
35 ERR(YKYHR_WRONG_PW, "Wrong Password"),
36 ERR(YKYHR_INVALID_PARAMS, "Invalid argument to a function"),
37 ERR(YKYHR_ENTRY_NOT_FOUND, "Entry not found"),
38};
39
40const char *ykyh_strerror(ykyh_rc err) {
41 static const char *unknown = "Unknown ykyh error";
42 const char *p;
43
44 if (-err < 0 || -err >= (int) (sizeof(errors) / sizeof(errors[0]))) {
45 return unknown;
46 }
47
48 p = errors[-err].description;
49 if (!p) {
50 p = unknown;
51 }
52
53 return p;
54}
55
56const char *ykyh_strerror_name(ykyh_rc err) {
57 if (-err < 0 || -err >= (int) (sizeof(errors) / sizeof(errors[0]))) {
58 return NULL;
59 }
60
61 return errors[-err].name;
62}
const mie::Vuint & p
Definition bn.cpp:27
#define ERR(name, desc)
Definition error.c:21
Definition error.c:24
const char * description
Definition error.c:26
const char * name
Definition error.c:26
ykyh_rc rc
Definition error.c:25
const char * ykyh_strerror(ykyh_rc err)
Definition error.c:40
const char * ykyh_strerror_name(ykyh_rc err)
Definition error.c:56
ykyh_rc
Definition ykyh.h:76
@ YKYHR_INVALID_PARAMS
Definition ykyh.h:82
@ YKYHR_GENERIC_ERROR
Definition ykyh.h:80
@ YKYHR_SUCCESS
Definition ykyh.h:77
@ YKYHR_MEMORY_ERROR
Definition ykyh.h:78
@ YKYHR_PCSC_ERROR
Definition ykyh.h:79
@ YKYHR_ENTRY_NOT_FOUND
Definition ykyh.h:83
@ YKYHR_WRONG_PW
Definition ykyh.h:81
bool unknown