summaryrefslogtreecommitdiff
path: root/lib/libalpm/util.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-08-11 20:16:42 -0500
committerDan McGee <dan@archlinux.org>2011-08-15 12:13:35 -0500
commitbd5ec9cd8e23bba4334a7b3a5a73843c3667c085 (patch)
tree76e6018d88a861a5cc16729d8274b3ceab7e3ccb /lib/libalpm/util.c
parentf37c5016572fecb16cc53d5e3fdd059944e36359 (diff)
downloadpacman-bd5ec9cd8e23bba4334a7b3a5a73843c3667c085.tar.xz
Validate the sha256sum if available
Adjust load_internal() to check the sha256sum value if we have it. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/util.c')
-rw-r--r--lib/libalpm/util.c45
1 files changed, 26 insertions, 19 deletions
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index d0661289..4dc0fbe7 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -829,25 +829,6 @@ char SYMEXPORT *alpm_compute_md5sum(const char *filename)
return md5sum;
}
-int _alpm_test_md5sum(const char *filepath, const char *md5sum)
-{
- char *md5sum2;
- int ret;
-
- md5sum2 = alpm_compute_md5sum(filepath);
-
- if(md5sum == NULL || md5sum2 == NULL) {
- ret = -1;
- } else if(strcmp(md5sum, md5sum2) != 0) {
- ret = 1;
- } else {
- ret = 0;
- }
-
- FREE(md5sum2);
- return ret;
-}
-
/** Get the sha256 sum of file.
* @param filename name of the file
* @return the checksum on success, NULL on error
@@ -879,6 +860,32 @@ char SYMEXPORT *alpm_compute_sha256sum(const char *filename)
return sha256sum;
}
+int _alpm_test_checksum(const char *filepath, const char *expected,
+ enum _alpm_csum type)
+{
+ char *computed;
+ int ret;
+
+ if(type == ALPM_CSUM_MD5) {
+ computed = alpm_compute_md5sum(filepath);
+ } else if(type == ALPM_CSUM_SHA256) {
+ computed = alpm_compute_sha256sum(filepath);
+ } else {
+ return -1;
+ }
+
+ if(expected == NULL || computed == NULL) {
+ ret = -1;
+ } else if(strcmp(expected, computed) != 0) {
+ ret = 1;
+ } else {
+ ret = 0;
+ }
+
+ FREE(computed);
+ return ret;
+}
+
/* Note: does NOT handle sparse files on purpose for speed. */
int _alpm_archive_fgets(struct archive *a, struct archive_read_buffer *b)
{