2007-01-10 17:11:43 +01:00
|
|
|
// Copyright Daniel Wallin 2006. Use, modification and distribution is
|
|
|
|
// subject to the Boost Software License, Version 1.0. (See accompanying
|
|
|
|
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
|
|
|
|
2017-08-14 00:49:49 +02:00
|
|
|
#include "boost_python.hpp"
|
2013-08-27 18:04:19 +02:00
|
|
|
#include <libtorrent/sha1_hash.hpp>
|
2016-05-23 14:15:39 +02:00
|
|
|
#include <iostream>
|
|
|
|
|
2014-09-13 00:38:07 +02:00
|
|
|
#include "bytes.hpp"
|
|
|
|
|
|
|
|
long get_hash(boost::python::object o)
|
|
|
|
{
|
|
|
|
using namespace boost::python;
|
2016-06-19 01:24:27 +02:00
|
|
|
return long(PyObject_Hash(str(o).ptr()));
|
2014-09-13 00:38:07 +02:00
|
|
|
}
|
|
|
|
|
2017-04-12 20:05:53 +02:00
|
|
|
using namespace lt;
|
2014-09-13 00:38:07 +02:00
|
|
|
|
|
|
|
bytes sha1_hash_bytes(const sha1_hash& bn) {
|
|
|
|
return bytes(bn.to_string());
|
|
|
|
}
|
2007-01-10 17:11:43 +01:00
|
|
|
|
2013-08-27 18:04:19 +02:00
|
|
|
void bind_sha1_hash()
|
2007-01-10 17:11:43 +01:00
|
|
|
{
|
|
|
|
using namespace boost::python;
|
2017-04-12 20:05:53 +02:00
|
|
|
using namespace lt;
|
2007-01-10 17:11:43 +01:00
|
|
|
|
2013-08-27 18:04:19 +02:00
|
|
|
class_<sha1_hash>("sha1_hash")
|
2007-01-10 17:11:43 +01:00
|
|
|
.def(self == self)
|
|
|
|
.def(self != self)
|
|
|
|
.def(self < self)
|
|
|
|
.def(self_ns::str(self))
|
2015-10-09 08:08:12 +02:00
|
|
|
.def(init<std::string>())
|
2013-08-27 18:04:19 +02:00
|
|
|
.def("clear", &sha1_hash::clear)
|
|
|
|
.def("is_all_zeros", &sha1_hash::is_all_zeros)
|
|
|
|
.def("to_string", &sha1_hash::to_string)
|
2014-09-13 00:38:07 +02:00
|
|
|
.def("__hash__", get_hash)
|
|
|
|
.def("to_bytes", sha1_hash_bytes)
|
2007-01-10 17:11:43 +01:00
|
|
|
;
|
2013-08-27 18:04:19 +02:00
|
|
|
|
2016-05-23 14:15:39 +02:00
|
|
|
scope().attr("peer_id") = scope().attr("sha1_hash");
|
2007-01-10 17:11:43 +01:00
|
|
|
}
|
|
|
|
|