Browse Source

Centralize error codes and messages

Define all error codes and error messages in a dedicated header.
develop
Damien Goutte-Gattat 5 years ago
parent
commit
7cd5d806ca
  1. 2
      src/Makefile.am
  2. 31
      src/gfsec-errors.h
  3. 55
      src/secret.c
  4. 18
      src/secret.h

2
src/Makefile.am

@ -1,7 +1,7 @@
bin_PROGRAMS = gfsec-use
gfsec_use_SOURCES = gfsec-use.c util.c util.h secret.c secret.h \
secretcfg.c secretcfg.h \
secretcfg.c secretcfg.h gfsec-errors.h \
mtp-support.c mtp-support.h \
uuid-support.c uuid-support.h

31
src/gfsec-errors.h

@ -0,0 +1,31 @@
/*
* gfsecret - Secret sharing tools
* Copyright (C) 2016 Damien Goutte-Gattat
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
GFSEC_ERROR(SUCCESS, 0, "Success")
GFSEC_ERROR(SYSTEM_ERROR, -1, strerror(errno))
GFSEC_ERROR(INVALID_CALL, -2, "A function was improperly called")
GFSEC_ERROR(NOT_ENOUGH_SHARES, -3, "Not enough shares available to reconstitute the secret")
GFSEC_ERROR(TOO_MANY_SHARES, -4, "Too many shares")
GFSEC_ERROR(SHARE_NOT_AVAILABLE, -5, "A share is not available")
GFSEC_ERROR(INVALID_LENGTH, -6, "Shares have inconsistent lengths")
GFSEC_ERROR(INVALID_SHARE, -7, "Checksum failed for share data")
GFSEC_ERROR(CONFIG_LINE_TOO_LONG, -9, "Line too long")
GFSEC_ERROR(CONFIG_INVALID_URI, -10, "Invalid share URI")
GFSEC_ERROR(CONFIG_INVALID_HASH, -11, "Invalid hash value")
GFSEC_ERROR(CONFIG_UNKNOWN_SCHEME, -12, "Unknown URI scheme")
GFSEC_ERROR(CONFIG_INVALID_THRESHOLD, -13, "Invalid threshold")

55
src/secret.c

@ -411,57 +411,12 @@ gfsec_error_string(int err)
const char *msg;
switch ( err ) {
case 0:
msg = "Success";
break;
case GFSEC_ERR_SYSTEM_ERROR:
msg = strerror(errno);
break;
case GFSEC_ERR_INVALID_CALL:
msg = "A function was improperly called";
break;
case GFSEC_ERR_NOT_ENOUGH_SHARES:
msg = "Not enough shares available to reconstitute the secret";
break;
case GFSEC_ERR_TOO_MANY_SHARES:
msg = "Too many shares";
break;
case GFSEC_ERR_SHARE_NOT_AVAILABLE:
msg = "A share is not available";
break;
case GFSEC_ERR_INVALID_LENGTH:
msg = "Shares have inconsistent lengths";
break;
case GFSEC_ERR_INVALID_SHARE:
msg = "Checksum failed for share data";
break;
case GFSEC_ERR_CONFIG_LINE_TOO_LONG:
msg = "Line too long";
break;
case GFSEC_ERR_CONFIG_INVALID_URI:
msg = "Invalid share URI";
break;
case GFSEC_ERR_CONFIG_INVALID_HASH:
msg = "Invalid hash value";
break;
case GFSEC_ERR_CONFIG_UNKNOWN_SCHEME:
msg = "Unknown URI scheme";
break;
case GFSEC_ERR_CONFIG_INVALID_THRESHOLD:
msg = "Invalid threshold";
#define GFSEC_ERROR(symbol, value, message) \
case GFSEC_ERR_##symbol: \
msg = message; \
break;
#include "gfsec-errors.h"
#undef GFSEC_ERROR
default: /* Should not happen. */
msg = "Unknown error";

18
src/secret.h

@ -19,18 +19,12 @@
#ifndef ICP20160807_SECRET_H
#define ICP20160807_SECRET_H
#define GFSEC_ERR_SYSTEM_ERROR -1
#define GFSEC_ERR_INVALID_CALL -2
#define GFSEC_ERR_NOT_ENOUGH_SHARES -3
#define GFSEC_ERR_TOO_MANY_SHARES -4
#define GFSEC_ERR_SHARE_NOT_AVAILABLE -5
#define GFSEC_ERR_INVALID_LENGTH -6
#define GFSEC_ERR_INVALID_SHARE -7
#define GFSEC_ERR_CONFIG_LINE_TOO_LONG -9
#define GFSEC_ERR_CONFIG_INVALID_URI -10
#define GFSEC_ERR_CONFIG_INVALID_HASH -11
#define GFSEC_ERR_CONFIG_UNKNOWN_SCHEME -12
#define GFSEC_ERR_CONFIG_INVALID_THRESHOLD -13
enum gfsec_error {
#define GFSEC_ERROR(symbol, value, message) \
GFSEC_ERR_##symbol = value,
#include "gfsec-errors.h"
#undef GFSEC_ERROR
};
#define GFSEC_SHARE_NUMBER_FULL 0
#define GFSEC_SHARE_NUMBER_AUTOASSIGN 256

Loading…
Cancel
Save