]>
git.saurik.com Git - apple/security.git/blob - SecurityTests/clxutils/pemtool/pemtool.c
2 * pemtool - convert between DER and PEM format
7 #include <security_cdsa_utils/cuFileIo.h>
8 #include <security_cdsa_utils/cuPem.h> /* private from CdsaUtils */
9 #include <security_cdsa_utils/cuEnc64.h> /* private from CdsaUtils */
11 static void usage (char **argv
)
14 printf(" %s e infile outfile header_string [q(uiet)] -- to PEM encode\n",
16 printf(" %s d infile outfile [q(uiet)] -- to PEM decode\n",
21 int main(int argc
, char **argv
)
24 unsigned char *inFile
= NULL
;
26 unsigned char *outFile
= NULL
;
55 for(arg
=optarg
; arg
<argc
; arg
++) {
56 switch(argv
[arg
][0]) {
64 if(readFile(argv
[2], &inFile
, &inFileLen
)) {
65 printf("***Error reading %s; aborting.\n", argv
[2]);
68 outFileName
= argv
[3];
70 rtn
= pemEncode(inFile
, inFileLen
, &outFile
, &outFileLen
,
74 if(isPem(inFile
, inFileLen
)) {
75 rtn
= pemDecode(inFile
, inFileLen
, &outFile
, &outFileLen
);
78 /* Maybe it's just base64, i.e., PEM without the header */
79 outFile
= cuDec64(inFile
, inFileLen
, &outFileLen
);
82 printf("***Error on base64 decode\n");
90 rtn
= writeFile(outFileName
, outFile
, outFileLen
);
92 printf("***Error writing to %s\n", outFileName
);
95 printf("...wrote %u bytes to %s.\n", outFileLen
, outFileName
);
99 printf("***Error processing %s.\n", argv
[2]);