summaryrefslogtreecommitdiff
path: root/legacy/eet/src/bin
diff options
context:
space:
mode:
authorCarsten Haitzler <raster@rasterman.com>2010-07-28 01:45:57 +0000
committerCarsten Haitzler <raster@rasterman.com>2010-07-28 01:45:57 +0000
commit926db95c5476a7e58ae30873227140b627fc292d (patch)
tree921fa2fb03c97910853287c1a15379175e845994 /legacy/eet/src/bin
parentba10bce4342f61992ceaf06dc6299639cac83a81 (diff)
testing uncrustify on eet. this shall be standard efl formatting from
now on. you may run indent on code and convert to your own formatting if you want.. but all code MUST be "uncrustified" before being cxommitted to svn or before generating patches. time to get the formatting monster under control. SVN revision: 50563
Diffstat (limited to 'legacy/eet/src/bin')
-rw-r--r--legacy/eet/src/bin/eet_main.c219
1 files changed, 123 insertions, 96 deletions
diff --git a/legacy/eet/src/bin/eet_main.c b/legacy/eet/src/bin/eet_main.c
index 5964d8a8ef..587146f7b8 100644
--- a/legacy/eet/src/bin/eet_main.c
+++ b/legacy/eet/src/bin/eet_main.c
@@ -58,20 +58,25 @@ do_eet_list(const char *file)
58 if (!ef) 58 if (!ef)
59 { 59 {
60 ERR("cannot open for reading: %s\n", file); 60 ERR("cannot open for reading: %s\n", file);
61 exit(-1); 61 exit(-1);
62 } 62 }
63
63 list = eet_list(ef, "*", &num); 64 list = eet_list(ef, "*", &num);
64 if (list) 65 if (list)
65 { 66 {
66 for (i = 0; i < num; i++) 67 for (i = 0; i < num; i++)
67 printf("%s\n",list[i]); 68 printf("%s\n",list[i]);
68 free(list); 69 free(list);
69 } 70 }
71
70 eet_close(ef); 72 eet_close(ef);
71} 73}
72 74
73static void 75static void
74do_eet_extract(const char *file, const char *key, const char *out, const char *crypto_key) 76do_eet_extract(const char *file,
77 const char *key,
78 const char *out,
79 const char *crypto_key)
75{ 80{
76 Eet_File *ef; 81 Eet_File *ef;
77 void *data; 82 void *data;
@@ -81,26 +86,30 @@ do_eet_extract(const char *file, const char *key, const char *out, const char *c
81 ef = eet_open(file, EET_FILE_MODE_READ); 86 ef = eet_open(file, EET_FILE_MODE_READ);
82 if (!ef) 87 if (!ef)
83 { 88 {
84 ERR("cannot open for reading: %s\n", file); 89 ERR("cannot open for reading: %s\n", file);
85 exit(-1); 90 exit(-1);
86 } 91 }
92
87 data = eet_read_cipher(ef, key, &size, crypto_key); 93 data = eet_read_cipher(ef, key, &size, crypto_key);
88 if (!data) 94 if (!data)
89 { 95 {
90 ERR("cannot read key %s\n", key); 96 ERR("cannot read key %s\n", key);
91 exit(-1); 97 exit(-1);
92 } 98 }
99
93 f = fopen(out, "wb"); 100 f = fopen(out, "wb");
94 if (!f) 101 if (!f)
95 { 102 {
96 ERR("cannot open %s\n", out); 103 ERR("cannot open %s\n", out);
97 exit(-1); 104 exit(-1);
98 } 105 }
106
99 if (fwrite(data, size, 1, f) != 1) 107 if (fwrite(data, size, 1, f) != 1)
100 { 108 {
101 ERR("cannot write to %s\n", out); 109 ERR("cannot write to %s\n", out);
102 exit(-1); 110 exit(-1);
103 } 111 }
112
104 fclose(f); 113 fclose(f);
105 free(data); 114 free(data);
106 eet_close(ef); 115 eet_close(ef);
@@ -113,7 +122,10 @@ do_eet_decode_dump(void *data, const char *str)
113} 122}
114 123
115static void 124static void
116do_eet_decode(const char *file, const char *key, const char *out, const char *crypto_key) 125do_eet_decode(const char *file,
126 const char *key,
127 const char *out,
128 const char *crypto_key)
117{ 129{
118 Eet_File *ef; 130 Eet_File *ef;
119 FILE *f; 131 FILE *f;
@@ -121,26 +133,33 @@ do_eet_decode(const char *file, const char *key, const char *out, const char *cr
121 ef = eet_open(file, EET_FILE_MODE_READ); 133 ef = eet_open(file, EET_FILE_MODE_READ);
122 if (!ef) 134 if (!ef)
123 { 135 {
124 ERR("cannot open for reading: %s\n", file); 136 ERR("cannot open for reading: %s\n", file);
125 exit(-1); 137 exit(-1);
126 } 138 }
139
127 f = fopen(out, "wb"); 140 f = fopen(out, "wb");
128 if (!f) 141 if (!f)
129 { 142 {
130 ERR("cannot open %s\n", out); 143 ERR("cannot open %s\n", out);
131 exit(-1); 144 exit(-1);
132 } 145 }
146
133 if (!eet_data_dump_cipher(ef, key, crypto_key, do_eet_decode_dump, f)) 147 if (!eet_data_dump_cipher(ef, key, crypto_key, do_eet_decode_dump, f))
134 { 148 {
135 ERR("cannot write to %s\n", out); 149 ERR("cannot write to %s\n", out);
136 exit(-1); 150 exit(-1);
137 } 151 }
152
138 fclose(f); 153 fclose(f);
139 eet_close(ef); 154 eet_close(ef);
140} 155}
141 156
142static void 157static void
143do_eet_insert(const char *file, const char *key, const char *out, int compress, const char *crypto_key) 158do_eet_insert(const char *file,
159 const char *key,
160 const char *out,
161 int compress,
162 const char *crypto_key)
144{ 163{
145 Eet_File *ef; 164 Eet_File *ef;
146 void *data; 165 void *data;
@@ -149,32 +168,37 @@ do_eet_insert(const char *file, const char *key, const char *out, int compress,
149 168
150 ef = eet_open(file, EET_FILE_MODE_READ_WRITE); 169 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
151 if (!ef) 170 if (!ef)
152 ef = eet_open(file, EET_FILE_MODE_WRITE); 171 ef = eet_open(file, EET_FILE_MODE_WRITE);
172
153 if (!ef) 173 if (!ef)
154 { 174 {
155 ERR("cannot open for read+write: %s\n", file); 175 ERR("cannot open for read+write: %s\n", file);
156 exit(-1); 176 exit(-1);
157 } 177 }
178
158 f = fopen(out, "rb"); 179 f = fopen(out, "rb");
159 if (!f) 180 if (!f)
160 { 181 {
161 ERR("cannot open %s\n", out); 182 ERR("cannot open %s\n", out);
162 exit(-1); 183 exit(-1);
163 } 184 }
185
164 fseek(f, 0, SEEK_END); 186 fseek(f, 0, SEEK_END);
165 size = ftell(f); 187 size = ftell(f);
166 rewind(f); 188 rewind(f);
167 data = malloc(size); 189 data = malloc(size);
168 if (!data) 190 if (!data)
169 { 191 {
170 ERR("cannot allocate %i bytes\n", size); 192 ERR("cannot allocate %i bytes\n", size);
171 exit(-1); 193 exit(-1);
172 } 194 }
195
173 if (fread(data, size, 1, f) != 1) 196 if (fread(data, size, 1, f) != 1)
174 { 197 {
175 ERR("cannot read file %s\n", out); 198 ERR("cannot read file %s\n", out);
176 exit(-1); 199 exit(-1);
177 } 200 }
201
178 fclose(f); 202 fclose(f);
179 eet_write_cipher(ef, key, data, size, compress, crypto_key); 203 eet_write_cipher(ef, key, data, size, compress, crypto_key);
180 free(data); 204 free(data);
@@ -182,7 +206,11 @@ do_eet_insert(const char *file, const char *key, const char *out, int compress,
182} 206}
183 207
184static void 208static void
185do_eet_encode(const char *file, const char *key, const char *out, int compress, const char *crypto_key) 209do_eet_encode(const char *file,
210 const char *key,
211 const char *out,
212 int compress,
213 const char *crypto_key)
186{ 214{
187 Eet_File *ef; 215 Eet_File *ef;
188 char *text; 216 char *text;
@@ -192,38 +220,44 @@ do_eet_encode(const char *file, const char *key, const char *out, int compress,
192 220
193 ef = eet_open(file, EET_FILE_MODE_READ_WRITE); 221 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
194 if (!ef) 222 if (!ef)
195 ef = eet_open(file, EET_FILE_MODE_WRITE); 223 ef = eet_open(file, EET_FILE_MODE_WRITE);
224
196 if (!ef) 225 if (!ef)
197 { 226 {
198 ERR("cannot open for read+write: %s\n", file); 227 ERR("cannot open for read+write: %s\n", file);
199 exit(-1); 228 exit(-1);
200 } 229 }
230
201 f = fopen(out, "rb"); 231 f = fopen(out, "rb");
202 if (!f) 232 if (!f)
203 { 233 {
204 ERR("cannot open %s\n", out); 234 ERR("cannot open %s\n", out);
205 exit(-1); 235 exit(-1);
206 } 236 }
237
207 fseek(f, 0, SEEK_END); 238 fseek(f, 0, SEEK_END);
208 textlen = ftell(f); 239 textlen = ftell(f);
209 rewind(f); 240 rewind(f);
210 text = malloc(textlen); 241 text = malloc(textlen);
211 if (!text) 242 if (!text)
212 { 243 {
213 ERR("cannot allocate %i bytes\n", size); 244 ERR("cannot allocate %i bytes\n", size);
214 exit(-1); 245 exit(-1);
215 } 246 }
247
216 if (fread(text, textlen, 1, f) != 1) 248 if (fread(text, textlen, 1, f) != 1)
217 { 249 {
218 ERR("cannot read file %s\n", out); 250 ERR("cannot read file %s\n", out);
219 exit(-1); 251 exit(-1);
220 } 252 }
253
221 fclose(f); 254 fclose(f);
222 if (!eet_data_undump_cipher(ef, key, crypto_key, text, textlen, compress)) 255 if (!eet_data_undump_cipher(ef, key, crypto_key, text, textlen, compress))
223 { 256 {
224 ERR("cannot parse %s\n", out); 257 ERR("cannot parse %s\n", out);
225 exit(-1); 258 exit(-1);
226 } 259 }
260
227 free(text); 261 free(text);
228 eet_close(ef); 262 eet_close(ef);
229} 263}
@@ -236,9 +270,10 @@ do_eet_remove(const char *file, const char *key)
236 ef = eet_open(file, EET_FILE_MODE_READ_WRITE); 270 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
237 if (!ef) 271 if (!ef)
238 { 272 {
239 ERR("cannot open for read+write: %s\n", file); 273 ERR("cannot open for read+write: %s\n", file);
240 exit(-1); 274 exit(-1);
241 } 275 }
276
242 eet_delete(ef, key); 277 eet_delete(ef, key);
243 eet_close(ef); 278 eet_close(ef);
244} 279}
@@ -254,8 +289,8 @@ do_eet_check(const char *file)
254 ef = eet_open(file, EET_FILE_MODE_READ); 289 ef = eet_open(file, EET_FILE_MODE_READ);
255 if (!ef) 290 if (!ef)
256 { 291 {
257 ERR("checking signature of `%s` failed\n", file); 292 ERR("checking signature of `%s` failed\n", file);
258 exit(-1); 293 exit(-1);
259 } 294 }
260 295
261 der = eet_identity_x509(ef, &der_length); 296 der = eet_identity_x509(ef, &der_length);
@@ -278,15 +313,15 @@ do_eet_sign(const char *file, const char *private_key, const char *public_key)
278 ef = eet_open(file, EET_FILE_MODE_READ_WRITE); 313 ef = eet_open(file, EET_FILE_MODE_READ_WRITE);
279 if (!ef) 314 if (!ef)
280 { 315 {
281 ERR("cannot open for read+write: %s.\n", file); 316 ERR("cannot open for read+write: %s.\n", file);
282 exit(-1); 317 exit(-1);
283 } 318 }
284 319
285 key = eet_identity_open(public_key, private_key, NULL); 320 key = eet_identity_open(public_key, private_key, NULL);
286 if (!key) 321 if (!key)
287 { 322 {
288 ERR("cannot open key '%s:%s'.\n", public_key, private_key); 323 ERR("cannot open key '%s:%s'.\n", public_key, private_key);
289 exit(-1); 324 exit(-1);
290 } 325 }
291 326
292 fprintf(stdout, "Using the following key to sign `%s`.\n", file); 327 fprintf(stdout, "Using the following key to sign `%s`.\n", file);
@@ -301,83 +336,75 @@ int
301main(int argc, char **argv) 336main(int argc, char **argv)
302{ 337{
303 if (!eet_init()) 338 if (!eet_init())
304 return -1; 339 return -1;
305 340
306 _eet_main_log_dom = eina_log_domain_register("Eet_Main",EINA_COLOR_CYAN); 341 _eet_main_log_dom = eina_log_domain_register("Eet_Main",EINA_COLOR_CYAN);
307 if(_eet_main_log_dom < -1) 342 if(_eet_main_log_dom < -1)
308 { 343 {
309 EINA_LOG_ERR("Impossible to create a log domain for eet_main.\n"); 344 EINA_LOG_ERR("Impossible to create a log domain for eet_main.\n");
310 eet_shutdown(); 345 eet_shutdown();
311 return(-1); 346 return(-1);
312 } 347 }
348
313 if (argc < 2) 349 if (argc < 2)
314 { 350 {
315 help: 351help:
316 printf("Usage:\n" 352 printf(
317 " eet -l FILE.EET list all keys in FILE.EET\n" 353 "Usage:\n"
318 " eet -x FILE.EET KEY OUT-FILE [CRYPTO_KEY] extract data stored in KEY in FILE.EET and write to OUT-FILE\n" 354 " eet -l FILE.EET list all keys in FILE.EET\n"
319 " eet -d FILE.EET KEY OUT-FILE [CRYPTO_KEY] extract and decode data stored in KEY in FILE.EET and write to OUT-FILE\n" 355 " eet -x FILE.EET KEY OUT-FILE [CRYPTO_KEY] extract data stored in KEY in FILE.EET and write to OUT-FILE\n"
320 " eet -i FILE.EET KEY IN-FILE COMPRESS [CRYPTO_KEY] insert data to KEY in FILE.EET from IN-FILE and if COMPRESS is 1, compress it\n" 356 " eet -d FILE.EET KEY OUT-FILE [CRYPTO_KEY] extract and decode data stored in KEY in FILE.EET and write to OUT-FILE\n"
321 " eet -e FILE.EET KEY IN-FILE COMPRESS [CRYPTO_KEY] insert and encode to KEY in FILE.EET from IN-FILE and if COMPRESS is 1, compress it\n" 357 " eet -i FILE.EET KEY IN-FILE COMPRESS [CRYPTO_KEY] insert data to KEY in FILE.EET from IN-FILE and if COMPRESS is 1, compress it\n"
322 " eet -r FILE.EET KEY remove KEY in FILE.EET\n" 358 " eet -e FILE.EET KEY IN-FILE COMPRESS [CRYPTO_KEY] insert and encode to KEY in FILE.EET from IN-FILE and if COMPRESS is 1, compress it\n"
323 " eet -c FILE.EET report and check the signature information of an eet file\n" 359 " eet -r FILE.EET KEY remove KEY in FILE.EET\n"
324 " eet -s FILE.EET PRIVATE_KEY PUBLIC_KEY sign FILE.EET with PRIVATE_KEY and attach PUBLIC_KEY as it's certificate\n" 360 " eet -c FILE.EET report and check the signature information of an eet file\n"
325 ); 361 " eet -s FILE.EET PRIVATE_KEY PUBLIC_KEY sign FILE.EET with PRIVATE_KEY and attach PUBLIC_KEY as it's certificate\n"
326 eet_shutdown(); 362 );
327 return -1; 363 eet_shutdown();
364 return -1;
328 } 365 }
366
329 if ((!strncmp(argv[1], "-h", 2))) 367 if ((!strncmp(argv[1], "-h", 2)))
330 { 368 goto help;
331 goto help;
332 }
333 else if ((!strcmp(argv[1], "-l")) && (argc > 2)) 369 else if ((!strcmp(argv[1], "-l")) && (argc > 2))
334 { 370 do_eet_list(argv[2]);
335 do_eet_list(argv[2]);
336 }
337 else if ((!strcmp(argv[1], "-x")) && (argc > 4)) 371 else if ((!strcmp(argv[1], "-x")) && (argc > 4))
338 { 372 {
339 if (argc > 5) 373 if (argc > 5)
340 do_eet_extract(argv[2], argv[3], argv[4], argv[5]); 374 do_eet_extract(argv[2], argv[3], argv[4], argv[5]);
341 else 375 else
342 do_eet_extract(argv[2], argv[3], argv[4], NULL); 376 do_eet_extract(argv[2], argv[3], argv[4], NULL);
343 } 377 }
344 else if ((!strcmp(argv[1], "-d")) && (argc > 4)) 378 else if ((!strcmp(argv[1], "-d")) && (argc > 4))
345 { 379 {
346 if (argc > 5) 380 if (argc > 5)
347 do_eet_decode(argv[2], argv[3], argv[4], argv[5]); 381 do_eet_decode(argv[2], argv[3], argv[4], argv[5]);
348 else 382 else
349 do_eet_decode(argv[2], argv[3], argv[4], NULL); 383 do_eet_decode(argv[2], argv[3], argv[4], NULL);
350 } 384 }
351 else if ((!strcmp(argv[1], "-i")) && (argc > 5)) 385 else if ((!strcmp(argv[1], "-i")) && (argc > 5))
352 { 386 {
353 if (argc > 6) 387 if (argc > 6)
354 do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]); 388 do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]);
355 else 389 else
356 do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), NULL); 390 do_eet_insert(argv[2], argv[3], argv[4], atoi(argv[5]), NULL);
357 } 391 }
358 else if ((!strcmp(argv[1], "-e")) && (argc > 5)) 392 else if ((!strcmp(argv[1], "-e")) && (argc > 5))
359 { 393 {
360 if (argc > 6) 394 if (argc > 6)
361 do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]); 395 do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), argv[6]);
362 else 396 else
363 do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), NULL); 397 do_eet_encode(argv[2], argv[3], argv[4], atoi(argv[5]), NULL);
364 } 398 }
365 else if ((!strcmp(argv[1], "-r")) && (argc > 3)) 399 else if ((!strcmp(argv[1], "-r")) && (argc > 3))
366 { 400 do_eet_remove(argv[2], argv[3]);
367 do_eet_remove(argv[2], argv[3]);
368 }
369 else if ((!strcmp(argv[1], "-c")) && (argc > 2)) 401 else if ((!strcmp(argv[1], "-c")) && (argc > 2))
370 { 402 do_eet_check(argv[2]);
371 do_eet_check(argv[2]);
372 }
373 else if ((!strcmp(argv[1], "-s")) && (argc > 4)) 403 else if ((!strcmp(argv[1], "-s")) && (argc > 4))
374 { 404 do_eet_sign(argv[2], argv[3], argv[4]);
375 do_eet_sign(argv[2], argv[3], argv[4]);
376 }
377 else 405 else
378 { 406 goto help;
379 goto help; 407
380 }
381 eina_log_domain_unregister(_eet_main_log_dom); 408 eina_log_domain_unregister(_eet_main_log_dom);
382 eet_shutdown(); 409 eet_shutdown();
383 return 0; 410 return 0;