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 <yubihsm.h>
18
19#include <stddef.h>
20
21#define ERR(name, desc) \
22 { name, desc }
23
24typedef struct {
26 const char *description;
27} err_t;
28
29static const err_t errors[] = {
30 ERR(YHR_SUCCESS, "Success"),
31 ERR(YHR_MEMORY_ERROR, "Unable to allocate memory"),
32 ERR(YHR_INIT_ERROR, "Unable to initialize libyubihsm"),
33 ERR(YHR_CONNECTION_ERROR, "Connection error"),
34 ERR(YHR_CONNECTOR_NOT_FOUND, "Unable to find a suitable connector"),
35 ERR(YHR_INVALID_PARAMETERS, "Invalid argument to a function"),
36 ERR(YHR_WRONG_LENGTH, "Mismatch between expected and received length"),
37 ERR(YHR_BUFFER_TOO_SMALL, "Not enough space to store data"),
38 ERR(YHR_CRYPTOGRAM_MISMATCH, "Unable to verify cryptogram"),
39 ERR(YHR_SESSION_AUTHENTICATION_FAILED, "Unable to authenticate session"),
40 ERR(YHR_MAC_MISMATCH, "Unable to verify MAC"),
41 ERR(YHR_DEVICE_OK, "No error"),
42 ERR(YHR_DEVICE_INVALID_COMMAND, "Invalid command"),
43 ERR(YHR_DEVICE_INVALID_DATA, "Malformed command / invalid data"),
44 ERR(YHR_DEVICE_INVALID_SESSION, "Invalid session"),
46 "Message encryption / verification failed"),
47 ERR(YHR_DEVICE_SESSIONS_FULL, "All sessions are allocated"),
48 ERR(YHR_DEVICE_SESSION_FAILED, "Session creation failed"),
49 ERR(YHR_DEVICE_STORAGE_FAILED, "Storage failure"),
50 ERR(YHR_DEVICE_WRONG_LENGTH, "Wrong length"),
51 ERR(YHR_DEVICE_INSUFFICIENT_PERMISSIONS, "Wrong permissions for operation"),
52 ERR(YHR_DEVICE_LOG_FULL, "Log buffer is full and forced audit is set"),
53 ERR(YHR_DEVICE_OBJECT_NOT_FOUND, "Object not found"),
54 ERR(YHR_DEVICE_INVALID_ID, "Invalid ID used"),
55 ERR(YHR_DEVICE_INVALID_OTP, "Invalid OTP"),
56 ERR(YHR_DEVICE_DEMO_MODE, "Demo mode, power cycle device"),
58 "The command execution has not terminated"),
59 ERR(YHR_GENERIC_ERROR, "Generic error"),
60 ERR(YHR_DEVICE_OBJECT_EXISTS, "An Object with that ID already exists"),
61 ERR(YHR_CONNECTOR_ERROR, "Connector operation failed"),
62 ERR(YHR_DEVICE_SSH_CA_CONSTRAINT_VIOLATION, "SSH CA constraint violation"),
63};
64
65const char *yh_strerror(yh_rc err) {
66 static const char *unknown = "Unknown yubihsm error";
67 const char *p;
68
69 if (-err < 0 || -err >= (int) (sizeof(errors) / sizeof(errors[0]))) {
70 return unknown;
71 }
72
73 p = errors[-err].description;
74 if (!p) {
75 p = unknown;
76 }
77
78 return p;
79}
const mie::Vuint & p
Definition bn.cpp:27
const char * yh_strerror(yh_rc err)
Definition error.c:65
#define ERR(name, desc)
Definition error.c:21
Definition error.c:24
const char * description
Definition error.c:26
yh_rc rc
Definition error.c:25
yh_rc
Definition yubihsm.h:170
@ YHR_INIT_ERROR
Returned value when failing to initialize libyubihsm.
Definition yubihsm.h:176
@ YHR_DEVICE_INSUFFICIENT_PERMISSIONS
Return value when the permissions to perform the operation are wrong.
Definition yubihsm.h:214
@ YHR_DEVICE_INVALID_SESSION
Returned value when the device session is invalid.
Definition yubihsm.h:201
@ YHR_GENERIC_ERROR
Return value when encountering an unknown error.
Definition yubihsm.h:228
@ YHR_SUCCESS
Returned value when function was successful.
Definition yubihsm.h:172
@ YHR_DEVICE_COMMAND_UNEXECUTED
Return value when the command execution has not terminated.
Definition yubihsm.h:226
@ YHR_INVALID_PARAMETERS
Returned value when an argument to a function is invalid.
Definition yubihsm.h:182
@ YHR_MEMORY_ERROR
Returned value when unable to allocate memory.
Definition yubihsm.h:174
@ YHR_DEVICE_INVALID_COMMAND
Returned value when the device receives and invalid command.
Definition yubihsm.h:197
@ YHR_DEVICE_SESSIONS_FULL
Return value when no more sessions can be opened on the device.
Definition yubihsm.h:205
@ YHR_DEVICE_SESSION_FAILED
Return value when failing to create a device session.
Definition yubihsm.h:207
@ YHR_DEVICE_OBJECT_NOT_FOUND
Return value when the object not found on the device.
Definition yubihsm.h:218
@ YHR_DEVICE_AUTHENTICATION_FAILED
Return value when the device fails to encrypt or verify the message.
Definition yubihsm.h:203
@ YHR_DEVICE_LOG_FULL
Return value when the log buffer is full and forced audit is set.
Definition yubihsm.h:216
@ YHR_DEVICE_INVALID_OTP
Return value when an invalid OTP is submitted.
Definition yubihsm.h:222
@ YHR_DEVICE_DEMO_MODE
Return value when the device is in demo mode and has to be power cycled.
Definition yubihsm.h:224
@ YHR_DEVICE_INVALID_DATA
Returned value when the device receives a malformed command invalid data.
Definition yubihsm.h:199
@ YHR_CONNECTOR_NOT_FOUND
Returned value when failing to find a suitable connector.
Definition yubihsm.h:180
@ YHR_DEVICE_STORAGE_FAILED
Return value when encountering a storage failure on the device.
Definition yubihsm.h:209
@ YHR_DEVICE_OBJECT_EXISTS
Return value when trying to add an object with an ID that already exists.
Definition yubihsm.h:230
@ YHR_BUFFER_TOO_SMALL
Returned value when there is not enough space to store data.
Definition yubihsm.h:187
@ YHR_CONNECTOR_ERROR
Return value when connector operation failed.
Definition yubihsm.h:232
@ YHR_MAC_MISMATCH
Returned value when failing to verify MAC.
Definition yubihsm.h:193
@ YHR_WRONG_LENGTH
Definition yubihsm.h:185
@ YHR_DEVICE_WRONG_LENGTH
Definition yubihsm.h:212
@ YHR_CONNECTION_ERROR
Returned value when a connection error was encountered.
Definition yubihsm.h:178
@ YHR_DEVICE_SSH_CA_CONSTRAINT_VIOLATION
Return value when encountering SSH CA constraint violation.
Definition yubihsm.h:234
@ YHR_DEVICE_OK
Returned value when the device returned no error.
Definition yubihsm.h:195
@ YHR_DEVICE_INVALID_ID
Return value when an invalid Object ID is used.
Definition yubihsm.h:220
@ YHR_SESSION_AUTHENTICATION_FAILED
Returned value when failing to authenticate the session.
Definition yubihsm.h:191
@ YHR_CRYPTOGRAM_MISMATCH
Returned value when failing to verify cryptogram.
Definition yubihsm.h:189
bool unknown