summaryrefslogtreecommitdiff
path: root/src/blob.c
diff options
context:
space:
mode:
authorTimo Teras <timo.teras@iki.fi>2009-07-14 19:14:05 +0300
committerTimo Teras <timo.teras@iki.fi>2009-07-14 19:14:05 +0300
commit981bc118f8bdf1df6c23c096a52c890a87ee3e5e (patch)
tree73063efdb73ce4ee3511cc827181ff9c6b28427e /src/blob.c
parente9eaedff5071b94d166973f13df90e47ff4936fe (diff)
downloadapk-tools-981bc118f8bdf1df6c23c096a52c890a87ee3e5e.tar.gz
apk-tools-981bc118f8bdf1df6c23c096a52c890a87ee3e5e.tar.bz2
apk-tools-981bc118f8bdf1df6c23c096a52c890a87ee3e5e.tar.xz
apk-tools-981bc118f8bdf1df6c23c096a52c890a87ee3e5e.zip
db: live with sha1 and md5
this also convers scripts file to a tar archive.
Diffstat (limited to 'src/blob.c')
-rw-r--r--src/blob.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/src/blob.c b/src/blob.c
index 73d39ec..ed7f418 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -186,6 +186,30 @@ void apk_blob_push_uint(apk_blob_t *to, unsigned int value, int radix)
apk_blob_push_blob(to, APK_BLOB_PTR_PTR(ptr+1, &buf[sizeof(buf)-1]));
}
+static int checksum_char_to_id(char chr)
+{
+ switch (chr) {
+ case '1': return APK_CHECKSUM_SHA1;
+ }
+ return APK_CHECKSUM_NONE;
+}
+
+void apk_blob_push_csum(apk_blob_t *to, struct apk_checksum *csum)
+{
+ switch (csum->type) {
+ case APK_CHECKSUM_MD5:
+ apk_blob_push_hexdump(to, APK_BLOB_CSUM(*csum));
+ break;
+ case APK_CHECKSUM_SHA1:
+ apk_blob_push_blob(to, APK_BLOB_STR("X1"));
+ apk_blob_push_hexdump(to, APK_BLOB_CSUM(*csum));
+ break;
+ default:
+ *to = APK_BLOB_NULL;
+ break;
+ }
+}
+
void apk_blob_push_hexdump(apk_blob_t *to, apk_blob_t binary)
{
char *d;
@@ -239,6 +263,31 @@ unsigned int apk_blob_pull_uint(apk_blob_t *b, int radix)
return val;
}
+void apk_blob_pull_csum(apk_blob_t *b, struct apk_checksum *csum)
+{
+ if (unlikely(APK_BLOB_IS_NULL(*b)))
+ return;
+
+ if (unlikely(b->len < 2)) {
+ *b = APK_BLOB_NULL;
+ return;
+ }
+
+ switch (b->ptr[0]) {
+ case 'X':
+ csum->type = checksum_char_to_id(b->ptr[1]);
+ b->ptr += 2;
+ b->len -= 2;
+ apk_blob_pull_hexdump(b, APK_BLOB_CSUM(*csum));
+ break;
+ default:
+ /* Assume MD5 for backwards compatibility */
+ csum->type = APK_CHECKSUM_MD5;
+ apk_blob_pull_hexdump(b, APK_BLOB_CSUM(*csum));
+ break;
+ }
+}
+
void apk_blob_pull_hexdump(apk_blob_t *b, apk_blob_t to)
{
char *s, *d;