Line data Source code
1 : //
2 : // jose_error.c
3 : // cjose_cjson
4 : //
5 : // Created by Danny Goossen on 22/1/18.
6 : // Copyright (c) 2018 Danny Goossen. All rights reserved.
7 : //
8 : #include <openssl/err.h>
9 : #include "jose_error.h"
10 : /**
11 : *
12 : * Copyrights
13 : *
14 : * Portions created or assigned to Cisco Systems, Inc. are
15 : * Copyright (c) 2014-2016 Cisco Systems, Inc. All Rights Reserved.
16 : */
17 :
18 :
19 :
20 :
21 : ////////////////////////////////////////////////////////////////////////////////
22 : static const char *_ERR_MSG_TABLE[] = { "no error", "invalid argument", "invalid state", "out of memory", "crypto error" };
23 :
24 : ////////////////////////////////////////////////////////////////////////////////
25 0 : const char *jose_err_message(jose_errcode code)
26 : {
27 0 : const char *retval = NULL;
28 0 : if (JOSE_ERR_CRYPTO == code)
29 : {
30 : // for crypto errors, return the most recent openssl error as message
31 0 : long err = ERR_get_error();
32 0 : while (0 != err)
33 : {
34 0 : retval = ERR_error_string(err, NULL);
35 0 : err = ERR_get_error();
36 : }
37 : }
38 0 : if (NULL == retval)
39 : {
40 0 : retval = _ERR_MSG_TABLE[code];
41 : }
42 0 : return retval;
43 : }
|