char *checksum_bin2hex(const char *src, size_t len)
{
- char *p;
- static char buf[65];
+ unsigned char *p;
+ static unsigned char buf[65];
+ const unsigned char *s = (unsigned char *)src;
static const unsigned char bin2hex[16] = {
'0', '1', '2', '3',
'4', '5', '6', '7',
if (len > 32)
return NULL;
- for (p = buf; len > 0; src++, len--) {
- *p++ = bin2hex[*src / 16];
- *p++ = bin2hex[*src % 16];
+ for (p = buf; len > 0; s++, len--) {
+ *p++ = bin2hex[*s / 16];
+ *p++ = bin2hex[*s % 16];
}
*p = 0;
- return buf;
+ return (char *)buf;
}
char *checksum_hex2bin(const char *src, size_t *len)
{
- char *p;
size_t slen;
- static char buf[32];
+ unsigned char *p;
+ const unsigned char *s = (unsigned char *)src;
+ static unsigned char buf[32];
while (isspace(*src))
src++;
(c >= 'a' ? (c - 'a') : (c >= 'A' ? (c - 'A') : (c - '0')))
for (p = buf, *len = 0;
- slen > 0 && isxdigit(src[0]) && isxdigit(src[1]);
- slen--, src += 2, (*len)++)
- *p++ = hex(src[0]) * 16 + hex(src[1]);
+ slen > 0 && isxdigit(s[0]) && isxdigit(s[1]);
+ slen--, s += 2, (*len)++)
+ *p++ = hex(s[0]) * 16 + hex(s[1]);
- return buf;
+ return (char *)buf;
}
int rm_r(const char *path)
#ifdef HAVE_MD5
/* Check for md5 values */
- pkg_md5 = pkg_get_string(pkg, PKG_MD5SUM);
+ pkg_md5 = pkg_get_md5(pkg);
if (pkg_md5) {
file_md5 = file_md5sum_alloc(local_filename);
if (file_md5 && strcmp(file_md5, pkg_md5)) {
#ifdef HAVE_SHA256
/* Check for sha256 value */
- pkg_sha256 = pkg_get_string(pkg, PKG_SHA256SUM);
+ pkg_sha256 = pkg_get_sha256(pkg);
if (pkg_sha256) {
file_sha256 = file_sha256sum_alloc(local_filename);
if (file_sha256 && strcmp(file_sha256, pkg_sha256)) {
return 0;
}
+char *pkg_get_md5(const pkg_t *pkg)
+{
+ char *p = pkg_get_raw(pkg, PKG_MD5SUM);
+
+ if (!p)
+ return NULL;
+
+ return checksum_bin2hex(p, 16);
+}
+
+char *pkg_set_md5(pkg_t *pkg, const char *cksum)
+{
+ size_t len;
+ char *p = checksum_hex2bin(cksum, &len);
+
+ if (!p || len != 16)
+ return NULL;
+
+ return pkg_set_raw(pkg, PKG_MD5SUM, p, len);
+}
+
+char *pkg_get_sha256(const pkg_t *pkg)
+{
+ char *p = pkg_get_raw(pkg, PKG_SHA256SUM);
+
+ if (!p)
+ return NULL;
+
+ return checksum_bin2hex(p, 32);
+}
+
+char *pkg_set_sha256(pkg_t *pkg, const char *cksum)
+{
+ size_t len;
+ char *p = checksum_hex2bin(cksum, &len);
+
+ if (!p || len != 32)
+ return NULL;
+
+ return pkg_set_raw(pkg, PKG_SHA256SUM, p, len);
+}
+
static void compound_depend_deinit(compound_depend_t * depends)
{
pkg_set_string(oldpkg, PKG_LOCAL_FILENAME, pkg_get_string(newpkg, PKG_LOCAL_FILENAME));
if (!pkg_get_string(oldpkg, PKG_TMP_UNPACK_DIR))
pkg_set_string(oldpkg, PKG_TMP_UNPACK_DIR, pkg_get_string(newpkg, PKG_TMP_UNPACK_DIR));
- if (!pkg_get_string(oldpkg, PKG_MD5SUM))
- pkg_set_string(oldpkg, PKG_MD5SUM, pkg_get_string(newpkg, PKG_MD5SUM));
- if (!pkg_get_string(oldpkg, PKG_SHA256SUM))
- pkg_set_string(oldpkg, PKG_SHA256SUM, pkg_get_string(newpkg, PKG_SHA256SUM));
+ if (!pkg_get_md5(oldpkg))
+ pkg_set_md5(oldpkg, pkg_get_md5(newpkg));
+ if (!pkg_get_sha256(oldpkg))
+ pkg_set_sha256(oldpkg, pkg_get_sha256(newpkg));
if (!pkg_get_int(oldpkg, PKG_SIZE))
pkg_set_int(oldpkg, PKG_SIZE, pkg_get_int(newpkg, PKG_SIZE));
if (!pkg_get_int(oldpkg, PKG_INSTALLED_SIZE))
fprintf(fp, "Maintainer: %s\n", p);
}
} else if (strcasecmp(field, "MD5sum") == 0) {
- p = pkg_get_string(pkg, PKG_MD5SUM);
+ p = pkg_get_md5(pkg);
if (p) {
fprintf(fp, "MD5Sum: %s\n", p);
}
char *pkg_get_architecture(const pkg_t *pkg);
int pkg_get_arch_priority(const pkg_t *pkg);
+char *pkg_get_md5(const pkg_t *pkg);
+char *pkg_set_md5(pkg_t *pkg, const char *cksum);
+
+char *pkg_get_sha256(const pkg_t *pkg);
+char *pkg_set_sha256(pkg_t *pkg, const char *cksum);
abstract_pkg_t *abstract_pkg_new(void);
break;
case 'M':
- if ((mask & PFM_MD5SUM) && (is_field("MD5sum:", line) || is_field("MD5Sum:", line))) {
- size_t len;
- char *cksum = checksum_hex2bin(line + strlen("MD5sum") + 1, &len);
- if (cksum && len == 16)
- pkg_set_raw(pkg, PKG_MD5SUM, cksum, len);
- }
+ if ((mask & PFM_MD5SUM) && (is_field("MD5sum:", line) || is_field("MD5Sum:", line)))
+ pkg_set_md5(pkg, line + strlen("MD5sum") + 1);
else if ((mask & PFM_MAINTAINER)
&& is_field("Maintainer", line))
pkg_set_string(pkg, PKG_MAINTAINER, line + strlen("Maintainer") + 1);
if ((mask & PFM_SECTION) && is_field("Section", line))
pkg_set_string(pkg, PKG_SECTION, line + strlen("Section") + 1);
#ifdef HAVE_SHA256
- else if ((mask & PFM_SHA256SUM) && is_field("SHA256sum", line)) {
- size_t len;
- char *cksum = checksum_hex2bin(line + strlen("SHA256sum") + 1, &len);
- if (cksum && len == 32)
- pkg_set_raw(pkg, PKG_SHA256SUM, cksum, len);
- }
+ else if ((mask & PFM_SHA256SUM) && is_field("SHA256sum", line))
+ pkg_set_sha256(pkg, line + strlen("SHA256sum") + 1);
#endif
else if ((mask & PFM_SIZE) && is_field("Size", line)) {
pkg_set_int(pkg, PKG_SIZE, strtoul(line + strlen("Size") + 1, NULL, 0));