~ubuntu-branches/debian/sid/botan/sid

« back to all changes in this revision

Viewing changes to misc/python/src/macs.cpp

  • Committer: Package Import Robot
  • Author(s): Laszlo Boszormenyi (GCS)
  • Date: 2018-03-01 22:23:25 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20180301222325-7p7vc45gu3hta34d
Tags: 2.4.0-2
* Don't remove .doctrees from the manual if it doesn't exist.
* Don't specify parallel to debhelper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*************************************************
2
 
* Boost.Python module definition                 *
3
 
* (C) 1999-2007 The Botan Project                *
4
 
*************************************************/
5
 
 
6
 
#include <botan/botan.h>
7
 
using namespace Botan;
8
 
 
9
 
#include <boost/python.hpp>
10
 
namespace python = boost::python;
11
 
 
12
 
class Py_MAC
13
 
   {
14
 
   public:
15
 
      u32bit output_length() const { return mac->OUTPUT_LENGTH; }
16
 
      u32bit keylength_min() const { return mac->MINIMUM_KEYLENGTH; }
17
 
      u32bit keylength_max() const { return mac->MAXIMUM_KEYLENGTH; }
18
 
      u32bit keylength_mod() const { return mac->KEYLENGTH_MULTIPLE; }
19
 
      std::string name() const { return mac->name(); }
20
 
      void clear() throw() { mac->clear(); }
21
 
 
22
 
      void set_key(const OctetString& key) { mac->set_key(key); }
23
 
 
24
 
      bool valid_keylength(u32bit kl) const
25
 
         {
26
 
         return mac->valid_keylength(kl);
27
 
         }
28
 
 
29
 
      void update(const std::string& in) { mac->update(in); }
30
 
 
31
 
      std::string final()
32
 
         {
33
 
         SecureVector<byte> result = mac->final();
34
 
         return std::string((const char*)result.begin(), result.size());
35
 
         }
36
 
 
37
 
      Py_MAC(const std::string& name)
38
 
         {
39
 
         mac = get_mac(name);
40
 
         }
41
 
      ~Py_MAC() { delete mac; }
42
 
   private:
43
 
      MessageAuthenticationCode* mac;
44
 
   };
45
 
 
46
 
void export_macs()
47
 
   {
48
 
   python::class_<Py_MAC>("MAC", python::init<std::string>())
49
 
      .add_property("output_length", &Py_MAC::output_length)
50
 
      .add_property("keylength_min", &Py_MAC::keylength_min)
51
 
      .add_property("keylength_max", &Py_MAC::keylength_max)
52
 
      .add_property("keylength_mod", &Py_MAC::keylength_mod)
53
 
      .add_property("name", &Py_MAC::name)
54
 
      .def("valid_keylength", &Py_MAC::valid_keylength)
55
 
      .def("set_key", &Py_MAC::set_key)
56
 
      .def("clear", &Py_MAC::clear)
57
 
      .def("update", &Py_MAC::update)
58
 
      .def("final", &Py_MAC::final);
59
 
   }