Commit 64078b7b authored by Niels Möller's avatar Niels Möller
Browse files

* 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
parent 66396ea3
...@@ -22,41 +22,24 @@ ...@@ -22,41 +22,24 @@
* MA 02111-1307, USA. * MA 02111-1307, USA.
*/ */
#if HAVE_CONFIG_H
# include "config.h"
#endif /* HAVE_CONFIG_H */
/* For asprintf */ /* For asprintf */
#define _GNU_SOURCE #define _GNU_SOURCE
#include "buffer.h"
#include "rsa.h"
#include "sexp.h"
#include "yarrow.h"
#include "io.h"
#include <ctype.h> #include <ctype.h>
#include <errno.h> #include <errno.h>
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#if !WITH_PUBLIC_KEY /* For getopt */
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 <unistd.h> #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 KEYSIZE 500
#define ESIZE 30 #define ESIZE 30
...@@ -97,9 +80,9 @@ main(int argc, char **argv) ...@@ -97,9 +80,9 @@ main(int argc, char **argv)
case '?': case '?':
if (isprint (optopt)) if (isprint (optopt))
fprintf(stderr, "Unknown option `-%c'.\n", optopt); werror("Unknown option `-%c'.\n", optopt);
else else
fprintf(stderr, "Unknown option character `\\x%x'.\n", werror("Unknown option character `\\x%x'.\n",
optopt); optopt);
return EXIT_FAILURE; return EXIT_FAILURE;
default: default:
...@@ -108,14 +91,14 @@ main(int argc, char **argv) ...@@ -108,14 +91,14 @@ main(int argc, char **argv)
if (!priv_name) if (!priv_name)
{ {
fprintf(stderr, "No filename provided.\n"); werror("No filename provided.\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
asprintf(&pub_name, "%s.pub", priv_name); asprintf(&pub_name, "%s.pub", priv_name);
if (!pub_name) if (!pub_name)
{ {
fprintf(stderr, "Memory exhausted.\n"); werror("Memory exhausted.\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -134,7 +117,7 @@ main(int argc, char **argv) ...@@ -134,7 +117,7 @@ main(int argc, char **argv)
NULL, progress, NULL, progress,
KEYSIZE, ESIZE)) KEYSIZE, ESIZE))
{ {
fprintf(stderr, "Key generation failed.\n"); werror("Key generation failed.\n");
return EXIT_FAILURE; return EXIT_FAILURE;
} }
...@@ -143,30 +126,29 @@ main(int argc, char **argv) ...@@ -143,30 +126,29 @@ main(int argc, char **argv)
if (!rsa_keypair_to_sexp(&pub_buffer, &pub, NULL)) 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; return EXIT_FAILURE;
} }
if (!rsa_keypair_to_sexp(&pub_buffer, &pub, &priv)) 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; return EXIT_FAILURE;
} }
if (!write_file(pub_name, pub_buffer.size, pub_buffer.contents)) 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)); strerror(errno));
return EXIT_FAILURE; return EXIT_FAILURE;
} }
if (!write_file(priv_name, priv_buffer.size, priv_buffer.contents)) 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)); strerror(errno));
return EXIT_FAILURE; return EXIT_FAILURE;
} }
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
#endif /* WITH_PUBLIC_KEY */
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment