summaryrefslogtreecommitdiff
path: root/lib/libalpm/signing.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-05-04 15:42:50 -0500
committerDan McGee <dan@archlinux.org>2011-05-04 15:46:18 -0500
commitc03faa32f335f3fb7bc1bc8718dd1781781ef3dd (patch)
tree98fd183e210e4e762215ed75229565f54fe7f2e1 /lib/libalpm/signing.c
parent4758cfe33f9a8473312a9fee718c45bf72f555f5 (diff)
Reduce duplicate signing debug code and fix logic condition
We had a lot of similar looking code that we can collapse down into a function. This also fixes errors seen when turning on some gcc warnings and implicitly casting away the const-ness of the string. Free the list when we are done with it as well. Also, fix a logic error where we should be checking with &&, not ||. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/signing.c')
-rw-r--r--lib/libalpm/signing.c58
1 files changed, 23 insertions, 35 deletions
diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c
index a2a6457a..b3a6500e 100644
--- a/lib/libalpm/signing.c
+++ b/lib/libalpm/signing.c
@@ -60,6 +60,15 @@ static const char *gpgme_string_validity(gpgme_validity_t validity)
return "???";
}
+static alpm_list_t *sigsum_test_bit(gpgme_sigsum_t sigsum, alpm_list_t *summary,
+ gpgme_sigsum_t bit, const char *value)
+{
+ if(sigsum & bit) {
+ summary = alpm_list_add(summary, (void *)value);
+ }
+ return summary;
+}
+
static alpm_list_t *gpgme_list_sigsum(gpgme_sigsum_t sigsum)
{
alpm_list_t *summary = NULL;
@@ -67,52 +76,30 @@ static alpm_list_t *gpgme_list_sigsum(gpgme_sigsum_t sigsum)
* for it anyway and show all possible flags in the returned string. */
/* The signature is fully valid. */
- if(sigsum & GPGME_SIGSUM_VALID) {
- summary = alpm_list_add(summary, "valid");
- }
+ summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_VALID, "valid");
/* The signature is good. */
- if(sigsum & GPGME_SIGSUM_GREEN) {
- summary = alpm_list_add(summary, "green");
- }
+ summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_GREEN, "green");
/* The signature is bad. */
- if(sigsum & GPGME_SIGSUM_RED) {
- summary = alpm_list_add(summary, "red");
- }
+ summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_RED, "red");
/* One key has been revoked. */
- if(sigsum & GPGME_SIGSUM_KEY_REVOKED) {
- summary = alpm_list_add(summary, "key revoked");
- }
+ summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_KEY_REVOKED, "key revoked");
/* One key has expired. */
- if(sigsum & GPGME_SIGSUM_KEY_EXPIRED) {
- summary = alpm_list_add(summary, "key expired");
- }
+ summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_KEY_EXPIRED, "key expired");
/* The signature has expired. */
- if(sigsum & GPGME_SIGSUM_SIG_EXPIRED) {
- summary = alpm_list_add(summary, "sig expired");
- }
+ summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_SIG_EXPIRED, "sig expired");
/* Can't verify: key missing. */
- if(sigsum & GPGME_SIGSUM_KEY_MISSING) {
- summary = alpm_list_add(summary, "key missing");
- }
+ summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_KEY_MISSING, "key missing");
/* CRL not available. */
- if(sigsum & GPGME_SIGSUM_CRL_MISSING) {
- summary = alpm_list_add(summary, "crl missing");
- }
+ summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_CRL_MISSING, "crl missing");
/* Available CRL is too old. */
- if(sigsum & GPGME_SIGSUM_CRL_TOO_OLD) {
- summary = alpm_list_add(summary, "crl too old");
- }
+ summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_CRL_TOO_OLD, "crl too old");
/* A policy was not met. */
- if(sigsum & GPGME_SIGSUM_BAD_POLICY) {
- summary = alpm_list_add(summary, "bad policy");
- }
+ summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_BAD_POLICY, "bad policy");
/* A system error occured. */
- if(sigsum & GPGME_SIGSUM_SYS_ERROR) {
- summary = alpm_list_add(summary, "sys error");
- }
+ summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_SYS_ERROR, "sys error");
/* Fallback case */
if(!sigsum) {
- summary = alpm_list_add(summary, "(empty)");
+ summary = alpm_list_add(summary, (void *)"(empty)");
}
return summary;
}
@@ -189,7 +176,7 @@ static int decode_signature(const char *base64_data,
int ret, destlen = 0;
/* get the necessary size for the buffer by passing 0 */
ret = base64_decode(NULL, &destlen, usline, len);
- if(ret != 0 || ret != POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) {
+ if(ret != 0 && ret != POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) {
goto error;
}
/* alloc our memory and repeat the call to decode */
@@ -316,6 +303,7 @@ int _alpm_gpgme_checksig(const char *path, const char *base64_sig)
for(summary = summary_list; summary; summary = summary->next) {
_alpm_log(PM_LOG_DEBUG, "summary: %s\n", (const char *)summary->data);
}
+ alpm_list_free(summary_list);
_alpm_log(PM_LOG_DEBUG, "status: %s\n", gpgme_strerror(gpgsig->status));
_alpm_log(PM_LOG_DEBUG, "timestamp: %lu\n", gpgsig->timestamp);
_alpm_log(PM_LOG_DEBUG, "exp_timestamp: %lu\n", gpgsig->exp_timestamp);