comparison common/listutil.c @ 40:5cb1eb928253

Clean up debug output / functions
author Andre Heinecke <aheinecke@intevation.de>
date Fri, 14 Mar 2014 09:47:42 +0000
parents fc6241283474
children 7055a79abe02
comparison
equal deleted inserted replaced
39:ee27186fc8e6 40:5cb1eb928253
21 #include <polarssl/base64.h> 21 #include <polarssl/base64.h>
22 #include <polarssl/sha256.h> 22 #include <polarssl/sha256.h>
23 #pragma GCC diagnostic pop 23 #pragma GCC diagnostic pop
24 24
25 #define MAX_FILESIZE 1048576 /* 1024*1024 */ 25 #define MAX_FILESIZE 1048576 /* 1024*1024 */
26
27 void handle_errno()
28 {
29 printf("Error: %s \n", strerror(errno));
30 }
31 26
32 /** 27 /**
33 * @brief Read a file into memory. 28 * @brief Read a file into memory.
34 * 29 *
35 * The caller needs to free data 30 * The caller needs to free data
116 char signature_b64[sig_b64_size + 1]; 111 char signature_b64[sig_b64_size + 1];
117 unsigned char signature[sig_size]; 112 unsigned char signature[sig_size];
118 /* Hash algroithm is sha256 */ 113 /* Hash algroithm is sha256 */
119 unsigned char hash[32]; 114 unsigned char hash[32];
120 115
121 printf ("size: %lu", (unsigned long) size);
122
123 /* Fetch the signature from the first line od data */ 116 /* Fetch the signature from the first line od data */
124 p = strchr(data, '\r'); 117 p = strchr(data, '\r');
125 if (p == 0 || (unsigned int)(p - (data + 2)) != sig_b64_size) { 118 if (p == 0 || (unsigned int)(p - (data + 2)) != sig_b64_size) {
126 printf("Invalid data. Signature might be too long.\n"); 119 /* printf("Invalid data. Signature might be too long.\n"); */
127 return -1; 120 return -1;
128 } 121 }
129 strncpy(signature_b64, data + 2, sig_b64_size); 122 strncpy(signature_b64, data + 2, sig_b64_size);
130 signature_b64[sig_b64_size] = '\0'; 123 signature_b64[sig_b64_size] = '\0';
131 124
132 ret = base64_decode(signature, &sig_size, 125 ret = base64_decode(signature, &sig_size,
133 (unsigned char *)signature_b64, sig_b64_size); 126 (unsigned char *)signature_b64, sig_b64_size);
134 127
135 if (ret != 0 || sig_size != 384) { 128 if (ret != 0 || sig_size != 384) {
136 printf("failed to decode signature\n"); 129 /* printf("failed to decode signature\n"); */
137 return -1; 130 return -1;
138 } 131 }
139 132
140 /* Hash is calculated over the data without the first line. 133 /* Hash is calculated over the data without the first line.
141 * linebreaks are \r\n so the first char of the new line is 134 * linebreaks are \r\n so the first char of the new line is
191 *size = 0; 184 *size = 0;
192 int ret = 0; 185 int ret = 0;
193 186
194 ret = read_file(file_name, data, size, MAX_FILESIZE); 187 ret = read_file(file_name, data, size, MAX_FILESIZE);
195 188
189 /* printf ("Ret: %i \n", ret); */
196 if (ret != 0) { 190 if (ret != 0) {
197 if (ret == READ_FILE_TOO_LARGE) { 191 if (ret == READ_FILE_TOO_LARGE) {
198 return TooLarge; 192 return TooLarge;
199 } 193 }
200 if (ret == READ_FILE_UNREADABLE) { 194 if (ret == READ_FILE_UNREADABLE) {
205 } 199 }
206 return UnknownError; 200 return UnknownError;
207 } 201 }
208 202
209 if (!*data || !*size) { 203 if (!*data || !*size) {
204 /* File is probably empty */
210 return UnknownError; 205 return UnknownError;
211 } 206 }
212 207
213 if (**data != 'S') { 208 if (**data != 'S') {
214 retval = InvalidFormat; 209 retval = InvalidFormat;

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