diff options
author | Peter Palfrader <peter@palfrader.org> | 2006-10-19 12:52:53 +0000 |
---|---|---|
committer | Peter Palfrader <peter@palfrader.org> | 2006-10-19 12:52:53 +0000 |
commit | e8dae74ccb9d32959f2d10ddaed97f0216842882 (patch) | |
tree | af2849c491bf14710a72e1d27a19a831258edf38 /contrib | |
parent | 3c459a7397eff03f0f7f05f1089ad88af829de79 (diff) | |
download | tor-e8dae74ccb9d32959f2d10ddaed97f0216842882.tar tor-e8dae74ccb9d32959f2d10ddaed97f0216842882.tar.gz |
id_to_fp: Support reading from stdin
svn:r8751
Diffstat (limited to 'contrib')
-rw-r--r-- | contrib/id_to_fp.c | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/contrib/id_to_fp.c b/contrib/id_to_fp.c index e6f9f4627..73395e16c 100644 --- a/contrib/id_to_fp.c +++ b/contrib/id_to_fp.c @@ -13,6 +13,7 @@ #include <stdio.h> #include <stdlib.h> +#include <string.h> #define die(s) do { fprintf(stderr, "%s\n", s); goto err; } while (0) @@ -26,11 +27,24 @@ main(int argc, char **argv) unsigned char digest[20]; int status = 1; - if (argc != 2) - die("I want a filename"); - if (!(b = BIO_new_file(argv[1], "r"))) - die("couldn't open file"); - + if (argc < 2) { + fprintf(stderr, "Reading key from stdin...\n"); + if (!(b = BIO_new_fp(stdin, BIO_NOCLOSE))) + die("couldn't read from stdin"); + } else if (argc == 2) { + if (strcmp(argv[1], "-h") == 0 || + strcmp(argv[1], "--help") == 0) { + fprintf(stdout, "Usage: %s [keyfile]\n", argv[0]); + status = 0; + goto err; + } else { + if (!(b = BIO_new_file(argv[1], "r"))) + die("couldn't open file"); + } + } else { + fprintf(stderr, "Usage: %s [keyfile]\n", argv[0]); + goto err; + } if (!(key = PEM_read_bio_RSAPrivateKey(b, NULL, NULL, NULL))) die("couldn't parse key"); |