From 373495b3a1c8ccdcfece70bac69625b6823ccec0 Mon Sep 17 00:00:00 2001 From: zyp Date: Mon, 8 May 2006 13:42:12 +0000 Subject: [project @ zyp-20060508134212-c2adcf41fc2bca06] [project @ 26] Fixing mess in SVN. --- setup.py | 5 +--- src/hash.cpp | 85 ---------------------------------------------------- src/hash.h | 37 ----------------------- src/hash_wrapper.cpp | 14 --------- 4 files changed, 1 insertion(+), 140 deletions(-) delete mode 100644 src/hash.cpp delete mode 100644 src/hash.h delete mode 100644 src/hash_wrapper.cpp diff --git a/setup.py b/setup.py index cea2803..f43c963 100644 --- a/setup.py +++ b/setup.py @@ -9,7 +9,4 @@ setup( ext_modules=[ Extension('multihash._multihash', ['src/' + x for x in os.listdir('src') if x.endswith('.cpp')], - include_dirs = [], - library_dirs = [], - libraries = ["boost_python", "ssl"], - extra_compile_args = [])]) + libraries = ["boost_python", "ssl"])]) diff --git a/src/hash.cpp b/src/hash.cpp deleted file mode 100644 index d844c46..0000000 --- a/src/hash.cpp +++ /dev/null @@ -1,85 +0,0 @@ -#include "hash.h" -#include "crc32.h" - -#include - -namespace Hex { - static char* digits = "0123456789abcdef"; - std::string hex(char* bin, int length) { - std::string s(length * 2, ' '); - for(int i = 0; i < length; i++) { - s[i*2] = digits[(bin[i] >> 4) & 0xf]; - s[i*2+1] = digits[bin[i] & 0xf]; - } - return s; - } - std::string hex(int bin) { - std::string s(sizeof(int) * 2, ' '); - for(int i = 0; i < sizeof(int) * 2; i++) { - s[sizeof(int) * 2 - 1 - i] = digits[bin & 0xf]; - bin = bin >> 4; - } - return s; - } -} - -Hash::Hash() { - finished = false; - - crc32_ctx = 0; - crc32_str = ""; - - ed2k_str = ""; - - MD5_Init(&md5_ctx); - md5_str = ""; - - SHA1_Init(&sha1_ctx); - sha1_str = ""; -} - -void Hash::update(std::string data) { - if(finished) { - throw std::runtime_error("Can't update after digest."); - } - crc32_ctx = CRC32::crc32(crc32_ctx, data.c_str(), data.length()); - ed2k_ctx.update(data.c_str(), data.length()); - MD5_Update(&md5_ctx, data.c_str(), data.length()); - SHA1_Update(&sha1_ctx, data.c_str(), data.length()); -} - -std::string Hash::crc32() { - return Hex::hex(crc32_ctx); -} - -std::string Hash::ed2k() { - if(!ed2k_str.length()) { - finished = true; - char* digest = ed2k_ctx.digest(); - ed2k_str = Hex::hex(digest, 16); - delete digest; - } - return ed2k_str; -} - -std::string Hash::md5() { - if(!md5_str.length()) { - finished = true; - char* digest = new char[16]; - MD5_Final((unsigned char*)digest, &md5_ctx); - md5_str = Hex::hex(digest, 16); - delete digest; - } - return md5_str; -} - -std::string Hash::sha1() { - if(!sha1_str.length()) { - finished = true; - char* digest = new char[20]; - SHA1_Final((unsigned char*)digest, &sha1_ctx); - sha1_str = Hex::hex(digest, 20); - delete digest; - } - return sha1_str; -} diff --git a/src/hash.h b/src/hash.h deleted file mode 100644 index 3c7b9c9..0000000 --- a/src/hash.h +++ /dev/null @@ -1,37 +0,0 @@ -#ifndef _HASH_H_ -#define _HASH_H_ - -#include - -#include "ed2k.h" - -#include -#include -#include - -class Hash { - private: - bool finished; - - int crc32_ctx; - std::string crc32_str; - - Ed2k ed2k_ctx; - std::string ed2k_str; - - MD5_CTX md5_ctx; - std::string md5_str; - - SHA_CTX sha1_ctx; - std::string sha1_str; - - public: - Hash(); - void update(std::string data); - std::string crc32(); - std::string ed2k(); - std::string md5(); - std::string sha1(); -}; - -#endif // _HASH_H_ diff --git a/src/hash_wrapper.cpp b/src/hash_wrapper.cpp deleted file mode 100644 index a4173b9..0000000 --- a/src/hash_wrapper.cpp +++ /dev/null @@ -1,14 +0,0 @@ -#include "hash.h" - -#include -using namespace boost::python; - -BOOST_PYTHON_MODULE(_hash) -{ - class_("Hash") - .def("update", &Hash::update) - .def("crc32", &Hash::crc32) - .def("ed2k", &Hash::ed2k) - .def("md5", &Hash::md5) - .def("sha1", &Hash::sha1); -} -- cgit v1.2.3