Contiki-NG
Loading...
Searching...
No Matches
cose-error.c
Go to the documentation of this file.
1/*
2 * Copyright (c) 2024, RISE Research Institutes of Sweden AB
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. Neither the name of the copyright holder nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 */
29
30/**
31 * \file
32 * COSE error implementation
33 * \author
34 * Niclas Finne <niclas.finne@ri.se>, Nicolas Tsiftes <nicolas.tsiftes@ri.se>
35 */
36
37#include "cose-error.h"
38
39/*---------------------------------------------------------------------------*/
40const char *
42{
43 switch(error) {
44 case COSE_SUCCESS:
45 return "Success";
46
47 /* Parameter and input errors */
49 return "Invalid parameter";
51 return "Null pointer";
53 return "Buffer too small";
55 return "Invalid length";
57 return "Algorithm not supported";
58
59 /* Memory and buffer errors */
61 return "Memory allocation failed";
63 return "Buffer overflow";
64
65 /* Cryptographic operation errors */
67 return "Key generation failed";
69 return "Digital signature failed";
71 return "Signature verification failed";
73 return "Encryption failed";
75 return "Decryption failed";
77 return "Authentication tag verification failed";
79 return "Invalid cryptographic key";
80
81 /* CBOR structure errors */
83 return "CBOR encoding failed";
85 return "CBOR decoding failed";
87 return "Invalid CBOR type";
89 return "Malformed CBOR data";
90
91 /* COSE structure errors */
93 return "Invalid COSE structure";
95 return "Required header missing";
97 return "Invalid header content";
99 return "Required payload missing";
100
101 /* General errors */
103 return "Not implemented";
105 return "Internal error";
106 case COSE_ERR_UNKNOWN:
107 return "Unknown error";
108
109 default:
110 return "Unrecognized COSE error code";
111 }
112}
113/*---------------------------------------------------------------------------*/
const char * cose_error_string(cose_error_t error)
Get a human-readable error message for a COSE error.
Definition cose-error.c:41
COSE library error definitions.
cose_error_t
COSE operation error codes.
Definition cose-error.h:53
@ COSE_ERR_CRYPTO_ENCRYPT
Encryption operation failed.
Definition cose-error.h:72
@ COSE_ERR_BUFFER_TOO_SMALL
Buffer too small for operation.
Definition cose-error.h:60
@ COSE_ERR_CRYPTO_KEYGEN
Key generation failed.
Definition cose-error.h:69
@ COSE_ERR_INVALID_LENGTH
Invalid length parameter.
Definition cose-error.h:61
@ COSE_ERR_MISSING_HEADER
Required header missing.
Definition cose-error.h:85
@ COSE_ERR_UNSUPPORTED_ALGORITHM
Algorithm not supported.
Definition cose-error.h:62
@ COSE_ERR_CBOR_MALFORMED
Malformed CBOR data.
Definition cose-error.h:81
@ COSE_ERR_UNKNOWN
Unknown error condition.
Definition cose-error.h:92
@ COSE_ERR_CRYPTO_SIGN
Digital signature failed.
Definition cose-error.h:70
@ COSE_ERR_CRYPTO_AUTHENTICATION
Authentication tag verification failed.
Definition cose-error.h:74
@ COSE_ERR_CRYPTO_VERIFY
Signature verification failed.
Definition cose-error.h:71
@ COSE_ERR_CBOR_DECODING
CBOR decoding failed.
Definition cose-error.h:79
@ COSE_ERR_BUFFER_OVERFLOW
Buffer overflow detected.
Definition cose-error.h:66
@ COSE_ERR_MISSING_PAYLOAD
Required payload missing.
Definition cose-error.h:87
@ COSE_ERR_INVALID_PARAMETER
Invalid parameter provided.
Definition cose-error.h:58
@ COSE_ERR_CBOR_ENCODING
CBOR encoding failed.
Definition cose-error.h:78
@ COSE_ERR_NOT_IMPLEMENTED
Feature not implemented.
Definition cose-error.h:90
@ COSE_ERR_INVALID_STRUCTURE
Invalid COSE structure.
Definition cose-error.h:84
@ COSE_ERR_CRYPTO_DECRYPT
Decryption operation failed.
Definition cose-error.h:73
@ COSE_ERR_NULL_POINTER
Null pointer provided.
Definition cose-error.h:59
@ COSE_ERR_INVALID_HEADER
Invalid header content.
Definition cose-error.h:86
@ COSE_ERR_INTERNAL_ERROR
Internal implementation error.
Definition cose-error.h:91
@ COSE_ERR_MEMORY_ALLOCATION
Memory allocation failed.
Definition cose-error.h:65
@ COSE_ERR_CBOR_INVALID_TYPE
Invalid CBOR data type.
Definition cose-error.h:80
@ COSE_ERR_CRYPTO_INVALID_KEY
Invalid cryptographic key.
Definition cose-error.h:75