Update ASN1 printing code and add a -print option to 'pkcs7' utility for
authorDr. Stephen Henson <steve@openssl.org>
Thu, 1 Sep 2005 18:00:56 +0000 (18:00 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Thu, 1 Sep 2005 18:00:56 +0000 (18:00 +0000)
initial testing.

apps/pkcs7.c
crypto/asn1/asn1.h
crypto/asn1/asn1t.h
crypto/asn1/tasn_prn.c
crypto/pkcs7/pk7_asn1.c
crypto/pkcs7/pkcs7.h

index da4dbe7a07c0706a223784f2143495fd414a9f58..aa1852a9fafea871c27230f7100463e73e261e9f 100644 (file)
@@ -90,7 +90,7 @@ int MAIN(int argc, char **argv)
        BIO *in=NULL,*out=NULL;
        int informat,outformat;
        char *infile,*outfile,*prog;
-       int print_certs=0,text=0,noout=0;
+       int print_certs=0,text=0,noout=0,p7_print=0;
        int ret=1;
 #ifndef OPENSSL_NO_ENGINE
        char *engine=NULL;
@@ -139,6 +139,8 @@ int MAIN(int argc, char **argv)
                        noout=1;
                else if (strcmp(*argv,"-text") == 0)
                        text=1;
+               else if (strcmp(*argv,"-print") == 0)
+                       p7_print=1;
                else if (strcmp(*argv,"-print_certs") == 0)
                        print_certs=1;
 #ifndef OPENSSL_NO_ENGINE
@@ -238,6 +240,9 @@ bad:
                        }
                }
 
+       if (p7_print)
+               PKCS7_print(out, p7, 0, NULL);
+
        if (print_certs)
                {
                STACK_OF(X509) *certs=NULL;
index 2d9f940f67924d563b330d9e0562190116d6eaa0..c8fb6fa01ce41c9ada7209c0e26a8e6bce340043 100644 (file)
@@ -317,6 +317,13 @@ typedef struct ASN1_VALUE_st ASN1_VALUE;
        type *name##_new(void); \
        void name##_free(type *a);
 
+#define DECLARE_ASN1_PRINT_FUNCTION(stname) \
+       DECLARE_ASN1_PRINT_FUNCTION_fname(stname, stname)
+
+#define DECLARE_ASN1_PRINT_FUNCTION_fname(stname, fname) \
+       int fname##_print(BIO *out, stname *x, int indent, \
+                                        const ASN1_PCTX *pctx);
+
 #define D2I_OF(type) type *(*)(type **,const unsigned char **,long)
 #define I2D_OF(type) int (*)(type *,unsigned char **)
 #define I2D_OF_const(type) int (*)(const type *,unsigned char **)
@@ -1011,6 +1018,8 @@ ASN1_TYPE *ASN1_generate_v3(char *str, X509V3_CTX *cnf);
 /* Don't show structure name even at top level */
 #define ASN1_PCTX_FLAGS_NO_STRUCT_NAME         0x100
 
+int ASN1_item_print(BIO *out, ASN1_VALUE *ifld, int indent,
+                               const ASN1_ITEM *it, const ASN1_PCTX *pctx);
 ASN1_PCTX *ASN1_PCTX_new(void);
 void ASN1_PCTX_free(ASN1_PCTX *p);
 unsigned long ASN1_PCTX_get_flags(ASN1_PCTX *p);
index 9f5d60947e33e3c79cc47aa01dc8d94dd2dbc18d..b44f75c2341c972afccddc508725ecfc71957c5f 100644 (file)
@@ -832,6 +832,17 @@ typedef struct ASN1_AUX_st {
         return ASN1_item_dup(ASN1_ITEM_rptr(stname), x); \
         }
 
+#define IMPLEMENT_ASN1_PRINT_FUNCTION(stname) \
+       IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, stname, stname)
+
+#define IMPLEMENT_ASN1_PRINT_FUNCTION_fname(stname, itname, fname) \
+       int fname##_print(BIO *out, stname *x, int indent, \
+                                               const ASN1_PCTX *pctx) \
+       { \
+               return ASN1_item_print(out, (ASN1_VALUE *)x, indent, \
+                       ASN1_ITEM_rptr(itname), pctx); \
+       } 
+
 #define IMPLEMENT_ASN1_FUNCTIONS_const(name) \
                IMPLEMENT_ASN1_FUNCTIONS_const_fname(name, name, name)
 
index a0254f65216835e10dd5c7c4ac115d59b9830d31..1c0379564a22b5d16ea53328ade22f937c11ab8a 100644 (file)
@@ -161,12 +161,15 @@ static int asn1_item_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
                                const ASN1_ITEM *it,
                                const char *fname, const char *sname,
                                int nohdr, const ASN1_PCTX *pctx);
+
 int asn1_template_print_ctx(BIO *out, ASN1_VALUE **fld, int indent,
                                const ASN1_TEMPLATE *tt, const ASN1_PCTX *pctx);
+
 static int asn1_primitive_print(BIO *out, ASN1_VALUE **fld,
                                const ASN1_ITEM *it, int indent,
                                const char *fname, const char *sname,
                                const ASN1_PCTX *pctx);
+
 static int asn1_print_fsname(BIO *out, int indent,
                        const char *fname, const char *sname,
                        const ASN1_PCTX *pctx);
index 77931feeb417a66ce3cabf11cedb34c32df3700f..d0471e06943254835992f50c700ff41bff01a0e0 100644 (file)
@@ -212,3 +212,5 @@ ASN1_ITEM_TEMPLATE(PKCS7_ATTR_VERIFY) =
        ASN1_EX_TEMPLATE_TYPE(ASN1_TFLG_SEQUENCE_OF | ASN1_TFLG_IMPTAG | ASN1_TFLG_UNIVERSAL,
                                V_ASN1_SET, PKCS7_ATTRIBUTES, X509_ATTRIBUTE)
 ASN1_ITEM_TEMPLATE_END(PKCS7_ATTR_VERIFY)
+
+IMPLEMENT_ASN1_PRINT_FUNCTION(PKCS7)
index cc092d262dc313e827751990c3d42191b30bf954..d699ed903a42cf0928fa237d4bd9818dcf10b7c2 100644 (file)
@@ -307,6 +307,7 @@ DECLARE_ASN1_ITEM(PKCS7_ATTR_SIGN)
 DECLARE_ASN1_ITEM(PKCS7_ATTR_VERIFY)
 
 DECLARE_ASN1_NDEF_FUNCTION(PKCS7)
+DECLARE_ASN1_PRINT_FUNCTION(PKCS7)
 
 long PKCS7_ctrl(PKCS7 *p7, int cmd, long larg, char *parg);