mirror of
https://github.com/guanzhi/GmSSL.git
synced 2026-05-13 11:56:28 +08:00
Update Tools
This commit is contained in:
@@ -47,22 +47,24 @@
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <gmssl/pem.h>
|
||||
#include <gmssl/x509.h>
|
||||
#include <gmssl/x509_crl.h>
|
||||
#include <gmssl/error.h>
|
||||
|
||||
static const char *options = "[-in file]";
|
||||
|
||||
static const char *options = "[-in file] [-out file]";
|
||||
|
||||
int crlparse_main(int argc, char **argv)
|
||||
{
|
||||
int ret = 1;
|
||||
char *prog = argv[0];
|
||||
char *infile = NULL;
|
||||
char *outfile = NULL;
|
||||
FILE *infp = stdin;
|
||||
|
||||
uint8_t crl[18192];
|
||||
FILE *outfp = stdout;
|
||||
uint8_t crl[64 * 1024];
|
||||
size_t crllen;
|
||||
|
||||
argc--;
|
||||
@@ -71,38 +73,50 @@ int crlparse_main(int argc, char **argv)
|
||||
while (argc > 0) {
|
||||
if (!strcmp(*argv, "-help")) {
|
||||
printf("usage: %s %s\n", prog, options);
|
||||
return 0;
|
||||
goto end;
|
||||
} else if (!strcmp(*argv, "-in")) {
|
||||
if (--argc < 1) goto bad;
|
||||
infile = *(++argv);
|
||||
if (!(infp = fopen(infile, "r"))) {
|
||||
fprintf(stderr, "%s: open '%s' failure : %s\n", prog, infile, strerror(errno));
|
||||
goto end;
|
||||
}
|
||||
} else if (!strcmp(*argv, "-out")) {
|
||||
if (--argc < 1) goto bad;
|
||||
outfile = *(++argv);
|
||||
if (!(outfp = fopen(outfile, "w"))) {
|
||||
fprintf(stderr, "%s: open '%s' failure : %s\n", prog, outfile, strerror(errno));
|
||||
goto end;
|
||||
}
|
||||
} else {
|
||||
fprintf(stderr, "%s: illegal option '%s'\n", prog, *argv);
|
||||
goto end;
|
||||
bad:
|
||||
fprintf(stderr, "%s: llegal option '%s'\n", prog, *argv);
|
||||
printf("usage: %s %s\n", prog, options);
|
||||
return 1;
|
||||
fprintf(stderr, "%s: '%s' option value missing\n", prog, *argv);
|
||||
goto end;
|
||||
}
|
||||
|
||||
argc--;
|
||||
argv++;
|
||||
}
|
||||
|
||||
if (infile) {
|
||||
if (!(infp = fopen(infile, "r"))) {
|
||||
error_print();
|
||||
return -1;
|
||||
for (;;) {
|
||||
int rv;
|
||||
|
||||
if ((rv = x509_crl_from_fp(crl, &crllen, sizeof(crl), infp)) != 1) {
|
||||
if (rv < 0) fprintf(stderr, "%s: read CRL failure\n", prog);
|
||||
else ret = 0;
|
||||
goto end;
|
||||
}
|
||||
x509_crl_print(outfp, 0, 0, "CRL", crl, crllen);
|
||||
if (x509_crl_to_pem(crl, crllen, outfp) != 1) {
|
||||
fprintf(stderr, "%s: output CRL failure\n", prog);
|
||||
goto end;
|
||||
}
|
||||
}
|
||||
|
||||
for (;;) {
|
||||
int ret;
|
||||
if ((ret = x509_crl_from_pem(crl, &crllen, sizeof(crl), infp)) < 0) {
|
||||
error_print();
|
||||
return -1;
|
||||
} else if (!ret) {
|
||||
break;
|
||||
}
|
||||
x509_crl_print(stdout, 0, 0, "CRL", crl, crllen);
|
||||
// x509_crl_to_pem(crl, crllen, stdout);
|
||||
}
|
||||
return 0;
|
||||
end:
|
||||
if (infile && infp) fclose(infp);
|
||||
if (outfile && outfp) fclose(outfp);
|
||||
return ret;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user