Eliminate header magic duplication all over the place, export it
authorPanu Matilainen <pmatilai@redhat.com>
Mon, 5 Jan 2009 09:18:46 +0000 (11:18 +0200)
committerPanu Matilainen <pmatilai@redhat.com>
Mon, 5 Jan 2009 09:18:46 +0000 (11:18 +0200)
- avoid several copies of the same thing...
- there are valid reasons for wanting to know header magic outside librpm,
  export it as rpm_header_magic

lib/header.c
lib/header.h
lib/package.c
lib/rpmchecksig.c
lib/signature.c

index afb9141..0d914de 100644 (file)
@@ -20,7 +20,7 @@ int _hdr_debug = 0;
 
 /** \ingroup header
  */
-static unsigned char const header_magic[8] = {
+const unsigned char rpm_header_magic[8] = {
        0x8e, 0xad, 0xe8, 0x01, 0x00, 0x00, 0x00, 0x00
 };
 
@@ -235,7 +235,7 @@ unsigned headerSizeof(Header h, enum hMagic magicp)
 
     switch (magicp) {
     case HEADER_MAGIC_YES:
-       size += sizeof(header_magic);
+       size += sizeof(rpm_header_magic);
        break;
     case HEADER_MAGIC_NO:
        break;
@@ -1053,7 +1053,7 @@ Header headerRead(FD_t fd, enum hMagic magicp)
 
     if (magicp == HEADER_MAGIC_YES) {
        magic = block[i++];
-       if (memcmp(&magic, header_magic, sizeof(magic)))
+       if (memcmp(&magic, rpm_header_magic, sizeof(magic)))
            goto exit;
        reserved = block[i++];
     }
@@ -1101,8 +1101,8 @@ int headerWrite(FD_t fd, Header h, enum hMagic magicp)
        return 1;
     switch (magicp) {
     case HEADER_MAGIC_YES:
-       nb = Fwrite(header_magic, sizeof(char), sizeof(header_magic), fd);
-       if (nb != sizeof(header_magic))
+       nb = Fwrite(rpm_header_magic, sizeof(uint8_t), sizeof(rpm_header_magic), fd);
+       if (nb != sizeof(rpm_header_magic))
            goto exit;
        break;
     case HEADER_MAGIC_NO:
index aa93e22..4f06c8f 100644 (file)
 extern "C" {
 #endif
 
+/** \ingroup header 
+ * Header magic value
+ */ 
+extern const unsigned char rpm_header_magic[8];
+
 /** \ingroup header
  * Include calculation for 8 bytes of (magic, 0)?
  */
index d3a093b..15e9469 100644 (file)
@@ -27,11 +27,6 @@ static unsigned int nkeyids = 0;
 static unsigned int nextkeyid  = 0;
 static unsigned int * keyids;
 
-/* XXX FIXME: these are doubled here and header.c and .. */
-static unsigned char const header_magic[8] = {
-        0x8e, 0xad, 0xe8, 0x01, 0x00, 0x00, 0x00, 0x00
-};
-
 void headerMergeLegacySigs(Header h, const Header sigh)
 {
     HeaderIterator hi;
@@ -417,8 +412,8 @@ verifyinfo_exit:
        (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_DIGEST), 0);
        dig->hdrmd5ctx = rpmDigestInit(dig->signature.hash_algo, RPMDIGEST_NONE);
 
-       b = (unsigned char *) header_magic;
-       nb = sizeof(header_magic);
+       b = (unsigned char *) rpm_header_magic;
+       nb = sizeof(rpm_header_magic);
         (void) rpmDigestUpdate(dig->hdrmd5ctx, b, nb);
         dig->nbytes += nb;
 
@@ -458,8 +453,8 @@ verifyinfo_exit:
        (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_DIGEST), 0);
        dig->hdrsha1ctx = rpmDigestInit(PGPHASHALGO_SHA1, RPMDIGEST_NONE);
 
-       b = (unsigned char *) header_magic;
-       nb = sizeof(header_magic);
+       b = (unsigned char *) rpm_header_magic;
+       nb = sizeof(rpm_header_magic);
         (void) rpmDigestUpdate(dig->hdrsha1ctx, b, nb);
         dig->nbytes += nb;
 
@@ -524,7 +519,7 @@ rpmRC rpmReadHeader(rpmts ts, FD_t fd, Header *hdrp, char ** msg)
                _("hdr size(%d): BAD, read returned %d\n"), (int)sizeof(block), xx);
        goto exit;
     }
-    if (memcmp(block, header_magic, sizeof(header_magic))) {
+    if (memcmp(block, rpm_header_magic, sizeof(rpm_header_magic))) {
        rasprintf(&buf, _("hdr magic: BAD\n"));
        goto exit;
     }
@@ -736,8 +731,8 @@ rpmRC rpmReadPackageFile(rpmts ts, FD_t fd, const char * fn, Header * hdrp)
            break;
        (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_DIGEST), 0);
        dig->hdrmd5ctx = rpmDigestInit(dig->signature.hash_algo, RPMDIGEST_NONE);
-       (void) rpmDigestUpdate(dig->hdrmd5ctx, header_magic, sizeof(header_magic));
-       dig->nbytes += sizeof(header_magic);
+       (void) rpmDigestUpdate(dig->hdrmd5ctx, rpm_header_magic, sizeof(rpm_header_magic));
+       dig->nbytes += sizeof(rpm_header_magic);
        (void) rpmDigestUpdate(dig->hdrmd5ctx, utd.data, utd.count);
        dig->nbytes += utd.count;
        (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_DIGEST), dig->nbytes);
@@ -761,8 +756,8 @@ rpmRC rpmReadPackageFile(rpmts ts, FD_t fd, const char * fn, Header * hdrp)
            break;
        (void) rpmswEnter(rpmtsOp(ts, RPMTS_OP_DIGEST), 0);
        dig->hdrsha1ctx = rpmDigestInit(PGPHASHALGO_SHA1, RPMDIGEST_NONE);
-       (void) rpmDigestUpdate(dig->hdrsha1ctx, header_magic, sizeof(header_magic));
-       dig->nbytes += sizeof(header_magic);
+       (void) rpmDigestUpdate(dig->hdrsha1ctx, rpm_header_magic, sizeof(rpm_header_magic));
+       dig->nbytes += sizeof(rpm_header_magic);
        (void) rpmDigestUpdate(dig->hdrsha1ctx, utd.data, utd.count);
        dig->nbytes += utd.count;
        (void) rpmswExit(rpmtsOp(ts, RPMTS_OP_DIGEST), dig->nbytes);
index 7e8131e..f80222d 100644 (file)
@@ -460,10 +460,6 @@ rpmtsClean(ts);
     return res;
 }
 
-static unsigned char const header_magic[8] = {
-        0x8e, 0xad, 0xe8, 0x01, 0x00, 0x00, 0x00, 0x00
-};
-
 /**
  * @todo If the GPG key was known available, the md5 digest could be skipped.
  */
@@ -495,10 +491,10 @@ static int readFile(FD_t fd, const char * fn, pgpDig dig)
                goto exit;
            }
            dig->hdrsha1ctx = rpmDigestInit(PGPHASHALGO_SHA1, RPMDIGEST_NONE);
-           (void) rpmDigestUpdate(dig->hdrsha1ctx, header_magic, sizeof(header_magic));
+           (void) rpmDigestUpdate(dig->hdrsha1ctx, rpm_header_magic, sizeof(rpm_header_magic));
            (void) rpmDigestUpdate(dig->hdrsha1ctx, utd.data, utd.count);
            dig->hdrmd5ctx = rpmDigestInit(dig->signature.hash_algo, RPMDIGEST_NONE);
-           (void) rpmDigestUpdate(dig->hdrmd5ctx, header_magic, sizeof(header_magic));
+           (void) rpmDigestUpdate(dig->hdrmd5ctx, rpm_header_magic, sizeof(rpm_header_magic));
            (void) rpmDigestUpdate(dig->hdrmd5ctx, utd.data, utd.count);
            rpmtdFreeData(&utd);
        }
index 67f70ab..feafc5e 100644 (file)
@@ -138,11 +138,6 @@ static inline rpmRC printSize(FD_t fd, size_t siglen, size_t pad, rpm_loff_t dat
     return RPMRC_OK;
 }
 
-/* XXX sigh yet another duplicate.. */
-static unsigned char const header_magic[8] = {
-    0x8e, 0xad, 0xe8, 0x01, 0x00, 0x00, 0x00, 0x00
-};
-
 rpmRC rpmReadSignature(FD_t fd, Header * sighp, sigType sig_type, char ** msg)
 {
     char *buf = NULL;
@@ -174,7 +169,7 @@ rpmRC rpmReadSignature(FD_t fd, Header * sighp, sigType sig_type, char ** msg)
                  (int)sizeof(block), xx);
        goto exit;
     }
-    if (memcmp(block, header_magic, sizeof(header_magic))) {
+    if (memcmp(block, rpm_header_magic, sizeof(rpm_header_magic))) {
        rasprintf(&buf, _("sigh magic: BAD\n"));
        goto exit;
     }
@@ -698,7 +693,7 @@ static int makeHDRSignature(Header sigh, const char * file, rpmSigTag sigTag,
                goto exit;
            }
            ctx = rpmDigestInit(PGPHASHALGO_SHA1, RPMDIGEST_NONE);
-           (void) rpmDigestUpdate(ctx, header_magic, sizeof(header_magic));
+           (void) rpmDigestUpdate(ctx, rpm_header_magic, sizeof(rpm_header_magic));
            (void) rpmDigestUpdate(ctx, utd.data, utd.count);
            (void) rpmDigestFinal(ctx, (void **)&SHA1, NULL, 1);
            rpmtdFreeData(&utd);