[or-cvs] r8751: id_to_fp: Support reading from stdin (tor/trunk/contrib)

weasel at seul.org weasel at seul.org
Thu Oct 19 12:52:54 UTC 2006


Author: weasel
Date: 2006-10-19 08:52:53 -0400 (Thu, 19 Oct 2006)
New Revision: 8751

Modified:
   tor/trunk/contrib/id_to_fp.c
Log:
id_to_fp: Support reading from stdin

Modified: tor/trunk/contrib/id_to_fp.c
===================================================================
--- tor/trunk/contrib/id_to_fp.c	2006-10-19 11:40:15 UTC (rev 8750)
+++ tor/trunk/contrib/id_to_fp.c	2006-10-19 12:52:53 UTC (rev 8751)
@@ -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 @@
   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");
 



More information about the tor-commits mailing list