Load and allow access to sha256sum

This adds a field in the package struct for this checksum type as well
as allowing access via the API to it. The frontend is now able to
display any read value. Note that this does not implement any use or
verification of the value internally.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-08-11 20:15:15 -05:00
parent 31f2e0cba3
commit ebb2e36cc4
7 changed files with 31 additions and 4 deletions

2
README
View File

@ -429,7 +429,7 @@ API CHANGES BETWEEN 3.5 AND 4.0
alpm_option_get_default_siglevel(), alpm_option_set_default_siglevel(),
alpm_option_get_gpgdir(), alpm_option_set_gpgdir(), alpm_db_get_siglevel(),
alpm_sigresult_cleanup(), alpm_db_check_pgp_signature(), alpm_pkg_check_pgp_signature(),
alpm_pkg_get_base64_sig()
alpm_pkg_get_sha256sum(), alpm_pkg_get_base64_sig()
- list functions:
alpm_list_to_array(), alpm_list_previous()
- structs:

View File

@ -609,12 +609,19 @@ time_t alpm_pkg_get_installdate(alpm_pkg_t *pkg);
const char *alpm_pkg_get_packager(alpm_pkg_t *pkg);
/** Returns the package's MD5 checksum as a string.
* The returned string is a sequence of lowercase hexadecimal digits.
* The returned string is a sequence of 32 lowercase hexadecimal digits.
* @param pkg a pointer to package
* @return a reference to an internal string
*/
const char *alpm_pkg_get_md5sum(alpm_pkg_t *pkg);
/** Returns the package's SHA256 checksum as a string.
* The returned string is a sequence of 64 lowercase hexadecimal digits.
* @param pkg a pointer to package
* @return a reference to an internal string
*/
const char *alpm_pkg_get_sha256sum(alpm_pkg_t *pkg);
/** Returns the architecture for which the package was built.
* @param pkg a pointer to package
* @return a reference to an internal string

View File

@ -99,6 +99,12 @@ static const char *_cache_get_md5sum(alpm_pkg_t *pkg)
return pkg->md5sum;
}
static const char *_cache_get_sha256sum(alpm_pkg_t *pkg)
{
LAZY_LOAD(INFRQ_DESC, NULL);
return pkg->sha256sum;
}
static const char *_cache_get_arch(alpm_pkg_t *pkg)
{
LAZY_LOAD(INFRQ_DESC, NULL);
@ -251,6 +257,7 @@ static struct pkg_operations local_pkg_ops = {
.get_installdate = _cache_get_installdate,
.get_packager = _cache_get_packager,
.get_md5sum = _cache_get_md5sum,
.get_sha256sum = _cache_get_sha256sum,
.get_arch = _cache_get_arch,
.get_size = _cache_get_size,
.get_isize = _cache_get_isize,

View File

@ -543,8 +543,7 @@ static int sync_db_read(alpm_db_t *db, struct archive *archive,
} else if(strcmp(line, "%MD5SUM%") == 0) {
READ_AND_STORE(pkg->md5sum);
} else if(strcmp(line, "%SHA256SUM%") == 0) {
/* we don't do anything with this value right now */
READ_NEXT();
READ_AND_STORE(pkg->sha256sum);
} else if(strcmp(line, "%PGPSIG%") == 0) {
READ_AND_STORE(pkg->base64_sig);
} else if(strcmp(line, "%REPLACES%") == 0) {

View File

@ -92,6 +92,7 @@ static time_t _pkg_get_builddate(alpm_pkg_t *pkg) { return pkg->builddate
static time_t _pkg_get_installdate(alpm_pkg_t *pkg) { return pkg->installdate; }
static const char *_pkg_get_packager(alpm_pkg_t *pkg) { return pkg->packager; }
static const char *_pkg_get_md5sum(alpm_pkg_t *pkg) { return pkg->md5sum; }
static const char *_pkg_get_sha256sum(alpm_pkg_t *pkg) { return pkg->sha256sum; }
static const char *_pkg_get_arch(alpm_pkg_t *pkg) { return pkg->arch; }
static off_t _pkg_get_size(alpm_pkg_t *pkg) { return pkg->size; }
static off_t _pkg_get_isize(alpm_pkg_t *pkg) { return pkg->isize; }
@ -139,6 +140,7 @@ struct pkg_operations default_pkg_ops = {
.get_installdate = _pkg_get_installdate,
.get_packager = _pkg_get_packager,
.get_md5sum = _pkg_get_md5sum,
.get_sha256sum = _pkg_get_sha256sum,
.get_arch = _pkg_get_arch,
.get_size = _pkg_get_size,
.get_isize = _pkg_get_isize,
@ -229,6 +231,13 @@ const char SYMEXPORT *alpm_pkg_get_md5sum(alpm_pkg_t *pkg)
return pkg->ops->get_md5sum(pkg);
}
const char SYMEXPORT *alpm_pkg_get_sha256sum(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
pkg->handle->pm_errno = 0;
return pkg->ops->get_sha256sum(pkg);
}
const char SYMEXPORT *alpm_pkg_get_base64_sig(alpm_pkg_t *pkg)
{
ASSERT(pkg != NULL, return NULL);
@ -483,6 +492,7 @@ alpm_pkg_t *_alpm_pkg_dup(alpm_pkg_t *pkg)
newpkg->installdate = pkg->installdate;
STRDUP(newpkg->packager, pkg->packager, goto cleanup);
STRDUP(newpkg->md5sum, pkg->md5sum, goto cleanup);
STRDUP(newpkg->sha256sum, pkg->md5sum, goto cleanup);
STRDUP(newpkg->arch, pkg->arch, goto cleanup);
newpkg->size = pkg->size;
newpkg->isize = pkg->isize;
@ -548,6 +558,7 @@ void _alpm_pkg_free(alpm_pkg_t *pkg)
FREE(pkg->url);
FREE(pkg->packager);
FREE(pkg->md5sum);
FREE(pkg->sha256sum);
FREE(pkg->base64_sig);
FREE(pkg->arch);
FREELIST(pkg->licenses);

View File

@ -55,6 +55,7 @@ struct pkg_operations {
time_t (*get_installdate) (alpm_pkg_t *);
const char *(*get_packager) (alpm_pkg_t *);
const char *(*get_md5sum) (alpm_pkg_t *);
const char *(*get_sha256sum) (alpm_pkg_t *);
const char *(*get_arch) (alpm_pkg_t *);
off_t (*get_size) (alpm_pkg_t *);
off_t (*get_isize) (alpm_pkg_t *);
@ -100,6 +101,7 @@ struct __alpm_pkg_t {
char *url;
char *packager;
char *md5sum;
char *sha256sum;
char *base64_sig;
char *arch;

View File

@ -135,6 +135,7 @@ void dump_pkg_full(alpm_pkg_t *pkg, enum pkg_from from, int extra)
if(from == PKG_FROM_SYNCDB) {
string_display(_("MD5 Sum :"), alpm_pkg_get_md5sum(pkg));
string_display(_("SHA256 Sum :"), alpm_pkg_get_sha256sum(pkg));
string_display(_("Signatures :"), alpm_pkg_get_base64_sig(pkg) ? _("Yes") : _("No"));
}
if(from == PKG_FROM_FILE) {