Allow PGP signature to be read from sync database

Add a new field to the package struct to hold PGP information and
instruct db_read to pick it up from the database. It is currently unused
internally but this is the first step.

Due to the fact that we store the PGP sig as binary data, we need to store
both the data and the length so we have a small utility struct to assist us.

Signed-off-by: Dan McGee <dan@archlinux.org>
Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Dan McGee 2008-06-02 15:16:00 -05:00
parent 9f2a3023f8
commit 60159c2e77
3 changed files with 53 additions and 0 deletions

View File

@ -45,6 +45,7 @@ extern "C" {
typedef struct __pmdb_t pmdb_t;
typedef struct __pmpkg_t pmpkg_t;
typedef struct __pmpgpsig_t pmpgpsig_t;
typedef struct __pmdelta_t pmdelta_t;
typedef struct __pmgrp_t pmgrp_t;
typedef struct __pmtrans_t pmtrans_t;
@ -215,6 +216,7 @@ time_t alpm_pkg_get_builddate(pmpkg_t *pkg);
time_t alpm_pkg_get_installdate(pmpkg_t *pkg);
const char *alpm_pkg_get_packager(pmpkg_t *pkg);
const char *alpm_pkg_get_md5sum(pmpkg_t *pkg);
const pmpgpsig_t *alpm_pkg_get_pgpsig(pmpkg_t *pkg);
const char *alpm_pkg_get_arch(pmpkg_t *pkg);
off_t alpm_pkg_get_size(pmpkg_t *pkg);
off_t alpm_pkg_get_isize(pmpkg_t *pkg);

View File

@ -40,6 +40,7 @@
#include "delta.h"
#include "handle.h"
#include "deps.h"
#include "base64.h"
/** \addtogroup alpm_packages Package Functions
* @brief Functions to manipulate libalpm packages
@ -201,6 +202,42 @@ const char SYMEXPORT *alpm_pkg_get_md5sum(pmpkg_t *pkg)
return pkg->ops->get_md5sum(pkg);
}
static int decode_pgpsig(pmpkg_t *pkg) {
int len = strlen(pkg->pgpsig.encdata);
const unsigned char *usline = (const unsigned char*)pkg->pgpsig.encdata;
int destlen = 0;
/* get the necessary size for the buffer by passing 0 */
int ret = base64_decode(NULL, &destlen, usline, len);
/* alloc our memory and repeat the call to decode */
MALLOC(pkg->pgpsig.rawdata, (size_t)destlen, goto error);
ret = base64_decode(pkg->pgpsig.rawdata, &destlen, usline, len);
pkg->pgpsig.rawlen = destlen;
if(ret != 0) {
goto error;
}
FREE(pkg->pgpsig.encdata);
return 0;
error:
FREE(pkg->pgpsig.rawdata);
pkg->pgpsig.rawlen = 0;
return 1;
}
const pmpgpsig_t SYMEXPORT *alpm_pkg_get_pgpsig(pmpkg_t *pkg)
{
ALPM_LOG_FUNC;
/* Sanity checks */
ASSERT(pkg != NULL, RET_ERR(PM_ERR_WRONG_ARGS, NULL));
if(pkg->pgpsig.rawdata == NULL && pkg->pgpsig.encdata != NULL) {
decode_pgpsig(pkg);
}
return &(pkg->pgpsig);
}
const char SYMEXPORT *alpm_pkg_get_arch(pmpkg_t *pkg)
{
return pkg->ops->get_arch(pkg);
@ -463,6 +500,8 @@ void _alpm_pkg_free(pmpkg_t *pkg)
FREE(pkg->url);
FREE(pkg->packager);
FREE(pkg->md5sum);
FREE(pkg->pgpsig.encdata);
FREE(pkg->pgpsig.rawdata);
FREE(pkg->arch);
FREELIST(pkg->licenses);
FREELIST(pkg->replaces);

View File

@ -87,6 +87,16 @@ struct pkg_operations {
*/
extern struct pkg_operations default_pkg_ops;
struct __pmpgpsig_t {
/* we will either store the encoded data or the raw data-
* this way we can decode on an as-needed basis since most
* operations won't require the overhead of base64 decodes
* on all packages in a sync repository. */
char *encdata;
size_t rawlen;
unsigned char *rawdata;
};
struct __pmpkg_t {
unsigned long name_hash;
char *filename;
@ -98,6 +108,8 @@ struct __pmpkg_t {
char *md5sum;
char *arch;
pmpgpsig_t pgpsig;
time_t builddate;
time_t installdate;