[Rpm-maint] [PATCH v8 02/11] Export generateSignature

Fionnuala Gunter fionnuala.gunter at gmail.com
Tue Jul 21 04:35:27 UTC 2015


From: "fin at linux.vnet.ibm.com" <fin at linux.vnet.ibm.com>

This patch exports generateSignature under the new name rpmGenerateSignature
so that includeFileSignatures can call it.
---
 build/pack.c    | 90 ++-------------------------------------------------------
 lib/signature.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 lib/signature.h | 11 +++++++
 3 files changed, 100 insertions(+), 88 deletions(-)

diff --git a/build/pack.c b/build/pack.c
index e351c5b..430eef0 100644
--- a/build/pack.c
+++ b/build/pack.c
@@ -289,92 +289,6 @@ static rpm_loff_t estimateCpioSize(Package pkg)
     return size;
 }
 
-static rpmRC generateSignature(char *SHA1, uint8_t *MD5, rpm_loff_t size,
-				rpm_loff_t payloadSize, FD_t fd)
-{
-    Header sig = NULL;
-    struct rpmtd_s td;
-    rpmRC rc = RPMRC_OK;
-    char *reservedSpace;
-    int spaceSize = 0;
-
-    /* Prepare signature */
-    sig = rpmNewSignature();
-
-    rpmtdReset(&td);
-    td.tag = RPMSIGTAG_SHA1;
-    td.count = 1;
-    td.type = RPM_STRING_TYPE;
-    td.data = SHA1;
-    headerPut(sig, &td, HEADERPUT_DEFAULT);
-
-    rpmtdReset(&td);
-    td.tag = RPMSIGTAG_MD5;
-    td.count = 16;
-    td.type = RPM_BIN_TYPE;
-    td.data = MD5;
-    headerPut(sig, &td, HEADERPUT_DEFAULT);
-
-    rpmtdReset(&td);
-    td.count = 1;
-    if (payloadSize < UINT32_MAX) {
-	rpm_off_t p = payloadSize;
-	rpm_off_t s = size;
-	td.type = RPM_INT32_TYPE;
-
-	td.tag = RPMSIGTAG_PAYLOADSIZE;
-	td.data = &p;
-	headerPut(sig, &td, HEADERPUT_DEFAULT);
-
-	td.tag = RPMSIGTAG_SIZE;
-	td.data = &s;
-	headerPut(sig, &td, HEADERPUT_DEFAULT);
-    } else {
-	rpm_loff_t p = payloadSize;
-	rpm_loff_t s = size;
-	td.type = RPM_INT64_TYPE;
-
-	td.tag = RPMSIGTAG_LONGARCHIVESIZE;
-	td.data = &p;
-	headerPut(sig, &td, HEADERPUT_DEFAULT);
-
-	td.tag = RPMSIGTAG_LONGSIZE;
-	td.data = &s;
-	headerPut(sig, &td, HEADERPUT_DEFAULT);
-    }
-
-    spaceSize = rpmExpandNumeric("%{__gpg_reserved_space}");
-    if(spaceSize > 0) {
-	reservedSpace = xcalloc(spaceSize, sizeof(char));
-	rpmtdReset(&td);
-	td.tag = RPMSIGTAG_RESERVEDSPACE;
-	td.count = spaceSize;
-	td.type = RPM_BIN_TYPE;
-	td.data = reservedSpace;
-	headerPut(sig, &td, HEADERPUT_DEFAULT);
-	free(reservedSpace);
-    }
-
-    /* Reallocate the signature into one contiguous region. */
-    sig = headerReload(sig, RPMTAG_HEADERSIGNATURES);
-    if (sig == NULL) { /* XXX can't happen */
-	rpmlog(RPMLOG_ERR, _("Unable to reload signature header.\n"));
-	rc = RPMRC_FAIL;
-	goto exit;
-    }
-
-    /* Write the signature section into the package. */
-    if (rpmWriteSignature(fd, sig)) {
-	rc = RPMRC_FAIL;
-	goto exit;
-    }
-
-exit:
-    rpmFreeSignature(sig);
-    return rc;
-}
-
-
 static rpmRC writeRPM(Package pkg, unsigned char ** pkgidp,
 		      const char *fileName, char **cookie)
 {
@@ -513,7 +427,7 @@ static rpmRC writeRPM(Package pkg, unsigned char ** pkgidp,
     sigStart = Ftell(fd);
 
     /* Generate and write a placeholder signature header */
-    rc = generateSignature(zerosS, zeros, 0, estimatedCpioSize, fd);
+    rc = rpmGenerateSignature(zerosS, zeros, 0, estimatedCpioSize, fd);
     if (rc != RPMRC_OK) {
 	rc = RPMRC_FAIL;
 	goto exit;
@@ -569,7 +483,7 @@ static rpmRC writeRPM(Package pkg, unsigned char ** pkgidp,
     }
 
     /* Generate the signature. Now with right values */
-    rc = generateSignature(SHA1, MD5, sigTargetSize, pkg->cpioArchiveSize, fd);
+    rc = rpmGenerateSignature(SHA1, MD5, sigTargetSize, pkg->cpioArchiveSize, fd);
     if (rc != RPMRC_OK) {
 	rc = RPMRC_FAIL;
 	goto exit;
diff --git a/lib/signature.c b/lib/signature.c
index 0defc81..972c0d5 100644
--- a/lib/signature.c
+++ b/lib/signature.c
@@ -12,6 +12,7 @@
 #include <rpm/rpmfileutil.h>
 #include <rpm/rpmlog.h>
 #include <rpm/rpmkeyring.h>
+#include <rpm/rpmmacro.h>
 
 #include "lib/rpmlead.h"
 #include "lib/signature.h"
@@ -296,6 +297,92 @@ Header rpmFreeSignature(Header sigh)
     return headerFree(sigh);
 }
 
+rpmRC rpmGenerateSignature(char *SHA1, uint8_t *MD5, rpm_loff_t size,
+                                rpm_loff_t payloadSize, FD_t fd)
+{
+    Header sig = NULL;
+    struct rpmtd_s td;
+    rpmRC rc = RPMRC_OK;
+    char *reservedSpace;
+    int spaceSize = 0;
+
+    /* Prepare signature */
+    sig = rpmNewSignature();
+
+    rpmtdReset(&td);
+    td.tag = RPMSIGTAG_SHA1;
+    td.count = 1;
+    td.type = RPM_STRING_TYPE;
+    td.data = SHA1;
+    headerPut(sig, &td, HEADERPUT_DEFAULT);
+
+    rpmtdReset(&td);
+    td.tag = RPMSIGTAG_MD5;
+    td.count = 16;
+    td.type = RPM_BIN_TYPE;
+    td.data = MD5;
+    headerPut(sig, &td, HEADERPUT_DEFAULT);
+
+    rpmtdReset(&td);
+    td.count = 1;
+    if (payloadSize < UINT32_MAX) {
+        rpm_off_t p = payloadSize;
+        rpm_off_t s = size;
+        td.type = RPM_INT32_TYPE;
+
+        td.tag = RPMSIGTAG_PAYLOADSIZE;
+        td.data = &p;
+        headerPut(sig, &td, HEADERPUT_DEFAULT);
+
+        td.tag = RPMSIGTAG_SIZE;
+        td.data = &s;
+        headerPut(sig, &td, HEADERPUT_DEFAULT);
+    } else {
+        rpm_loff_t p = payloadSize;
+        rpm_loff_t s = size;
+        td.type = RPM_INT64_TYPE;
+
+        td.tag = RPMSIGTAG_LONGARCHIVESIZE;
+        td.data = &p;
+        headerPut(sig, &td, HEADERPUT_DEFAULT);
+
+        td.tag = RPMSIGTAG_LONGSIZE;
+        td.data = &s;
+        headerPut(sig, &td, HEADERPUT_DEFAULT);
+    }
+
+    spaceSize = rpmExpandNumeric("%{__gpg_reserved_space}");
+    if(spaceSize > 0) {
+        reservedSpace = xcalloc(spaceSize, sizeof(char));
+        rpmtdReset(&td);
+        td.tag = RPMSIGTAG_RESERVEDSPACE;
+        td.count = spaceSize;
+        td.type = RPM_BIN_TYPE;
+        td.data = reservedSpace;
+        headerPut(sig, &td, HEADERPUT_DEFAULT);
+        free(reservedSpace);
+    }
+
+    /* Reallocate the signature into one contiguous region. */
+    sig = headerReload(sig, RPMTAG_HEADERSIGNATURES);
+    if (sig == NULL) { /* XXX can't happen */
+        rpmlog(RPMLOG_ERR, _("Unable to reload signature header.\n"));
+        rc = RPMRC_FAIL;
+        goto exit;
+    }
+
+    /* Write the signature section into the package. */
+    if (rpmWriteSignature(fd, sig)) {
+        rc = RPMRC_FAIL;
+        goto exit;
+    }
+
+exit:
+    rpmFreeSignature(sig);
+    return rc;
+}
+
+
 static const char * rpmSigString(rpmRC res)
 {
     const char * str;
diff --git a/lib/signature.h b/lib/signature.h
index b2c61ca..7866e7b 100644
--- a/lib/signature.h
+++ b/lib/signature.h
@@ -78,6 +78,17 @@ rpmRC rpmVerifySignature(rpmKeyring keyring, rpmtd sigtd, pgpDigParams sig,
  */
 Header rpmFreeSignature(Header h);
 
+/** \ingroup signature
+ * Generate signature and write to file
+ * @param SHA1		SHA1 digest
+ * @param MD5		MD5 digest
+ * @param size		size of header
+ * @param payloadSize	size of archive
+ * @param fd		output file
+ */
+rpmRC rpmGenerateSignature(char *SHA1, uint8_t *MD5, rpm_loff_t size,
+				rpm_loff_t payloadSize, FD_t fd);
+
 RPM_GNUC_INTERNAL
 rpmRC rpmSigInfoParse(rpmtd td, const char *origin,
                      struct sigtInfo_s *sigt, pgpDigParams *sigp, char **msg);
-- 
2.4.3



More information about the Rpm-maint mailing list