From e7fde76bef8ba317cd6cc681c21c27d4aad13199 Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 26 Jul 2006 18:46:03 +0200 Subject: * support sha256 as well --- python/apt_pkgmodule.cc | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'python') diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index e73628c3..01e9c200 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -232,6 +233,43 @@ static PyObject *sha1sum(PyObject *Self,PyObject *Args) return CppPyString(Sum.Result().Value()); } + PyErr_SetString(PyExc_TypeError,"Only understand strings and files"); + return 0; +} + /*}}}*/ +// sha256sum - Compute the sha1sum of a file or string /*{{{*/ +// --------------------------------------------------------------------- +static char *doc_sha256sum = "sha256sum(String) -> String or sha256sum(File) -> String"; +static PyObject *sha256sum(PyObject *Self,PyObject *Args) +{ + PyObject *Obj; + if (PyArg_ParseTuple(Args,"O",&Obj) == 0) + return 0; + + // Digest of a string. + if (PyString_Check(Obj) != 0) + { + SHA256Summation Sum; + Sum.Add(PyString_AsString(Obj)); + return CppPyString(Sum.Result().Value()); + } + + // Digest of a file + if (PyFile_Check(Obj) != 0) + { + SHA256Summation Sum; + int Fd = fileno(PyFile_AsFile(Obj)); + struct stat St; + if (fstat(Fd,&St) != 0 || + Sum.AddFD(Fd,St.st_size) == false) + { + PyErr_SetFromErrno(PyExc_SystemError); + return 0; + } + + return CppPyString(Sum.Result().Value()); + } + PyErr_SetString(PyExc_TypeError,"Only understand strings and files"); return 0; } @@ -370,6 +408,7 @@ static PyMethodDef methods[] = // Stuff {"md5sum",md5sum,METH_VARARGS,doc_md5sum}, {"sha1sum",sha1sum,METH_VARARGS,doc_sha1sum}, + {"sha256sum",sha1sum,METH_VARARGS,doc_sha256sum}, // Strings {"CheckDomainList",StrCheckDomainList,METH_VARARGS,"CheckDomainList(String,String) -> Bool"}, -- cgit v1.2.3 From 8d79b99c1a3338e31e8def858cee3209824ae8bf Mon Sep 17 00:00:00 2001 From: Michael Vogt Date: Wed, 26 Jul 2006 18:59:40 +0200 Subject: * #cough# - actually use sha256 --- debian/changelog | 2 +- python/apt_pkgmodule.cc | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'python') diff --git a/debian/changelog b/debian/changelog index ba6c47f6..783e510f 100644 --- a/debian/changelog +++ b/debian/changelog @@ -13,7 +13,7 @@ python-apt (0.6.19) unstable; urgency=low - allow change of rootdir for APT database loading - add dh_installexamples in package building Closes: #376014 - -- + -- Michael Vogt Wed, 26 Jul 2006 18:51:56 +0200 python-apt (0.6.18-0.2) unstable; urgency=low diff --git a/python/apt_pkgmodule.cc b/python/apt_pkgmodule.cc index 01e9c200..b1c5c2a5 100644 --- a/python/apt_pkgmodule.cc +++ b/python/apt_pkgmodule.cc @@ -408,7 +408,7 @@ static PyMethodDef methods[] = // Stuff {"md5sum",md5sum,METH_VARARGS,doc_md5sum}, {"sha1sum",sha1sum,METH_VARARGS,doc_sha1sum}, - {"sha256sum",sha1sum,METH_VARARGS,doc_sha256sum}, + {"sha256sum",sha256sum,METH_VARARGS,doc_sha256sum}, // Strings {"CheckDomainList",StrCheckDomainList,METH_VARARGS,"CheckDomainList(String,String) -> Bool"}, -- cgit v1.2.3