The following commit has been merged in the master branch:
commit 78c3744c84ad7e494eae291432c55963f8f1ed81
Author: Guillem Jover <[email protected]>
Date: Fri Sep 25 00:20:19 2009 +0200
libdpkg: Add new buffer_hash and buffer_md5 functions
diff --git a/lib/dpkg/buffer.c b/lib/dpkg/buffer.c
index e201e66..d2a4f09 100644
--- a/lib/dpkg/buffer.c
+++ b/lib/dpkg/buffer.c
@@ -196,6 +196,19 @@ buffer_copy_TYPE(PtrInt, void *, ptr, int, i);
buffer_copy_TYPE(PtrPtr, void *, ptr, void *, ptr);
off_t
+buffer_hash(const void *input, void *output, int type, off_t limit)
+{
+ struct buffer_data data = { output, type };
+ off_t ret;
+
+ buffer_init(NULL, &data);
+ ret = buffer_write(&data, input, limit, NULL);
+ buffer_done(NULL, &data);
+
+ return ret;
+}
+
+off_t
buffer_copy(buffer_data_t read_data, buffer_data_t write_data,
off_t limit, const char *desc)
{
diff --git a/lib/dpkg/buffer.h b/lib/dpkg/buffer.h
index 0830c7d..db19f42 100644
--- a/lib/dpkg/buffer.h
+++ b/lib/dpkg/buffer.h
@@ -51,6 +51,9 @@ struct buffer_data {
int type;
};
+# define buffer_md5(buf, hash, limit) \
+ buffer_hash(buf, hash, BUFFER_WRITE_MD5, limit)
+
#if HAVE_C99
# define fd_md5(fd, hash, limit, ...) \
buffer_copy_IntPtr(fd, BUFFER_READ_FD, hash, BUFFER_WRITE_MD5, \
@@ -135,6 +138,7 @@ off_t buffer_copy_IntPtr(int i, int typeIn, void *p, int
typeOut,
off_t buffer_copy_IntInt(int i1, int typeIn, int i2, int typeOut,
off_t limit, const char *desc,
...) DPKG_ATTR_PRINTF(6);
+off_t buffer_hash(const void *buf, void *hash, int typeOut, off_t length);
off_t buffer_write(buffer_data_t data, const void *buf,
off_t length, const char *desc);
diff --git a/lib/dpkg/test/.gitignore b/lib/dpkg/test/.gitignore
index 70ee418..605314e 100644
--- a/lib/dpkg/test/.gitignore
+++ b/lib/dpkg/test/.gitignore
@@ -1,3 +1,4 @@
+t-buffer
t-macros
t-path
t-pkginfo
diff --git a/lib/dpkg/test/Makefile.am b/lib/dpkg/test/Makefile.am
index a65cc76..9400267 100644
--- a/lib/dpkg/test/Makefile.am
+++ b/lib/dpkg/test/Makefile.am
@@ -11,6 +11,7 @@ check_PROGRAMS = \
t-test \
t-macros \
t-string \
+ t-buffer \
t-path \
t-varbuf \
t-version \
@@ -22,6 +23,7 @@ t_macros_LDADD = $(CHECK_LDADD)
t_path_LDADD = $(CHECK_LDADD)
t_pkginfo_LDADD = $(CHECK_LDADD)
t_string_LDADD = $(CHECK_LDADD)
+t_buffer_LDADD = $(CHECK_LDADD)
t_test_LDADD = $(CHECK_LDADD)
t_varbuf_LDADD = $(CHECK_LDADD)
t_version_LDADD = $(CHECK_LDADD)
diff --git a/lib/dpkg/test/t-pkginfo.c b/lib/dpkg/test/t-buffer.c
similarity index 65%
copy from lib/dpkg/test/t-pkginfo.c
copy to lib/dpkg/test/t-buffer.c
index 0a8aeb6..00bd7f0 100644
--- a/lib/dpkg/test/t-pkginfo.c
+++ b/lib/dpkg/test/t-buffer.c
@@ -1,6 +1,6 @@
/*
* libdpkg - Debian packaging suite library routines
- * t-pkginfo.c - test pkginfo handling
+ * t-buffer.c - test buffer handling
*
* Copyright © 2009 Guillem Jover <[email protected]>
*
@@ -20,25 +20,27 @@
*/
#include <dpkg/test.h>
-#include <dpkg/dpkg-db.h>
+#include <dpkg/buffer.h>
+
+#include <stdio.h>
static void
-test_pkginfo_informative(void)
+test_buffer_hash(void)
{
- struct pkginfo pkg;
+ const char str_test[] = "this is a test string\n";
+ const char str_empty[] = "";
+ char hash[MD5HASHLEN + 1];
- blankpackage(&pkg);
- pkg.want = want_purge;
- test_pass(informative(&pkg, &pkg.installed));
+ buffer_md5(str_empty, hash, strlen(str_empty));
+ test_str(hash, ==, "d41d8cd98f00b204e9800998ecf8427e");
- /* FIXME: Complete. */
+ buffer_md5(str_test, hash, strlen(str_test));
+ test_str(hash, ==, "475aae3b885d70a9130eec23ab33f2b9");
}
static void
test(void)
{
- test_pkginfo_informative();
-
- /* FIXME: Complete. */
+ test_buffer_hash();
}
--
dpkg's main repository
--
To UNSUBSCRIBE, email to [email protected]
with a subject of "unsubscribe". Trouble? Contact [email protected]