File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -75,6 +75,10 @@ enum {
7575 CRYPT_HASH_OVERFLOW , /* Hash applied to too many bits */
7676 CRYPT_PW_CTX_MISSING , /* Password context to decrypt key file is missing */
7777 CRYPT_UNKNOWN_PEM , /* The PEM header was not recognized */
78+
79+ /* Here only follows the number of error codes.
80+ * This will never be returned and shall always be at the end of the enum. */
81+ CRYPT_ERR_NUM
7882};
7983
8084#include "tomcrypt_cfg.h"
Original file line number Diff line number Diff line change 88 Convert error codes to ASCII strings, Tom St Denis
99*/
1010
11- static const char * const err_2_str [] =
11+ static const char * const err_2_str [CRYPT_ERR_NUM ] =
1212{
1313 "CRYPT_OK" ,
1414 "CRYPT_ERROR" ,
@@ -44,27 +44,26 @@ static const char * const err_2_str[] =
4444
4545 "The input was longer than expected." ,
4646
47- "Invalid sized parameter ." ,
47+ "Invalid size input for PK parameters ." ,
4848
4949 "Invalid size for prime." ,
50-
5150 "Invalid padding." ,
5251
5352 "Hash applied to too many bits." ,
54-
5553 "Password context to decrypt key file is missing." ,
56-
5754 "The PEM header was not recognized" ,
5855};
5956
57+ LTC_STATIC_ASSERT (correct_err_2_str_size , (sizeof (err_2_str )/sizeof (err_2_str [0 ])) == CRYPT_ERR_NUM )
58+
6059/**
6160 Convert an LTC error code to ASCII
6261 @param err The error code
6362 @return A pointer to the ASCII NUL terminated string for the error or "Invalid error code." if the err code was not valid.
6463*/
6564const char * error_to_string (int err )
6665{
67- if (err < 0 || err >= ( int )( sizeof ( err_2_str )/ sizeof ( err_2_str [ 0 ])) ) {
66+ if (err < 0 || err >= CRYPT_ERR_NUM ) {
6867 return "Invalid error code." ;
6968 }
7069 return err_2_str [err ];
You can’t perform that action at this time.
0 commit comments