summaryrefslogtreecommitdiff
path: root/futility/file_type.h
blob: e1efe760d766faa57b6e0c34279fd9698d80f190 (plain)
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
78
79
/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#ifndef VBOOT_REFERENCE_FILE_TYPE_H_
#define VBOOT_REFERENCE_FILE_TYPE_H_

/* What type of things do I know how to handle? */
enum futil_file_type {
	FILE_TYPE_UNKNOWN,
#define FILE_TYPE(A, B, C, D, E, F) FILE_TYPE_ ## A,
#include "file_type.inc"
#undef FILE_TYPE
	NUM_FILE_TYPES
};

/* Short name for file types */
const char * const futil_file_type_name(enum futil_file_type type);

/* Description of file type */
const char * const futil_file_type_desc(enum futil_file_type type);

/* Print the list of type names and exit with the given value. */
void print_file_types_and_exit(int retval);

/* Lookup a type by name. Return true on success */
int futil_str_to_file_type(const char *str, enum futil_file_type *type);

/*
 * This tries to match the buffer content to one of the known file types.
 */
enum futil_file_type futil_file_type_buf(uint8_t *buf, uint32_t len);

/*
 * This opens a file and tries to match it to one of the known file types.
 * It's not an error if it returns FILE_TYPE_UKNOWN.
 */
enum futil_file_err futil_file_type(const char *filename,
				    enum futil_file_type *type);

/*
 * Call the show() method on a buffer containing a specific file type.
 * Returns zero on success. It's up to the caller to ensure that only valid
 * file types are invoked.
 */
int futil_file_type_show(enum futil_file_type type,
			 const char *filename,
			 uint8_t *buf, uint32_t len);

/*
 * Call the sign() method on a buffer containing a specific file type.
 * Returns zero on success. It's up to the caller to ensure that only valid
 * file types are invoked.
 */
int futil_file_type_sign(enum futil_file_type type,
			 const char *filename,
			 uint8_t *buf, uint32_t len);

/*
 * Declare the file_type functions. Certain functions are reused for more than
 * one file type, leading to redundant declarations here.
 */
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wredundant-decls"
#define R_(FOO) \
	enum futil_file_type FOO(uint8_t *buf, uint32_t len);
#define S_(FOO) \
	int FOO(const char *name, uint8_t *buf, uint32_t len, void *data);
#define NONE
#define FILE_TYPE(A, B, C, D, E, F) D E F
#include "file_type.inc"
#undef FILE_TYPE
#undef NONE
#undef S_
#undef R_
#pragma GCC diagnostic pop

#endif  /* VBOOT_REFERENCE_FILE_TYPE_H_ */