Split internal header signature and digest generation to separate functions

- These have fairly little in common in reality: one is always
  automatically created on package generation, the other is optional
  extra step requiring passphrases and all sorts of other things.
- The switch-cases are now fairly hysterical but leaving them for
  later spring-clean to keep changes minimal for this step.
- No functional changes (supposedly ;)
This commit is contained in:
Panu Matilainen 2010-09-29 10:29:18 +03:00
parent 17b433ce8c
commit 825691afb2
1 changed files with 46 additions and 26 deletions

View File

@ -461,6 +461,49 @@ static int makeHDRSignature(Header sigh, const char * file, rpmSigTag sigTag,
uint8_t * pkt = NULL; uint8_t * pkt = NULL;
size_t pktlen; size_t pktlen;
char * fn = NULL; char * fn = NULL;
int ret = -1; /* assume failure. */
switch (sigTag) {
case RPMSIGTAG_DSA:
case RPMSIGTAG_RSA:
fd = Fopen(file, "r.fdio");
if (fd == NULL || Ferror(fd))
goto exit;
h = headerRead(fd, HEADER_MAGIC_YES);
if (h == NULL)
goto exit;
(void) Fclose(fd);
fd = rpmMkTempFile(NULL, &fn);
if (fd == NULL || Ferror(fd))
goto exit;
if (headerWrite(fd, h, HEADER_MAGIC_YES))
goto exit;
(void) Fclose(fd); fd = NULL;
if (makeGPGSignature(fn, &sigTag, &pkt, &pktlen, passPhrase)
|| !sighdrPut(sigh, sigTag, RPM_BIN_TYPE, pkt, pktlen))
goto exit;
ret = 0;
break;
default:
goto exit;
break;
}
exit:
if (fn) {
(void) unlink(fn);
free(fn);
}
free(pkt);
h = headerFree(h);
if (fd != NULL) (void) Fclose(fd);
return ret;
}
static int makeHDRDigest(Header sigh, const char * file, rpmSigTag sigTag)
{
Header h = NULL;
FD_t fd = NULL;
char * SHA1 = NULL; char * SHA1 = NULL;
int ret = -1; /* assume failure. */ int ret = -1; /* assume failure. */
@ -501,37 +544,12 @@ static int makeHDRSignature(Header sigh, const char * file, rpmSigTag sigTag,
goto exit; goto exit;
ret = 0; ret = 0;
break; break;
case RPMSIGTAG_DSA:
case RPMSIGTAG_RSA:
fd = Fopen(file, "r.fdio");
if (fd == NULL || Ferror(fd))
goto exit;
h = headerRead(fd, HEADER_MAGIC_YES);
if (h == NULL)
goto exit;
(void) Fclose(fd);
fd = rpmMkTempFile(NULL, &fn);
if (fd == NULL || Ferror(fd))
goto exit;
if (headerWrite(fd, h, HEADER_MAGIC_YES))
goto exit;
(void) Fclose(fd); fd = NULL;
if (makeGPGSignature(fn, &sigTag, &pkt, &pktlen, passPhrase)
|| !sighdrPut(sigh, sigTag, RPM_BIN_TYPE, pkt, pktlen))
goto exit;
ret = 0;
break;
default: default:
goto exit; goto exit;
break; break;
} }
exit: exit:
if (fn) {
(void) unlink(fn);
free(fn);
}
free(pkt);
free(SHA1); free(SHA1);
h = headerFree(h); h = headerFree(h);
if (fd != NULL) (void) Fclose(fd); if (fd != NULL) (void) Fclose(fd);
@ -586,9 +604,11 @@ int rpmAddSignature(Header sigh, const char * file, rpmSigTag sigTag,
} break; } break;
case RPMSIGTAG_RSA: case RPMSIGTAG_RSA:
case RPMSIGTAG_DSA: case RPMSIGTAG_DSA:
case RPMSIGTAG_SHA1:
ret = makeHDRSignature(sigh, file, sigTag, passPhrase); ret = makeHDRSignature(sigh, file, sigTag, passPhrase);
break; break;
case RPMSIGTAG_SHA1:
ret = makeHDRDigest(sigh, file, sigTag);
break;
default: default:
break; break;
} }