aboutsummaryrefslogtreecommitdiffstats
path: root/doc/python
diff options
context:
space:
mode:
authorlloyd <[email protected]>2006-06-03 04:47:50 +0000
committerlloyd <[email protected]>2006-06-03 04:47:50 +0000
commite3988b539e47af9a900e7e81c33001ea93bfe006 (patch)
treebe745714b686057ee893594bafe084ce0644f425 /doc/python
parent23e1d23233622c4a1da340d53c4a1ef7f9f98009 (diff)
doc/wrap -> doc/python
Diffstat (limited to 'doc/python')
-rw-r--r--doc/python/Makefile36
-rw-r--r--doc/python/botan/__init__.py9
-rwxr-xr-xdoc/python/mkdeps.py35
-rw-r--r--doc/python/src/base.cpp31
-rw-r--r--doc/python/src/core.cpp20
-rw-r--r--doc/python/src/filter.cpp71
-rw-r--r--doc/python/src/pipe.cpp24
-rw-r--r--doc/python/src/x509.cpp15
-rwxr-xr-xdoc/python/test.py19
9 files changed, 260 insertions, 0 deletions
diff --git a/doc/python/Makefile b/doc/python/Makefile
new file mode 100644
index 000000000..dec00a632
--- /dev/null
+++ b/doc/python/Makefile
@@ -0,0 +1,36 @@
+CXX = g++
+LANG_FLAGS = -fPIC -Wall -W -ftemplate-depth-255
+OPT_FLAGS = -g -Os
+
+PYTHON_ROOT = /usr/lib/python2.3/config
+PYTHON_INC = -I/usr/include/python2.3
+PYTHON_DEF = -DBOOST_PYTHON_DYNAMIC_LIB -DBOOST_PYTHON_SOURCE
+BOOST_ROOT = /usr/local/src/boost
+
+WRAPPER_CFLAGS = $(shell botan-config --cflags)
+SHARED_CFLAGS = $(LANG_FLAGS) $(OPT_FLAGS) $(PYTHON_INC)
+
+BOOST_CFLAGS = $(PYTHON_DEF) $(SHARED_CFLAGS)
+
+WRAP_SRC = $(wildcard src/*)
+WRAP_OBJS = $(patsubst src/%.cpp,build/botan/%.o,$(WRAP_SRC))
+
+all: botan/_botan.so
+
+include boost.deps
+
+build/libboost_python.so: $(BOOST_OBJS)
+ $(CXX) -fPIC -shared -o $@ $(BOOST_DEF) -L$(PYTHON_ROOT) $(PYTHON_INC) -Wl,-soname,libboost_python.so $^
+
+build/botan/%.o: src/%.cpp
+ $(CXX) $(SHARED_CFLAGS) $(WRAPPER_CFLAGS) -c $< -o $@
+
+botan/_botan.so: $(WRAP_OBJS) build/libboost_python.so
+ $(CXX) -shared -o $@ $(shell botan-config --libs) -L$(PYTHON_ROOT) $(WRAP_OBJS) -Lbuild/ -lboost_python -Wl,-rpath-link,. -Wl,-soname,$@
+
+dirs:
+ mkdir -p build build/boost build/botan botan
+
+clean:
+ rm -rf build/
+ rm -f botan/*.so botan/*.pyc
diff --git a/doc/python/botan/__init__.py b/doc/python/botan/__init__.py
new file mode 100644
index 000000000..e6bd5266a
--- /dev/null
+++ b/doc/python/botan/__init__.py
@@ -0,0 +1,9 @@
+from _botan import *
+
+init = LibraryInitializer()
+
+def Filter(name):
+ return make_filter(name)
+
+#def Filter(name, key):
+# return make_filter(name, key)
diff --git a/doc/python/mkdeps.py b/doc/python/mkdeps.py
new file mode 100755
index 000000000..64eafb9dc
--- /dev/null
+++ b/doc/python/mkdeps.py
@@ -0,0 +1,35 @@
+#!/usr/bin/python
+
+import os, re, sys
+
+def boost_dir():
+ return "/usr/local/src/boost/libs/python/src"
+
+def get_listing_of(dir):
+ list = [];
+ for root, dirs, files in os.walk(dir):
+ list = list + [os.path.join(root, name) for name in files]
+ list.sort()
+ return list
+
+def produce_output(list):
+ def obj_name(source):
+ return re.sub(r"^/.*/(.+).cpp$", r"build/boost/\1.o", source)
+
+ def obj_deps(sources):
+ def obj_dep(source):
+ return obj_name(source) + ": " + source + "\n\t$(CXX) $(BOOST_CFLAGS) -c $< -o $@\n"
+ return map(obj_dep, sources);
+
+ def file_lists(list):
+ def file_list(list, macro, trans):
+ return 'BOOST_' + macro + ' = ' + ' '.join(map(trans, list)) + "\n\n"
+ return file_list(list, 'SRC', None) + file_list(list, 'OBJS', obj_name)
+
+ return file_lists(list) + "\n".join(obj_deps(list))
+
+def main():
+ print produce_output(get_listing_of(boost_dir()))
+
+if __name__ == "__main__":
+ sys.exit(main())
diff --git a/doc/python/src/base.cpp b/doc/python/src/base.cpp
new file mode 100644
index 000000000..33457fe61
--- /dev/null
+++ b/doc/python/src/base.cpp
@@ -0,0 +1,31 @@
+/*************************************************
+* Wrappers for basic Botan types *
+* (C) 2005-2006 Jack Lloyd <[email protected]> *
+*************************************************/
+
+#include <boost/python.hpp>
+using namespace boost::python;
+
+#include <botan/init.h>
+#include <botan/symkey.h>
+using namespace Botan;
+
+void export_basic_types()
+ {
+ class_<LibraryInitializer>("LibraryInitializer")
+ .def(init< optional<std::string> >());
+
+ class_<OctetString>("OctetString")
+ .def(init< optional<std::string> >())
+ .def("as_string", &OctetString::as_string)
+ .def("length", &OctetString::length)
+ .def(self ^= self);
+
+ class_<SymmetricKey, bases<OctetString> >("SymmetricKey")
+ .def(init< optional<std::string> >())
+ .def(init< u32bit >());
+
+ class_<InitializationVector, bases<OctetString> >("InitializationVector")
+ .def(init< optional<std::string> >())
+ .def(init< u32bit >());
+ }
diff --git a/doc/python/src/core.cpp b/doc/python/src/core.cpp
new file mode 100644
index 000000000..6c8f61c1c
--- /dev/null
+++ b/doc/python/src/core.cpp
@@ -0,0 +1,20 @@
+/*************************************************
+* Boost.Python module definition *
+* (C) 2005-2006 Jack Lloyd <[email protected]> *
+*************************************************/
+
+#include <boost/python.hpp>
+using namespace boost::python;
+
+extern void export_basic_types();
+extern void export_filters();
+extern void export_pipe();
+extern void export_x509();
+
+BOOST_PYTHON_MODULE(_botan)
+ {
+ export_basic_types();
+ export_filters();
+ export_pipe();
+ export_x509();
+ }
diff --git a/doc/python/src/filter.cpp b/doc/python/src/filter.cpp
new file mode 100644
index 000000000..10497f851
--- /dev/null
+++ b/doc/python/src/filter.cpp
@@ -0,0 +1,71 @@
+/*************************************************
+* Wrappers for Botan Filters *
+* (C) 2005-2006 Jack Lloyd <[email protected]> *
+*************************************************/
+
+#include <boost/python.hpp>
+using namespace boost::python;
+
+#include <botan/pipe.h>
+#include <botan/lookup.h>
+using namespace Botan;
+
+class Python_Filter : public Fanout_Filter, public wrapper<Fanout_Filter>
+ {
+ public:
+ virtual void write(const byte in[], u32bit len)
+ {
+ this->get_override("write")(in, len);
+ }
+ virtual void start_msg()
+ {
+ if(override start_msg = this->get_override("start_msg"))
+ start_msg();
+ Filter::start_msg();
+ }
+ virtual void end_msg()
+ {
+ if(override end_msg = this->get_override("end_msg"))
+ end_msg();
+ Filter::end_msg();
+ }
+
+ Python_Filter(Filter* f)
+ {
+ if(f) { attach(f); incr_owns(); }
+ }
+ };
+
+Python_Filter* make_filter1(const std::string& name)
+ {
+ printf("Trying to make filter of type %s\n", name.c_str());
+
+ if(have_hash(name))
+ return new Python_Filter(new Hash_Filter(name));
+ if(name == "Hex_Encoder")
+ return new Python_Filter(new Hex_Encoder);
+
+ return 0;
+ }
+
+// FIXME: add new wrapper for Keyed_Filter here
+Python_Filter* make_filter2(const std::string& name,
+ const SymmetricKey& key)
+ {
+ printf("Trying to make a filter of type %s (key %s)\n", name.c_str(),
+ key.as_string().c_str());
+ return 0;
+ }
+
+void export_filters()
+ {
+ class_<Python_Filter, boost::noncopyable>("Filter", no_init)
+ .def("write", &Filter::write)
+ .def("start_msg", &Filter::start_msg)
+ .def("end_msg", &Filter::end_msg);
+
+ def("make_filter", make_filter1,
+ return_value_policy<manage_new_object>());
+ def("make_filter", make_filter2,
+ return_value_policy<manage_new_object>());
+ }
diff --git a/doc/python/src/pipe.cpp b/doc/python/src/pipe.cpp
new file mode 100644
index 000000000..e586b087f
--- /dev/null
+++ b/doc/python/src/pipe.cpp
@@ -0,0 +1,24 @@
+/*************************************************
+* Pipe wrapper using Boost.Python *
+* (C) 2005-2006 Jack Lloyd <[email protected]> *
+*************************************************/
+
+#include <boost/python.hpp>
+using namespace boost::python;
+
+#include <botan/pipe.h>
+using namespace Botan;
+
+void export_pipe()
+ {
+ void (Pipe::*pipe_write1)(const std::string&) = &Pipe::write;
+ void (Pipe::*pipe_write2)(const byte[], u32bit) = &Pipe::write;
+
+ class_<Pipe, boost::noncopyable>("Pipe")
+ .def(init< Python_Filter*, optional<Python_Filter*> >())
+ .def("start_msg", &Pipe::start_msg)
+ .def("end_msg", &Pipe::end_msg)
+ .def("write", pipe_write1)
+ .def("write", pipe_write2)
+ .def("read_all", &Pipe::read_all_as_string);
+ }
diff --git a/doc/python/src/x509.cpp b/doc/python/src/x509.cpp
new file mode 100644
index 000000000..dc462f48b
--- /dev/null
+++ b/doc/python/src/x509.cpp
@@ -0,0 +1,15 @@
+/*************************************************
+* Wrappers for X.509 types *
+* (C) 2005-2006 Jack Lloyd <[email protected]> *
+*************************************************/
+
+#include <boost/python.hpp>
+using namespace boost::python;
+
+#include <botan/x509_key.h>
+
+void export_x509()
+ {
+ class_<X509_PublicKey>("x509_key", no_init)
+ .def(
+ }
diff --git a/doc/python/test.py b/doc/python/test.py
new file mode 100755
index 000000000..c73cc9369
--- /dev/null
+++ b/doc/python/test.py
@@ -0,0 +1,19 @@
+#!/usr/bin/python
+
+import sys, botan
+
+def do_hash(input):
+ pipe = botan.Pipe(botan.Filter("MD5"), botan.Filter("Hex_Encoder"))
+
+ print pipe
+ pipe.start_msg()
+ pipe.write(input)
+ pipe.end_msg()
+
+ return pipe.read_all()
+
+def main():
+ print do_hash("foo")
+
+if __name__ == "__main__":
+ sys.exit(main())