]> git.saurik.com Git - apple/security.git/blob - SecurityTests/clxutils/parseCert/parseCert.cpp
Security-57031.1.35.tar.gz
[apple/security.git] / SecurityTests / clxutils / parseCert / parseCert.cpp
1 /*
2 * parseCert.cpp - CL-based cert parser.
3 *
4 * See oidParser.h for info on config file.
5 */
6 #include <security_cdsa_utils/cuPrintCert.h>
7 #include <security_cdsa_utils/cuFileIo.h>
8 #include <stdlib.h>
9 #include <stdio.h>
10 #include <string.h>
11
12 static void usage(char **argv)
13 {
14 printf("Usage: %s certFile [v(erbose) [l(oop)]\n", argv[0]);
15 exit(1);
16 }
17
18 int main(int argc, char **argv)
19 {
20 unsigned char *rawCert = NULL;
21 unsigned rawCertSize;
22 int rtn;
23 CSSM_BOOL verbose = CSSM_FALSE;
24 int arg;
25 int loop = 0;
26
27 if(argc < 2) {
28 usage(argv);
29 }
30 for(arg=2; arg<argc; arg++) {
31 switch(argv[arg][0]) {
32 case 'v':
33 verbose = CSSM_TRUE;
34 break;
35 case 'l':
36 loop = 1;
37 break;
38 default:
39 usage(argv);
40 }
41 }
42 rtn = readFile(argv[1], &rawCert, &rawCertSize);
43 if(rtn) {
44 printf("Error reading %s; %s\n", argv[1], strerror(rtn));
45 exit(1);
46 }
47 do {
48 printCert(rawCert, rawCertSize, verbose);
49 if(loop) {
50 printf("Enter q to quit, anything else to continue: ");
51 fflush(stdout);
52 char c = getchar();
53 if(c == 'q') {
54 break;
55 }
56 }
57 } while(loop);
58 return 0;
59 }
60