aboutsummaryrefslogtreecommitdiffstats
path: root/wrappers/swig/base.h
blob: 341a5c35ae5512293cb9adca7aaee0bb11f48d1e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/*************************************************
* SWIG Interface for Botan                       *
* (C) 1999-2003 Jack Lloyd                       *
*************************************************/

#ifndef BOTAN_WRAP_BASE_H__
#define BOTAN_WRAP_BASE_H__

#include <botan/pipe.h>

#if !defined(SWIG)
  #define OUTPUT
  #define INOUT
#endif

/*************************************************
* Typedefs                                       *
*************************************************/
typedef unsigned char byte;
typedef unsigned int u32bit;

/*************************************************
* Library Initalization/Shutdown Object          *
*************************************************/
class LibraryInitializer
   {
   public:
      LibraryInitializer(const char*);
      ~LibraryInitializer();
   };

/*************************************************
* Symmetric Key Object                           *
*************************************************/
class SymmetricKey
   {
   public:
      std::string as_string() const { return key->as_string(); }
      u32bit length() const { return key->length(); }
      SymmetricKey(u32bit = 0);
      SymmetricKey(const std::string&);
      ~SymmetricKey();
   private:
      Botan::SymmetricKey* key;
   };

/*************************************************
* Initialization Vector Object                   *
*************************************************/
class InitializationVector
   {
   public:
      std::string as_string() const { return iv.as_string(); }
      u32bit length() const { return iv.length(); }
      InitializationVector(u32bit n = 0) { iv.change(n); }
      InitializationVector(const std::string&);
   private:
      Botan::InitializationVector iv;
   };

/*************************************************
* Filter Object                                  *
*************************************************/
class Filter
   {
   public:
      Filter(const char*);
      //Filter(const char*, const SymmetricKey&);
      //Filter(const char*, const SymmetricKey&, const InitializationVector&);
      ~Filter();
   private:
      friend class Pipe;
      Botan::Filter* filter;
      bool pipe_owns;
   };

/*************************************************
* Pipe Object                                    *
*************************************************/
class Pipe
   {
   public:
      static const u32bit DEFAULT_MESSAGE = 0xFFFFFFFF;

      void write_file(const char*);
      void write_string(const char*);

      u32bit read(byte*, u32bit, u32bit = DEFAULT_MESSAGE);
      std::string read_all_as_string(u32bit = DEFAULT_MESSAGE);

      u32bit remaining(u32bit = DEFAULT_MESSAGE);

      void start_msg();
      void end_msg();

      Pipe(Filter* = 0, Filter* = 0, Filter* = 0, Filter* = 0);
      ~Pipe();
   private:
      Botan::Pipe* pipe;
   };

#endif