summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Vogt <michael.vogt@ubuntu.com>2008-07-04 20:15:25 +0200
committerMichael Vogt <michael.vogt@ubuntu.com>2008-07-04 20:15:25 +0200
commit798980a40020e6571a284ae4c5336e3d210cb7fb (patch)
treeff60318a6f9250ba3feeb2ca08b244ada1711314
parentb6d95a31a6b8eb7f5d22eb040e7847b18f74cbf9 (diff)
parent7625577a6974aa580877cf5d5ed22a6e663843fb (diff)
downloadpython-apt-798980a40020e6571a284ae4c5336e3d210cb7fb.tar.gz
merged from mvo
-rw-r--r--debian/changelog11
-rw-r--r--po/python-apt.pot2
-rw-r--r--python/apt_pkgmodule.cc15
-rw-r--r--tests/test_hashsums.py64
4 files changed, 88 insertions, 4 deletions
diff --git a/debian/changelog b/debian/changelog
index c9feb515..36a168ad 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,14 @@
+python-apt (0.7.6ubuntu2) intrepid; urgency=low
+
+ * python/apt_pkgmodule.cc:
+ - fix bug in hashsum calculation when the original string
+ contains \0 charackters (thanks to Celso Providelo and
+ Ryan Hass for the test-case) LP: #243630
+ * tests/test_hashsums.py:
+ - add tests for the hashsum code
+
+ -- Michael Vogt <mvo@debian.org> Fri, 04 Jul 2008 19:53:28 +0200
+
python-apt (0.7.6ubuntu1) intrepid; urgency=low
* merged with debian, remaining changes:
diff --git a/po/python-apt.pot b/po/python-apt.pot
index ef031aea..c8c93668 100644
--- a/po/python-apt.pot
+++ b/po/python-apt.pot
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2008-07-04 11:12+0200\n"
+"POT-Creation-Date: 2008-07-04 20:08+0200\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc
index ae1cf7be..fd7a83cd 100644
--- a/python/apt_pkgmodule.cc
+++ b/python/apt_pkgmodule.cc
@@ -175,8 +175,11 @@ static PyObject *md5sum(PyObject *Self,PyObject *Args)
// Digest of a string.
if (PyString_Check(Obj) != 0)
{
+ char *s;
+ Py_ssize_t len;
MD5Summation Sum;
- Sum.Add(PyString_AsString(Obj));
+ PyString_AsStringAndSize(Obj, &s, &len);
+ Sum.Add((const unsigned char*)s, len);
return CppPyString(Sum.Result().Value());
}
@@ -212,8 +215,11 @@ static PyObject *sha1sum(PyObject *Self,PyObject *Args)
// Digest of a string.
if (PyString_Check(Obj) != 0)
{
+ char *s;
+ Py_ssize_t len;
SHA1Summation Sum;
- Sum.Add(PyString_AsString(Obj));
+ PyString_AsStringAndSize(Obj, &s, &len);
+ Sum.Add((const unsigned char*)s, len);
return CppPyString(Sum.Result().Value());
}
@@ -249,8 +255,11 @@ static PyObject *sha256sum(PyObject *Self,PyObject *Args)
// Digest of a string.
if (PyString_Check(Obj) != 0)
{
+ char *s;
+ Py_ssize_t len;
SHA256Summation Sum;
- Sum.Add(PyString_AsString(Obj));
+ PyString_AsStringAndSize(Obj, &s, &len);
+ Sum.Add((const unsigned char*)s, len);
return CppPyString(Sum.Result().Value());
}
diff --git a/tests/test_hashsums.py b/tests/test_hashsums.py
new file mode 100644
index 00000000..7fa6eb60
--- /dev/null
+++ b/tests/test_hashsums.py
@@ -0,0 +1,64 @@
+#!/usr/bin/python
+
+import unittest
+import apt_pkg
+
+class testHashes(unittest.TestCase):
+ " test the hashsum functions against strings and files "
+
+ def testMD5(self):
+ # simple
+ s = "foo"
+ s_md5 = "acbd18db4cc2f85cedef654fccc4a4d8"
+ res = apt_pkg.md5sum(s)
+ self.assert_(res == s_md5)
+ # file
+ res = apt_pkg.md5sum(open("hashsum_test.data"))
+ self.assert_(res == s_md5)
+ # with zero (\0) in the string
+ s = "foo\0bar"
+ s_md5 = "f6f5f8cd0cb63668898ba29025ae824e"
+ res = apt_pkg.md5sum(s)
+ self.assert_(res == s_md5)
+ # file
+ res = apt_pkg.md5sum(open("hashsum_test_with_zero.data"))
+ self.assert_(res == s_md5)
+
+ def testSHA1(self):
+ # simple
+ s = "foo"
+ s_hash = "0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"
+ res = apt_pkg.sha1sum(s)
+ self.assert_(res == s_hash)
+ # file
+ res = apt_pkg.sha1sum(open("hashsum_test.data"))
+ self.assert_(res == s_hash)
+ # with zero (\0) in the string
+ s = "foo\0bar"
+ s_hash = "e2c300a39311a2dfcaff799528415cb74c19317f"
+ res = apt_pkg.sha1sum(s)
+ self.assert_(res == s_hash)
+ # file
+ res = apt_pkg.sha1sum(open("hashsum_test_with_zero.data"))
+ self.assert_(res == s_hash)
+
+ def testSHA256(self):
+ # simple
+ s = "foo"
+ s_hash = "2c26b46b68ffc68ff99b453c1d30413413422d706483bfa0f98a5e886266e7ae"
+ res = apt_pkg.sha256sum(s)
+ self.assert_(res == s_hash)
+ # file
+ res = apt_pkg.sha256sum(open("hashsum_test.data"))
+ self.assert_(res == s_hash)
+ # with zero (\0) in the string
+ s = "foo\0bar"
+ s_hash = "d6b681bfce7155d44721afb79c296ef4f0fa80a9dd6b43c5cf74dd0f64c85512"
+ res = apt_pkg.sha256sum(s)
+ self.assert_(res == s_hash)
+ # file
+ res = apt_pkg.sha256sum(open("hashsum_test_with_zero.data"))
+ self.assert_(res == s_hash)
+
+if __name__ == "__main__":
+ unittest.main()