On Fri, Jan 03, 2014 at 16:55, Marc Espie wrote:

> @@ -377,30 +377,37 @@ main(int argc, char **argv)
> }
> }
> argc -= optind;
> -     if (argc != 0)
> -             usage();
> -
> -     if (inputfile && !sigfile) {
> -             if (snprintf(sigfilebuf, sizeof(sigfilebuf), "%s.sig",
> -                 inputfile) >= sizeof(sigfilebuf))
> -                     errx(1, "path too long");
> -             sigfile = sigfilebuf;
> -     }
> +     argv += optind;

You can haul the none check up to here now. (which is where it was
long ago, when verb was in argv). The check at the end used to be for
an unrecognized verb, but that can't happen now.

> 
> if (verb == GENERATE) {
> -             if (!pubkeyfile || !seckeyfile)
> +             if (!pubkeyfile || !seckeyfile || argc != 0)
> usage();
> generate(pubkeyfile, seckeyfile, rounds);
> -     } else if (verb == SIGN) {
> -             if (!seckeyfile || !inputfile)
> +     } else if (verb == SIGN || verb == VERIFY) {
> +             if (argc != 1)
> usage();
> -             sign(seckeyfile, inputfile, sigfile);
> -     } else if (verb == VERIFY) {
> -             if (!pubkeyfile || !inputfile)
> -                     usage();
> -             verify(pubkeyfile, inputfile, sigfile);
> +
> +             inputfile = argv[0];
> +
> +             if (!sigfile) {
> +                     if (snprintf(sigfilebuf, sizeof(sigfilebuf), "%s.sig",
> +                         inputfile) >= sizeof(sigfilebuf))
> +                             errx(1, "path too long");
> +                     sigfile = sigfilebuf;
> +             }
> +
> +             if (verb == SIGN) {
> +                     if (!seckeyfile)
> +                             usage();
> +                     sign(seckeyfile, inputfile, sigfile);
> +             } else if (verb == VERIFY) {
> +                     if (!pubkeyfile)
> +                             usage();
> +                     verify(pubkeyfile, inputfile, sigfile);
> +             }
> } else {
> usage();
> }
> +
> return 0;
> }

Reply via email to