Remove duplicate code.
[openssl.git] / crypto / cms / cms_dd.c
index 8919c15be1268fde5e61a889d615284bafa04d74..d5fda1a5c3bdd0aa317e508c2af47dbc31bf9616 100644 (file)
@@ -1,5 +1,6 @@
 /* crypto/cms/cms_dd.c */
-/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
+/*
+ * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
  * project.
  */
 /* ====================================================================
@@ -10,7 +11,7 @@
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer. 
+ *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
@@ -64,85 +65,81 @@ DECLARE_ASN1_ITEM(CMS_DigestedData)
 /* CMS DigestedData Utilities */
 
 CMS_ContentInfo *cms_DigestedData_create(const EVP_MD *md)
-       {
-       CMS_ContentInfo *cms;
-       CMS_DigestedData *dd;
-       cms = CMS_ContentInfo_new();
-       if (!cms)
-               return NULL;
+{
+    CMS_ContentInfo *cms;
+    CMS_DigestedData *dd;
+    cms = CMS_ContentInfo_new();
+    if (!cms)
+        return NULL;
 
-       dd = M_ASN1_new_of(CMS_DigestedData);
+    dd = M_ASN1_new_of(CMS_DigestedData);
 
-       if (!dd)
-               goto err;
+    if (!dd)
+        goto err;
 
-       cms->contentType = OBJ_nid2obj(NID_pkcs7_digest);
-       cms->d.digestedData = dd;
+    cms->contentType = OBJ_nid2obj(NID_pkcs7_digest);
+    cms->d.digestedData = dd;
 
-       dd->version = 0;
-       dd->encapContentInfo->eContentType = OBJ_nid2obj(NID_pkcs7_data);
+    dd->version = 0;
+    dd->encapContentInfo->eContentType = OBJ_nid2obj(NID_pkcs7_data);
 
-       cms_DigestAlgorithm_set(dd->digestAlgorithm, md);
+    X509_ALGOR_set_md(dd->digestAlgorithm, md);
 
-       return cms;
+    return cms;
 
      err:
+ err:
 
-       if (cms)
-               CMS_ContentInfo_free(cms);
+    if (cms)
+        CMS_ContentInfo_free(cms);
 
-       return NULL;
-       }
+    return NULL;
+}
 
 BIO *cms_DigestedData_init_bio(CMS_ContentInfo *cms)
-       {
-       CMS_DigestedData *dd;
-       dd = cms->d.digestedData;
-       return cms_DigestAlgorithm_init_bio(dd->digestAlgorithm);
-       }
+{
+    CMS_DigestedData *dd;
+    dd = cms->d.digestedData;
+    return cms_DigestAlgorithm_init_bio(dd->digestAlgorithm);
+}
 
 int cms_DigestedData_do_final(CMS_ContentInfo *cms, BIO *chain, int verify)
-       {
-       EVP_MD_CTX mctx;
-       unsigned char md[EVP_MAX_MD_SIZE];
-       unsigned int mdlen;
-       int r = 0;
-       CMS_DigestedData *dd;
-       EVP_MD_CTX_init(&mctx);
-
-       dd = cms->d.digestedData;
-
-       if (!cms_DigestAlgorithm_find_ctx(&mctx, chain, dd->digestAlgorithm))
-               goto err;
-
-       if (EVP_DigestFinal_ex(&mctx, md, &mdlen) <= 0)
-               goto err;
-
-       if (verify)
-               {
-               if (mdlen != (unsigned int)dd->digest->length)
-                       {
-                       CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL,
-                               CMS_R_MESSAGEDIGEST_WRONG_LENGTH);
-                       goto err;
-                       }
-
-               if (memcmp(md, dd->digest->data, mdlen))
-                       CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL,
-                               CMS_R_VERIFICATION_FAILURE);
-               else
-                       r = 1;
-               }
-       else
-               {
-               if (!ASN1_STRING_set(dd->digest, md, mdlen))
-                       goto err;
-               r = 1;
-               }
-
-       err:
-       EVP_MD_CTX_cleanup(&mctx);
-
-       return r;
-
-       }
+{
+    EVP_MD_CTX mctx;
+    unsigned char md[EVP_MAX_MD_SIZE];
+    unsigned int mdlen;
+    int r = 0;
+    CMS_DigestedData *dd;
+    EVP_MD_CTX_init(&mctx);
+
+    dd = cms->d.digestedData;
+
+    if (!cms_DigestAlgorithm_find_ctx(&mctx, chain, dd->digestAlgorithm))
+        goto err;
+
+    if (EVP_DigestFinal_ex(&mctx, md, &mdlen) <= 0)
+        goto err;
+
+    if (verify) {
+        if (mdlen != (unsigned int)dd->digest->length) {
+            CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL,
+                   CMS_R_MESSAGEDIGEST_WRONG_LENGTH);
+            goto err;
+        }
+
+        if (memcmp(md, dd->digest->data, mdlen))
+            CMSerr(CMS_F_CMS_DIGESTEDDATA_DO_FINAL,
+                   CMS_R_VERIFICATION_FAILURE);
+        else
+            r = 1;
+    } else {
+        if (!ASN1_STRING_set(dd->digest, md, mdlen))
+            goto err;
+        r = 1;
+    }
+
+ err:
+    EVP_MD_CTX_cleanup(&mctx);
+
+    return r;
+
+}