Change RNG test to block oriented instead of request oriented, add option
[openssl.git] / apps / asn1pars.c
index 305db1590359068f9e7360cbcd43a21faf5d94b6..b5d65e725b8e505e49ff318b95ef155cadeadfc0 100644 (file)
@@ -56,7 +56,7 @@
  * [including the GNU Public Licence.]
  */
 
-/* A nice addition from Dr Stephen Henson <shenson@bigfoot.com> to 
+/* A nice addition from Dr Stephen Henson <steve@openssl.org> to 
  * add the -strparse option which parses nested binary structures
  */
 
@@ -96,7 +96,7 @@ int MAIN(int argc, char **argv)
        unsigned char *tmpbuf;
        const unsigned char *ctmpbuf;
        BUF_MEM *buf=NULL;
-       STACK *osk=NULL;
+       STACK_OF(OPENSSL_STRING) *osk=NULL;
        ASN1_TYPE *at=NULL;
 
        informat=FORMAT_PEM;
@@ -113,7 +113,7 @@ int MAIN(int argc, char **argv)
        prog=argv[0];
        argc--;
        argv++;
-       if ((osk=sk_new_null()) == NULL)
+       if ((osk=sk_OPENSSL_STRING_new_null()) == NULL)
                {
                BIO_printf(bio_err,"Memory allocation failure\n");
                goto end;
@@ -169,7 +169,7 @@ int MAIN(int argc, char **argv)
                else if (strcmp(*argv,"-strparse") == 0)
                        {
                        if (--argc < 1) goto bad;
-                       sk_push(osk,*(++argv));
+                       sk_OPENSSL_STRING_push(osk,*(++argv));
                        }
                else if (strcmp(*argv,"-genstr") == 0)
                        {
@@ -196,7 +196,7 @@ int MAIN(int argc, char **argv)
 bad:
                BIO_printf(bio_err,"%s [options] <infile\n",prog);
                BIO_printf(bio_err,"where options are\n");
-               BIO_printf(bio_err," -inform arg   input format - one of DER TXT PEM\n");
+               BIO_printf(bio_err," -inform arg   input format - one of DER PEM\n");
                BIO_printf(bio_err," -in arg       input file\n");
                BIO_printf(bio_err," -out arg      output file (output format is always DER\n");
                BIO_printf(bio_err," -noout arg    don't produce any output\n");
@@ -302,17 +302,18 @@ bad:
 
        /* If any structs to parse go through in sequence */
 
-       if (sk_num(osk))
+       if (sk_OPENSSL_STRING_num(osk))
                {
                tmpbuf=(unsigned char *)str;
                tmplen=num;
-               for (i=0; i<sk_num(osk); i++)
+               for (i=0; i<sk_OPENSSL_STRING_num(osk); i++)
                        {
                        ASN1_TYPE *atmp;
-                       j=atoi(sk_value(osk,i));
+                       int typ;
+                       j=atoi(sk_OPENSSL_STRING_value(osk,i));
                        if (j == 0)
                                {
-                               BIO_printf(bio_err,"'%s' is an invalid number\n",sk_value(osk,i));
+                               BIO_printf(bio_err,"'%s' is an invalid number\n",sk_OPENSSL_STRING_value(osk,i));
                                continue;
                                }
                        tmpbuf+=j;
@@ -327,6 +328,15 @@ bad:
                                ERR_print_errors(bio_err);
                                goto end;
                                }
+                       typ = ASN1_TYPE_get(at);
+                       if ((typ == V_ASN1_OBJECT)
+                               || (typ == V_ASN1_NULL))
+                               {
+                               BIO_printf(bio_err, "Can't parse %s type\n",
+                                       typ == V_ASN1_NULL ? "NULL" : "OBJECT");
+                               ERR_print_errors(bio_err);
+                               goto end;
+                               }
                        /* hmm... this is a little evil but it works */
                        tmpbuf=at->value.asn1_string->data;
                        tmplen=at->value.asn1_string->length;
@@ -368,7 +378,7 @@ end:
                ERR_print_errors(bio_err);
        if (buf != NULL) BUF_MEM_free(buf);
        if (at != NULL) ASN1_TYPE_free(at);
-       if (osk != NULL) sk_free(osk);
+       if (osk != NULL) sk_OPENSSL_STRING_free(osk);
        OBJ_cleanup();
        apps_shutdown();
        OPENSSL_EXIT(ret);