summaryrefslogtreecommitdiffstats
path: root/src/apk_blob.h
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/apk_blob.h
parente9eaedff5071b94d166973f13df90e47ff4936fe (diff)
downloadapk-tools-981bc118f8bdf1df6c23c096a52c890a87ee3e5e.tar.bz2
apk-tools-981bc118f8bdf1df6c23c096a52c890a87ee3e5e.tar.xz
db: live with sha1 and md5
this also convers scripts file to a tar archive.
Diffstat (limited to 'src/apk_blob.h')
-rw-r--r--src/apk_blob.h44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/apk_blob.h b/src/apk_blob.h
index 9ad79c4..170cf20 100644
--- a/src/apk_blob.h
+++ b/src/apk_blob.h
@@ -13,6 +13,8 @@
#define APK_BLOB_H
#include <string.h>
+#include <openssl/evp.h>
+
#include "apk_defines.h"
struct apk_blob {
@@ -22,10 +24,38 @@ struct apk_blob {
typedef struct apk_blob apk_blob_t;
typedef int (*apk_blob_cb)(void *ctx, apk_blob_t blob);
+#define APK_CHECKSUM_NONE 0
+#define APK_CHECKSUM_MD5 16
+#define APK_CHECKSUM_SHA1 20
+
+/* Internal cointainer for MD5 or SHA1 */
+struct apk_checksum {
+ unsigned char data[20];
+ unsigned char type;
+};
+
+static inline const EVP_MD *apk_default_checksum(void)
+{
+ return EVP_sha1();
+}
+
+static inline const EVP_MD *apk_get_digest(int type)
+{
+ switch (type) {
+ case APK_CHECKSUM_MD5:
+ return EVP_md5();
+ case APK_CHECKSUM_SHA1:
+ return EVP_sha1();
+ }
+ return EVP_md_null();
+}
+
#define APK_BLOB_IS_NULL(blob) ((blob).ptr == NULL)
#define APK_BLOB_NULL ((apk_blob_t){0, NULL})
#define APK_BLOB_BUF(buf) ((apk_blob_t){sizeof(buf), (char *)(buf)})
+#define APK_BLOB_CSUM(csum) ((apk_blob_t){(csum).type, (char *)(csum).data})
+#define APK_BLOB_STRUCT(s) ((apk_blob_t){sizeof(s), (char*)&(s)})
#define APK_BLOB_PTR_LEN(beg,len) ((apk_blob_t){(len), (beg)})
#define APK_BLOB_PTR_PTR(beg,end) APK_BLOB_PTR_LEN((beg),(end)-(beg)+1)
@@ -47,12 +77,26 @@ int apk_blob_compare(apk_blob_t a, apk_blob_t b);
int apk_blob_for_each_segment(apk_blob_t blob, const char *split,
apk_blob_cb cb, void *ctx);
+static inline void apk_blob_checksum(apk_blob_t b, const EVP_MD *md, struct apk_checksum *csum)
+{
+ csum->type = EVP_MD_size(md);
+ EVP_Digest(b.ptr, b.len, csum->data, NULL, md, NULL);
+}
+static inline const int apk_checksum_compare(const struct apk_checksum *a,
+ const struct apk_checksum *b)
+{
+ return apk_blob_compare(APK_BLOB_PTR_LEN((char *) a->data, a->type),
+ APK_BLOB_PTR_LEN((char *) b->data, b->type));
+}
+
void apk_blob_push_blob(apk_blob_t *to, apk_blob_t literal);
void apk_blob_push_uint(apk_blob_t *to, unsigned int value, int radix);
+void apk_blob_push_csum(apk_blob_t *to, struct apk_checksum *csum);
void apk_blob_push_hexdump(apk_blob_t *to, apk_blob_t binary);
void apk_blob_pull_char(apk_blob_t *b, int expected);
unsigned int apk_blob_pull_uint(apk_blob_t *b, int radix);
+void apk_blob_pull_csum(apk_blob_t *b, struct apk_checksum *csum);
void apk_blob_pull_hexdump(apk_blob_t *b, apk_blob_t to);
#endif