From 66396ea32dc947a828db60a5decbe43b5f75d4d8 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:01 +0200 Subject: [PATCH] * examples/rsa-sign.c: No need to include config.h. Use werror instead of fprintf. * examples/rsa-verify.c: Likewise. Rev: src/nettle/examples/rsa-sign.c:1.3 Rev: src/nettle/examples/rsa-verify.c:1.2 --- examples/rsa-sign.c | 25 +++++-------------------- examples/rsa-verify.c | 29 +++++++---------------------- 2 files changed, 12 insertions(+), 42 deletions(-) diff --git a/examples/rsa-sign.c b/examples/rsa-sign.c index 2645af44..a96d3b1e 100644 --- a/examples/rsa-sign.c +++ b/examples/rsa-sign.c @@ -22,26 +22,12 @@ * MA 02111-1307, USA. */ -#if HAVE_CONFIG_H -# include "config.h" -#endif /* HAVE_CONFIG_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 */ - #include <errno.h> #include <stdlib.h> #include <stdio.h> #include <string.h> +/* string.h must be included before gmp.h */ #include "rsa.h" #include "io.h" @@ -54,7 +40,7 @@ main(int argc, char **argv) if (argc != 2) { - fprintf(stderr, "Usage: rsa-sign PRIVATE-KEY < file\n"); + werror("Usage: rsa-sign PRIVATE-KEY < file\n"); return EXIT_FAILURE; } @@ -62,14 +48,14 @@ main(int argc, char **argv) if (!read_rsa_key(argv[1], NULL, &key)) { - fprintf(stderr, "Invalid key\n"); + werror("Invalid key\n"); return EXIT_FAILURE; } sha1_init(&hash); if (!hash_file(&nettle_sha1, &hash, stdin)) { - fprintf(stderr, "Failed reading stdin: %s\n", + werror("Failed reading stdin: %s\n", strerror(errno)); return 0; } @@ -79,7 +65,7 @@ main(int argc, char **argv) if (!mpz_out_str(stdout, 16, s)) { - fprintf(stderr, "Failed writing signature: %s\n", + werror("Failed writing signature: %s\n", strerror(errno)); return 0; } @@ -91,4 +77,3 @@ main(int argc, char **argv) return EXIT_SUCCESS; } -#endif /* WITH_PUBLIC_KEY */ diff --git a/examples/rsa-verify.c b/examples/rsa-verify.c index 77e25694..5dcd90b2 100644 --- a/examples/rsa-verify.c +++ b/examples/rsa-verify.c @@ -22,29 +22,15 @@ * MA 02111-1307, USA. */ -#if HAVE_CONFIG_H -# include "config.h" -#endif /* HAVE_CONFIG_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 */ +#include "rsa.h" +#include "io.h" #include <errno.h> #include <stdlib.h> #include <stdio.h> #include <string.h> -#include "rsa.h" -#include "io.h" - static int read_signature(const char *name, mpz_t s) { @@ -71,7 +57,7 @@ main(int argc, char **argv) if (argc != 3) { - fprintf(stderr, "Usage: rsa-sign PUBLIC-KEY SIGNATURE-FILE < file\n"); + werror("Usage: rsa-sign PUBLIC-KEY SIGNATURE-FILE < file\n"); return EXIT_FAILURE; } @@ -79,7 +65,7 @@ main(int argc, char **argv) if (!read_rsa_key(argv[1], &key, NULL)) { - fprintf(stderr, "Invalid key\n"); + werror("Invalid key\n"); return EXIT_FAILURE; } @@ -87,7 +73,7 @@ main(int argc, char **argv) if (!read_signature(argv[2], s)) { - fprintf(stderr, "Failed to read signature file `%s'\n", + werror("Failed to read signature file `%s'\n", argv[2]); return EXIT_FAILURE; } @@ -95,14 +81,14 @@ main(int argc, char **argv) sha1_init(&hash); if (!hash_file(&nettle_sha1, &hash, stdin)) { - fprintf(stderr, "Failed reading stdin: %s\n", + werror("Failed reading stdin: %s\n", strerror(errno)); return 0; } if (!rsa_sha1_verify(&key, &hash, s)) { - fprintf(stderr, "Invalid signature!\n"); + werror("Invalid signature!\n"); return EXIT_FAILURE; } @@ -111,4 +97,3 @@ main(int argc, char **argv) return EXIT_SUCCESS; } -#endif /* WITH_PUBLIC_KEY */ -- GitLab