From 64078b7bbb9fe3b810c486e6e2c93ee28f1682aa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Niels=20M=C3=B6ller?= <nisse@lysator.liu.se>
Date: Tue, 1 Oct 2002 16:04:51 +0200
Subject: [PATCH] * examples/rsa-sign.c: No need to include config.h. Use
 werror instead of fprintf. * examples/rsa-verify.c: Likewise. *
 examples/rsa-keygen.c: Likewise.

Rev: src/nettle/examples/rsa-keygen.c:1.4
---
 examples/rsa-keygen.c | 52 ++++++++++++++-----------------------------
 1 file changed, 17 insertions(+), 35 deletions(-)

diff --git a/examples/rsa-keygen.c b/examples/rsa-keygen.c
index 39b0f421..a38889a9 100644
--- a/examples/rsa-keygen.c
+++ b/examples/rsa-keygen.c
@@ -22,41 +22,24 @@
  * MA 02111-1307, USA.
  */
 
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif /* HAVE_CONFIG_H */
-
 /* For asprintf */
 #define _GNU_SOURCE
 
+#include "buffer.h"
+#include "rsa.h"
+#include "sexp.h"
+#include "yarrow.h"
+
+#include "io.h"
+
 #include <ctype.h>
 #include <errno.h>
 #include <stdlib.h>
 #include <stdio.h>
 #include <string.h>
 
-#if !WITH_PUBLIC_KEY
-int
-main(int argc, char **argv)
-{
-  fprintf(stderr,
-	  "You need to install GMP somewhere where Nettle can find it,\n"
-	  "and recompile Nettle\n");
-  return EXIT_FAILURE;
-}
-#else /* WITH_PUBLIC_KEY */
-
+/* For getopt */
 #include <unistd.h>
-#include <fcntl.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-
-#include "buffer.h"
-#include "rsa.h"
-#include "sexp.h"
-#include "yarrow.h"
-
-#include "io.h"
 
 #define KEYSIZE 500
 #define ESIZE 30
@@ -97,9 +80,9 @@ main(int argc, char **argv)
 	
       case '?':
 	if (isprint (optopt))
-	  fprintf(stderr, "Unknown option `-%c'.\n", optopt);
+	  werror("Unknown option `-%c'.\n", optopt);
 	else
-	  fprintf(stderr, "Unknown option character `\\x%x'.\n",
+	  werror("Unknown option character `\\x%x'.\n",
 		  optopt);
 	return EXIT_FAILURE;
       default:
@@ -108,14 +91,14 @@ main(int argc, char **argv)
 
   if (!priv_name)
     {
-      fprintf(stderr, "No filename provided.\n");
+      werror("No filename provided.\n");
       return EXIT_FAILURE;
     }
 
   asprintf(&pub_name, "%s.pub", priv_name);
   if (!pub_name)
     {
-      fprintf(stderr, "Memory exhausted.\n");
+      werror("Memory exhausted.\n");
       return EXIT_FAILURE;
     }
   
@@ -134,7 +117,7 @@ main(int argc, char **argv)
        NULL, progress,
        KEYSIZE, ESIZE))
     {
-      fprintf(stderr, "Key generation failed.\n");
+      werror("Key generation failed.\n");
       return EXIT_FAILURE;
     }
 
@@ -143,30 +126,29 @@ main(int argc, char **argv)
   
   if (!rsa_keypair_to_sexp(&pub_buffer, &pub, NULL))
     {
-      fprintf(stderr, "Formatting public key failed.\n");
+      werror("Formatting public key failed.\n");
       return EXIT_FAILURE;
     }
 
   if (!rsa_keypair_to_sexp(&pub_buffer, &pub, &priv))
     {
-      fprintf(stderr, "Formatting private key failed.\n");
+      werror("Formatting private key failed.\n");
       return EXIT_FAILURE;
     }
   
   if (!write_file(pub_name, pub_buffer.size, pub_buffer.contents))
     {
-      fprintf(stderr, "Failed to write public key: %s\n",
+      werror("Failed to write public key: %s\n",
 	      strerror(errno));
       return EXIT_FAILURE;
     }
 
   if (!write_file(priv_name, priv_buffer.size, priv_buffer.contents))
     {
-      fprintf(stderr, "Failed to write private key: %s\n",
+      werror("Failed to write private key: %s\n",
 	      strerror(errno));
       return EXIT_FAILURE;
     }
 
   return EXIT_SUCCESS;
 }
-#endif /* WITH_PUBLIC_KEY */
-- 
GitLab