Start to reduce some of the header bloat.
[openssl.git] / apps / rsautl.c
index bcb94c3d81040c772aeb62bec3efe2701d3b5745..56025c5f0cc1719bcca6f5a36543139c85d31e42 100644 (file)
  * Hudson (tjh@cryptsoft.com).
  *
  */
+
+#ifndef OPENSSL_NO_RSA
+
 #include "apps.h"
 #include <string.h>
 #include <openssl/err.h>
 #include <openssl/pem.h>
+#include <openssl/engine.h>
 
 #define RSA_SIGN       1
 #define RSA_VERIFY     2
@@ -79,8 +83,10 @@ int MAIN(int argc, char **);
 
 int MAIN(int argc, char **argv)
 {
+       ENGINE *e = NULL;
        BIO *in = NULL, *out = NULL;
        char *infile = NULL, *outfile = NULL;
+       char *engine = NULL;
        char *keyfile = NULL;
        char rsa_mode = RSA_VERIFY, key_type = KEY_PRIVKEY;
        int keyform = FORMAT_PEM;
@@ -114,6 +120,9 @@ int MAIN(int argc, char **argv)
                } else if(!strcmp(*argv, "-inkey")) {
                        if (--argc < 1) badarg = 1;
                        keyfile = *(++argv);
+               } else if(!strcmp(*argv, "-engine")) {
+                       if (--argc < 1) badarg = 1;
+                       engine = *(++argv);
                } else if(!strcmp(*argv, "-pubin")) {
                        key_type = KEY_PUBKEY;
                } else if(!strcmp(*argv, "-certin")) {
@@ -148,20 +157,25 @@ int MAIN(int argc, char **argv)
                goto end;
        }
 
+        e = setup_engine(bio_err, engine, 0);
+
 /* FIXME: seed PRNG only if needed */
        app_RAND_load_file(NULL, bio_err, 0);
        
        switch(key_type) {
                case KEY_PRIVKEY:
-               pkey = load_key(bio_err, keyfile, keyform, NULL);
+               pkey = load_key(bio_err, keyfile, keyform,
+                       NULL, e, "Private Key");
                break;
 
                case KEY_PUBKEY:
-               pkey = load_pubkey(bio_err, keyfile, keyform);
+               pkey = load_pubkey(bio_err, keyfile, keyform,
+                       NULL, e, "Public Key");
                break;
 
                case KEY_CERT:
-               x = load_cert(bio_err, keyfile, keyform);
+               x = load_cert(bio_err, keyfile, keyform,
+                       NULL, e, "Certificate");
                if(x) {
                        pkey = X509_get_pubkey(x);
                        X509_free(x);
@@ -170,7 +184,6 @@ int MAIN(int argc, char **argv)
        }
 
        if(!pkey) {
-               BIO_printf(bio_err, "Error loading key\n");
                return 1;
        }
 
@@ -200,7 +213,7 @@ int MAIN(int argc, char **argv)
                }
        } else {
                out = BIO_new_fp(stdout, BIO_NOCLOSE);
-#ifdef VMS
+#ifdef OPENSSL_SYS_VMS
                {
                    BIO *tmpbio = BIO_new(BIO_f_linebuffer());
                    out = BIO_push(tmpbio, out);
@@ -288,3 +301,4 @@ static void usage()
        BIO_printf(bio_err, "-hexdump        hex dump output\n");
 }
 
+#endif