Crypto++
channels.h
1 #ifndef CRYPTOPP_CHANNELS_H
2 #define CRYPTOPP_CHANNELS_H
3 
4 #include "simple.h"
5 #include "smartptr.h"
6 #include <map>
7 #include <list>
8 
9 NAMESPACE_BEGIN(CryptoPP)
10 
11 #if 0
12 //! Route input on default channel to different and/or multiple channels based on message sequence number
13 class MessageSwitch : public Sink
14 {
15 public:
16  void AddDefaultRoute(BufferedTransformation &destination, const std::string &channel);
17  void AddRoute(unsigned int begin, unsigned int end, BufferedTransformation &destination, const std::string &channel);
18 
19  void Put(byte inByte);
20  void Put(const byte *inString, unsigned int length);
21 
22  void Flush(bool completeFlush, int propagation=-1);
23  void MessageEnd(int propagation=-1);
24  void PutMessageEnd(const byte *inString, unsigned int length, int propagation=-1);
25  void MessageSeriesEnd(int propagation=-1);
26 
27 private:
28  typedef std::pair<BufferedTransformation *, std::string> Route;
29  struct RangeRoute
30  {
31  RangeRoute(unsigned int begin, unsigned int end, const Route &route)
32  : begin(begin), end(end), route(route) {}
33  bool operator<(const RangeRoute &rhs) const {return begin < rhs.begin;}
34  unsigned int begin, end;
35  Route route;
36  };
37 
38  typedef std::list<RangeRoute> RouteList;
39  typedef std::list<Route> DefaultRouteList;
40 
41  RouteList m_routes;
42  DefaultRouteList m_defaultRoutes;
43  unsigned int m_nCurrentMessage;
44 };
45 #endif
46 
48 {
49 public:
50  typedef std::pair<BufferedTransformation *, std::string> Route;
51  typedef std::multimap<std::string, Route> RouteMap;
52 
53  typedef std::pair<BufferedTransformation *, value_ptr<std::string> > DefaultRoute;
54  typedef std::list<DefaultRoute> DefaultRouteList;
55 
56  // SunCC workaround: can't use const_iterator here
57  typedef RouteMap::iterator MapIterator;
58  typedef DefaultRouteList::iterator ListIterator;
59 };
60 
61 class ChannelSwitch;
62 
64 {
65 public:
66  ChannelSwitch& m_cs;
67  std::string m_channel;
68  bool m_useDefault;
69  MapIterator m_itMapCurrent, m_itMapEnd;
70  ListIterator m_itListCurrent, m_itListEnd;
71 
72  ChannelRouteIterator(ChannelSwitch &cs) : m_cs(cs) {}
73  void Reset(const std::string &channel);
74  bool End() const;
75  void Next();
76  BufferedTransformation & Destination();
77  const std::string & Channel();
78 };
79 
80 //! Route input to different and/or multiple channels based on channel ID
81 class CRYPTOPP_DLL ChannelSwitch : public Multichannel<Sink>, public ChannelSwitchTypedefs
82 {
83 public:
84  ChannelSwitch() : m_it(*this), m_blocked(false) {}
85  ChannelSwitch(BufferedTransformation &destination) : m_it(*this), m_blocked(false)
86  {
87  AddDefaultRoute(destination);
88  }
89  ChannelSwitch(BufferedTransformation &destination, const std::string &outChannel) : m_it(*this), m_blocked(false)
90  {
91  AddDefaultRoute(destination, outChannel);
92  }
93 
94  void IsolatedInitialize(const NameValuePairs &parameters=g_nullNameValuePairs);
95 
96  size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking);
97  size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking);
98 
99  bool ChannelFlush(const std::string &channel, bool completeFlush, int propagation=-1, bool blocking=true);
100  bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true);
101 
102  byte * ChannelCreatePutSpace(const std::string &channel, size_t &size);
103 
104  void AddDefaultRoute(BufferedTransformation &destination);
105  void RemoveDefaultRoute(BufferedTransformation &destination);
106  void AddDefaultRoute(BufferedTransformation &destination, const std::string &outChannel);
107  void RemoveDefaultRoute(BufferedTransformation &destination, const std::string &outChannel);
108  void AddRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel);
109  void RemoveRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel);
110 
111 private:
112  RouteMap m_routeMap;
113  DefaultRouteList m_defaultRoutes;
114 
116  bool m_blocked;
117 
118  friend class ChannelRouteIterator;
119 };
120 
121 NAMESPACE_END
122 
123 #endif
interface for buffered transformations
Definition: cryptlib.h:770
Route input to different and/or multiple channels based on channel ID.
Definition: channels.h:81
size_t Put(byte inByte, bool blocking=true)
input a byte for processing
Definition: cryptlib.h:784
virtual bool MessageSeriesEnd(int propagation=-1, bool blocking=true)
mark end of a series of messages
virtual bool Flush(bool hardFlush, int propagation=-1, bool blocking=true)
flush buffered input and/or output
const NameValuePairs & g_nullNameValuePairs
empty set of name-value pairs
bool operator<(const ::PolynomialMod2 &a, const ::PolynomialMod2 &b)
compares degree
Definition: gf2n.h:252
A BufferedTransformation that doesn't produce any retrievable output.
Definition: simple.h:189
interface for retrieving values given their names
Definition: cryptlib.h:224