diff --git a/lib/asn1/asn1_print.1 b/lib/asn1/asn1_print.1 index 2d167f063..8066b0b5b 100644 --- a/lib/asn1/asn1_print.1 +++ b/lib/asn1/asn1_print.1 @@ -40,27 +40,13 @@ .Sh SYNOPSIS .Nm .Bk -words -.Oo Fl i \*(Ba Xo -.Fl Fl no-indent -.Xc -.Oc -.Oo Fl I \*(Ba Xo -.Fl Fl inner -.Xc -.Oc -.Oo Fl l \*(Ba Xo -.Fl Fl list-types -.Xc -.Oc -.Oo Fl A \*(Ba Xo -.Fl Fl try-all-types -.Xc -.Oc -.Oo Fl S \*(Ba Xo -.Fl Fl raw-sequence -.Xc -.Oc +.Oo Fl i \*(Ba Xo Fl Fl no-indent Xc Oc +.Oo Fl I \*(Ba Xo Fl Fl inner Xc Oc +.Oo Fl l \*(Ba Xo Fl Fl list-types Xc Oc +.Oo Fl A \*(Ba Xo Fl Fl try-all-types Xc Oc +.Oo Fl S \*(Ba Xo Fl Fl raw-sequence Xc Oc .Oo Fl n \*(Ba Xo Fl Fl no-print Xc Oc +.Oo Fl q \*(Ba Xo Fl Fl quiet Xc Oc .Oo Xo Fl Fl test-encode Xc Oc .Oo Xo Fl Fl test-copy Xc Oc .Oo Fl l v \*(Ba Xo @@ -126,6 +112,18 @@ or where a is given, do not output a JSON representation of the value, just attempt to decode it. This is useful for fuzzing. +.It Fl q, Fl Fl quiet +Similar to +.Fl n, Fl Fl no-print +but JSON output will be formatted, just not output. +As with +.Fl n, Fl Fl no-print, +this option requires +.Fl A / Fl Fl try-all-types +or that a +.Ar TypeName +be given. +This is useful for fuzzing. .It Fl Fl test-encode Check that encoding produces the same value as decoding. Useful for fuzzing. diff --git a/lib/asn1/asn1_print.c b/lib/asn1/asn1_print.c index 20558e93d..5bb1003af 100644 --- a/lib/asn1/asn1_print.c +++ b/lib/asn1/asn1_print.c @@ -55,6 +55,7 @@ #include "rfc4108_asn1.h" #include "x690sample_asn1.h" +static int quiet_flag = 0; static int print_flag = 1; static int test_copy_flag; static int test_encode_flag; @@ -410,11 +411,11 @@ dotype(unsigned char *buf, size_t len, char **argv, size_t *size) ret = sorted_types[i].decode(buf, len, v, &sz); if (ret == 0) { matches++; - if (sz == len) { + if (!quiet_flag && sz == len) { fprintf(stderr, "Match: %s\n", typename); } else if (sequence_flag) { *size = sz; - } else { + } else if (!quiet_flag) { fprintf(stderr, "Prefix match: %s\n", typename); } if (print_flag) { @@ -425,7 +426,8 @@ dotype(unsigned char *buf, size_t len, char **argv, size_t *size) ret = errno; err(1, "Could not print %s\n", typename); } - fprintf(stdout, "%s\n", s); + if (!quiet_flag) + printf("%s\n", s); free(s); } if (test_encode_flag) { @@ -604,6 +606,8 @@ struct getargs args[] = { "\ttest copy operation (for memory debugging and fuzzing)", NULL }, { "print", 'n', arg_negative_flag, &print_flag, "\ttest copy operation (for memory debugging and fuzzing)", NULL }, + { "quiet", 'q', arg_flag, &quiet_flag, + "\tOutput nothing (exit status 0 means type matched)", NULL }, { "version", 'v', arg_flag, &version_flag, NULL, NULL }, { "help", 'h', arg_flag, &help_flag, NULL, NULL } }; @@ -636,17 +640,22 @@ main(int argc, char **argv) if (sequence_flag && try_all_flag) errx(1, "--raw-sequence and --try-all-types are mutually exclusive"); + if (quiet_flag && !try_all_flag && argc < 2) + errx(1, "--quiet requires --try-all-types or that a TypeName be given"); + if (!print_flag && !try_all_flag && argc < 2) + errx(1, "--no-print requires --try-all-types or that a TypeName be given"); if (list_types_flag) { size_t i; if (argc) - usage(1); + errx(1, "--list-types is exclusive of other options or arguments"); for (i = 0; i < sizeof(types)/sizeof(types[0]); i++) printf("%s\n", types[i].name); exit(0); } + if (argc < 1) usage(1); return doit(argv);