Simplify preprocessor statements.
[openssl.git] / apps / apps.c
index 03bd9e2d3fa2c77035f3e0d34eab3ceaedc0bb4c..ca3f557ca2efd3b877eb7f5a96383988034d9749 100644 (file)
@@ -178,6 +178,8 @@ int str2fmt(char *s)
                || (strcmp(s,"PKCS12") == 0) || (strcmp(s,"pkcs12") == 0)
                || (strcmp(s,"P12") == 0) || (strcmp(s,"p12") == 0))
                return(FORMAT_PKCS12);
+       else if ((*s == 'E') || (*s == 'e'))
+               return(FORMAT_ENGINE);
        else
                return(FORMAT_UNDEF);
        }
@@ -440,7 +442,11 @@ int add_oid_section(BIO *err, LHASH *conf)
        STACK_OF(CONF_VALUE) *sktmp;
        CONF_VALUE *cnf;
        int i;
-       if(!(p=CONF_get_string(conf,NULL,"oid_section"))) return 1;
+       if(!(p=CONF_get_string(conf,NULL,"oid_section")))
+               {
+               ERR_clear_error();
+               return 1;
+               }
        if(!(sktmp = CONF_get_section(conf, p))) {
                BIO_printf(err, "problem loading oid section %s\n", p);
                return 0;
@@ -551,7 +557,7 @@ end:
        return(x);
        }
 
-EVP_PKEY *load_key(BIO *err, char *file, int format, char *pass)
+EVP_PKEY *load_key(BIO *err, char *file, int format, char *pass, ENGINE *e)
        {
        BIO *key=NULL;
        EVP_PKEY *pkey=NULL;
@@ -561,6 +567,14 @@ EVP_PKEY *load_key(BIO *err, char *file, int format, char *pass)
                BIO_printf(err,"no keyfile specified\n");
                goto end;
                }
+       if (format == FORMAT_ENGINE)
+               {
+               if (!e)
+                       BIO_printf(bio_err,"no engine specified\n");
+               else
+                       pkey = ENGINE_load_private_key(e, file, pass);
+               goto end;
+               }
        key=BIO_new(BIO_s_file());
        if (key == NULL)
                {
@@ -600,7 +614,7 @@ EVP_PKEY *load_key(BIO *err, char *file, int format, char *pass)
        return(pkey);
        }
 
-EVP_PKEY *load_pubkey(BIO *err, char *file, int format)
+EVP_PKEY *load_pubkey(BIO *err, char *file, int format, ENGINE *e)
        {
        BIO *key=NULL;
        EVP_PKEY *pkey=NULL;
@@ -610,6 +624,14 @@ EVP_PKEY *load_pubkey(BIO *err, char *file, int format)
                BIO_printf(err,"no keyfile specified\n");
                goto end;
                }
+       if (format == FORMAT_ENGINE)
+               {
+               if (!e)
+                       BIO_printf(bio_err,"no engine specified\n");
+               else
+                       pkey = ENGINE_load_public_key(e, file, NULL);
+               goto end;
+               }
        key=BIO_new(BIO_s_file());
        if (key == NULL)
                {