comparison common/binverify.h @ 1081:edbf5e5e88f4

(issue118) Extend verify_binary to carry an open file * binverify.c: Change result to a structure containing an open fptr Use in Memory data for windows verification. * mainwindow.cpp, selftest.c: Handle the returend structure * binverifytest.cpp: Test for the exclusive read and update signature. * listutil.c: Add optional fptr parameter to read_file
author Andre Heinecke <andre.heinecke@intevation.de>
date Thu, 11 Sep 2014 12:05:24 +0200
parents 78798d3af8f0
children 2a1aa9df8f11
comparison
equal deleted inserted replaced
1080:898b1ddcca11 1081:edbf5e5e88f4
11 /* @file binverify.h 11 /* @file binverify.h
12 * @brief Verification of binary files 12 * @brief Verification of binary files
13 */ 13 */
14 #include <stdbool.h> 14 #include <stdbool.h>
15 #include <stddef.h> 15 #include <stddef.h>
16 #include <stdio.h>
16 17
17 #ifdef __cplusplus 18 #ifdef __cplusplus
18 extern "C" { 19 extern "C" {
19 #endif 20 #endif
20 21
21 /** 22 /**
22 * @enum bin_verify_result 23 * @enum verify_result
23 * @brief Result of a verification 24 * @brief Result of a verification
24 */ 25 */
25 typedef enum { 26 typedef enum {
26 VerifyValid = 100, /*! Could be read and signature matched */ 27 VerifyValid = 100, /*! Could be read and signature matched */
27 VerifyUnknownError = 1, /*! The expected unexpected */ 28 VerifyUnknownError = 1, /*! The expected unexpected */
28 VerifyInvalidSignature = 4, /*! Signature was invalid */ 29 VerifyInvalidSignature = 4, /*! Signature was invalid */
29 VerifyInvalidCertificate = 5, /*! Certificate mismatch */ 30 VerifyInvalidCertificate = 5, /*! Certificate mismatch */
30 VerifyReadFailed = 6, /*! File exists but could not read the file */ 31 VerifyReadFailed = 6, /*! File exists but could not read the file */
32 } verify_result;
33
34 /**
35 * A structure containing a verify_result and a reference to the
36 * verified file.
37 */
38 typedef struct {
39 /*@{*/
40 verify_result result; /**< the result of the verification */
41 FILE *fptr; /**< Pointer to the open file struct of the verified file
42 The ptr is only valid if verify_result is VerifyValid
43 and needs to be closed by the caller in that case.*/
44 /*@}*/
31 } bin_verify_result; 45 } bin_verify_result;
32 46
33 /** 47 /**
34 * @brief verify a binary 48 * @brief verify a binary
35 * 49 *
55 * 69 *
56 * @returns the verification result. 70 * @returns the verification result.
57 */ 71 */
58 bin_verify_result verify_binary(const char *filename, size_t name_len); 72 bin_verify_result verify_binary(const char *filename, size_t name_len);
59 73
74 /**@def Max size of a valid binary in byte */
75 #define MAX_VALID_BIN_SIZE (32 * 1024 * 1024)
76
60 #ifdef WIN32 77 #ifdef WIN32
61 /** 78 /**
62 * @brief windows implementation of verify_binary 79 * @brief windows implementation of verify_binary
63 */ 80 */
64 bin_verify_result verify_binary_win(const char *filename, size_t name_len); 81 bin_verify_result verify_binary_win(const char *filename, size_t name_len);
65 #else /* WIN32 */ 82 #else /* WIN32 */
66 /**@def Max size of a valid binary in byte */
67 #define MAX_VALID_BIN_SIZE (32 * 1024 * 1024)
68 83
69 /** 84 /**
70 * @brief linux implementation of verify_binary 85 * @brief linux implementation of verify_binary
71 */ 86 */
72 bin_verify_result verify_binary_linux(const char *filename, size_t name_len); 87 bin_verify_result verify_binary_linux(const char *filename, size_t name_len);

http://wald.intevation.org/projects/trustbridge/