c-multihash/errors.c

24 lines
638 B
C
Raw Normal View History

2016-07-25 10:51:54 +00:00
/* vim: set ts=8 sw=8 noexpandtab: */
#include "errors.h"
static const struct mh_error_desc {
int code;
2016-07-25 11:06:39 +00:00
const char *message;
2016-07-25 10:51:54 +00:00
} mh_errordesc[] = {
{ MH_E_UNKNOWN_CODE, "unknown multihash code" },
{ MH_E_TOO_SHORT, "multihash too short. must be > 3 bytes" },
{ MH_E_TOO_LONG, "multihash too long. must be < 129 bytes" },
{ MH_E_LEN_NOT_SUPPORTED, "multihash does not yet support"
" digests longer than 127 bytes" }
};
const char *mh_error_string(mh_error code) {
2016-07-25 11:06:39 +00:00
unsigned int i = 0;
for (; i < sizeof(mh_errordesc); i++) {
if (mh_errordesc[i].code == code)
return mh_errordesc->message;
}
return "unknown error code";
2016-07-25 10:51:54 +00:00
}