File: scryptenc_print_error.c

package info (click to toggle)
scrypt 1.3.3-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,368 kB
  • sloc: ansic: 5,763; sh: 5,504; makefile: 257
file content (77 lines) | stat: -rw-r--r-- 1,935 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#include <assert.h>
#include <stddef.h>

#include "warnp.h"

#include "scryptenc.h"
#include "scryptenc_print_error.h"

/**
 * scryptenc_print_error(rc, infilename, outfilename):
 * Print the error corresponding to ${rc}.  If relevant, use ${infilename}
 * or ${outfilename} to display an error about reading or writing; these
 * arguments can be NULL to indicate standard input or output.
 */
void
scryptenc_print_error(int rc, const char * infilename,
    const char * outfilename)
{

	/* Sanity check: this should only be used for errors. */
	assert(rc != SCRYPT_OK);

	/* Display error. */
	switch (rc) {
	case SCRYPT_ELIMIT:
		warnp("Error determining amount of available memory");
		break;
	case SCRYPT_ECLOCK:
		warnp("Error reading clocks");
		break;
	case SCRYPT_EKEY:
		warnp("Error computing derived key");
		break;
	case SCRYPT_ESALT:
		warnp("Error reading salt");
		break;
	case SCRYPT_EOPENSSL:
		warnp("OpenSSL error");
		break;
	case SCRYPT_ENOMEM:
		warnp("Error allocating memory");
		break;
	case SCRYPT_EINVAL:
		warn0("Input is not valid scrypt-encrypted block");
		break;
	case SCRYPT_EVERSION:
		warn0("Unrecognized scrypt format version");
		break;
	case SCRYPT_ETOOBIG:
		warn0("Decrypting file would require too much memory");
		break;
	case SCRYPT_ETOOSLOW:
		warn0("Decrypting file would take too much CPU time");
		break;
	case SCRYPT_EBIGSLOW:
		warn0("Decrypting file would require too much memory"
		    " and CPU time");
		break;
	case SCRYPT_EPASS:
		warn0("Passphrase is incorrect");
		break;
	case SCRYPT_EWRFILE:
		warnp("Error writing file: %s",
		    (outfilename != NULL) ? outfilename : "standard output");
		break;
	case SCRYPT_ERDFILE:
		warnp("Error reading file: %s",
		    (infilename != NULL) ? infilename : "standard input");
		break;
	case SCRYPT_EPARAM:
		warn0("Error in explicit parameters");
		break;
	default:
		warn0("Programmer error: unrecognized scrypt error");
		break;
	}
}