fix indent, newline
[openssl.git] / crypto / asn1 / t_x509.c
index 7d22e1c0ce2a4890930f0d42fce569a5d66fefdb..d7eab16339428f5e09bda947003bce081d8681e4 100644 (file)
@@ -72,6 +72,7 @@
 #include <openssl/objects.h>
 #include <openssl/x509.h>
 #include <openssl/x509v3.h>
+#include "asn1_locl.h"
 
 #ifndef OPENSSL_NO_FP_API
 int X509_print_fp(FILE *fp, X509 *x)
@@ -255,7 +256,8 @@ int X509_ocspid_print (BIO *bp, X509 *x)
                goto err;
        i2d_X509_NAME(x->cert_info->subject, &dertmp);
 
-       EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL);
+       if (!EVP_Digest(der, derlen, SHA1md, NULL, EVP_sha1(), NULL))
+               goto err;
        for (i=0; i < SHA_DIGEST_LENGTH; i++)
                {
                if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0) goto err;
@@ -268,8 +270,10 @@ int X509_ocspid_print (BIO *bp, X509 *x)
        if (BIO_printf(bp,"\n        Public key OCSP hash: ") <= 0)
                goto err;
 
-       EVP_Digest(x->cert_info->key->public_key->data,
-               x->cert_info->key->public_key->length, SHA1md, NULL, EVP_sha1(), NULL);
+       if (!EVP_Digest(x->cert_info->key->public_key->data,
+                       x->cert_info->key->public_key->length,
+                       SHA1md, NULL, EVP_sha1(), NULL))
+               goto err;
        for (i=0; i < SHA_DIGEST_LENGTH; i++)
                {
                if (BIO_printf(bp,"%02X",SHA1md[i]) <= 0)
@@ -283,26 +287,50 @@ err:
        return(0);
        }
 
-int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig)
+int X509_signature_dump(BIO *bp, const ASN1_STRING *sig, int indent)
 {
-       unsigned char *s;
+       const unsigned char *s;
        int i, n;
-       if (BIO_puts(bp,"    Signature Algorithm: ") <= 0) return 0;
-       if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0) return 0;
 
        n=sig->length;
        s=sig->data;
        for (i=0; i<n; i++)
                {
                if ((i%18) == 0)
-                       if (BIO_write(bp,"\n        ",9) <= 0) return 0;
+                       {
+                       if (BIO_write(bp,"\n",1) <= 0) return 0;
+                       if (BIO_indent(bp, indent, indent) <= 0) return 0;
+                       }
                        if (BIO_printf(bp,"%02x%s",s[i],
                                ((i+1) == n)?"":":") <= 0) return 0;
                }
        if (BIO_write(bp,"\n",1) != 1) return 0;
+
        return 1;
 }
 
+int X509_signature_print(BIO *bp, X509_ALGOR *sigalg, ASN1_STRING *sig)
+{
+       int sig_nid;
+       if (BIO_puts(bp,"    Signature Algorithm: ") <= 0) return 0;
+       if (i2a_ASN1_OBJECT(bp, sigalg->algorithm) <= 0) return 0;
+
+       sig_nid = OBJ_obj2nid(sigalg->algorithm);
+       if (sig_nid != NID_undef)
+               {
+               int pkey_nid, dig_nid;
+               const EVP_PKEY_ASN1_METHOD *ameth;
+               if (OBJ_find_sigid_algs(sig_nid, &dig_nid, &pkey_nid))
+                       {
+                       ameth = EVP_PKEY_asn1_find(NULL, pkey_nid);
+                       if (ameth && ameth->sig_print)
+                               return ameth->sig_print(bp, sigalg, sig, 9, 0);
+                       }
+               }
+
+       return X509_signature_dump(bp, sig, 9);
+}
+
 int ASN1_STRING_print(BIO *bp, const ASN1_STRING *v)
        {
        int i,n;
@@ -370,13 +398,13 @@ int ASN1_GENERALIZEDTIME_print(BIO *bp, const ASN1_GENERALIZEDTIME *tm)
        d= (v[6]-'0')*10+(v[7]-'0');
        h= (v[8]-'0')*10+(v[9]-'0');
        m=  (v[10]-'0')*10+(v[11]-'0');
-       if (i >= 14 &&
+       if (tm->length >= 14 &&
            (v[12] >= '0') && (v[12] <= '9') &&
            (v[13] >= '0') && (v[13] <= '9'))
                {
                s=  (v[12]-'0')*10+(v[13]-'0');
                /* Check for fractions of seconds. */
-               if (i >= 15 && v[14] == '.')
+               if (tm->length >= 15 && v[14] == '.')
                        {
                        int l = tm->length;
                        f = &v[14];     /* The decimal point. */
@@ -417,7 +445,7 @@ int ASN1_UTCTIME_print(BIO *bp, const ASN1_UTCTIME *tm)
        d= (v[4]-'0')*10+(v[5]-'0');
        h= (v[6]-'0')*10+(v[7]-'0');
        m=  (v[8]-'0')*10+(v[9]-'0');
-       if (i >=12 &&
+       if (tm->length >=12 &&
            (v[10] >= '0') && (v[10] <= '9') &&
            (v[11] >= '0') && (v[11] <= '9'))
                s=  (v[10]-'0')*10+(v[11]-'0');