-static size_t hex_to_bytes(const char *hex, char *result)
-{
- char buf[3] = "xx\0", *endp;
- size_t i, len;
-
- len = strlen(hex) / 2;
- for (i = 0; i < len; i++) {
- memcpy(buf, &hex[i * 2], 2);
- result[i] = strtoul(buf, &endp, 16);
- if (endp != &buf[2])
- return -EINVAL;
- }
- return i;
-}
-
-__attribute__((format(printf, 5, 6)))
-static void clogger(struct crypt_device *cd, int level, const char *file,
- int line, const char *format, ...)
-{
- va_list argp;
- char *target = NULL;
-
- va_start(argp, format);
-
- if (vasprintf(&target, format, argp) > 0) {
- if (level >= 0) {
- crypt_log(cd, level, target);
-#ifdef CRYPT_DEBUG
- } else if (opt_debug)
- printf("# %s:%d %s\n", file ?: "?", line, target);
-#else
- } else if (opt_debug)
- printf("# %s\n", target);
-#endif
- }
-
- va_end(argp);
- free(target);
-}
-
-static void _log(int level, const char *msg, void *usrptr __attribute__((unused)))
-{
- switch(level) {
-
- case CRYPT_LOG_NORMAL:
- fputs(msg, stdout);
- break;
- case CRYPT_LOG_VERBOSE:
- if (opt_verbose)
- fputs(msg, stdout);
- break;
- case CRYPT_LOG_ERROR:
- fputs(msg, stderr);
- break;
- case CRYPT_LOG_DEBUG:
- if (opt_debug)
- printf("# %s\n", msg);
- break;
- default:
- fprintf(stderr, "Internal error on logging class for msg: %s", msg);
- break;
- }
-}
-