source: trunk/src-cryptopp/channels.h

Last change on this file was e230cb0, checked in by David Stainton <dstainton415@…>, at 2016-10-12T13:27:29Z

Add cryptopp from tag CRYPTOPP_5_6_5

  • Property mode set to 100644
File size: 4.4 KB
Line 
1// channels.h - written and placed in the public domain by Wei Dai
2
3//! \file
4//! \headerfile channels.h
5//! \brief Classes for multiple named channels
6
7#ifndef CRYPTOPP_CHANNELS_H
8#define CRYPTOPP_CHANNELS_H
9
10#include "cryptlib.h"
11#include "simple.h"
12#include "smartptr.h"
13#include "stdcpp.h"
14
15NAMESPACE_BEGIN(CryptoPP)
16
17#if 0
18//! Route input on default channel to different and/or multiple channels based on message sequence number
19class MessageSwitch : public Sink
20{
21public:
22        void AddDefaultRoute(BufferedTransformation &destination, const std::string &channel);
23        void AddRoute(unsigned int begin, unsigned int end, BufferedTransformation &destination, const std::string &channel);
24
25        void Put(byte inByte);
26        void Put(const byte *inString, unsigned int length);
27
28        void Flush(bool completeFlush, int propagation=-1);
29        void MessageEnd(int propagation=-1);
30        void PutMessageEnd(const byte *inString, unsigned int length, int propagation=-1);
31        void MessageSeriesEnd(int propagation=-1);
32
33private:
34        typedef std::pair<BufferedTransformation *, std::string> Route;
35        struct RangeRoute
36        {
37                RangeRoute(unsigned int begin, unsigned int end, const Route &route)
38                        : begin(begin), end(end), route(route) {}
39                bool operator<(const RangeRoute &rhs) const {return begin < rhs.begin;}
40                unsigned int begin, end;
41                Route route;
42        };
43
44        typedef std::list<RangeRoute> RouteList;
45        typedef std::list<Route> DefaultRouteList;
46
47        RouteList m_routes;
48        DefaultRouteList m_defaultRoutes;
49        unsigned int m_nCurrentMessage;
50};
51#endif
52
53class ChannelSwitchTypedefs
54{
55public:
56        typedef std::pair<BufferedTransformation *, std::string> Route;
57        typedef std::multimap<std::string, Route> RouteMap;
58
59        typedef std::pair<BufferedTransformation *, value_ptr<std::string> > DefaultRoute;
60        typedef std::list<DefaultRoute> DefaultRouteList;
61
62        // SunCC workaround: can't use const_iterator here
63        typedef RouteMap::iterator MapIterator;
64        typedef DefaultRouteList::iterator ListIterator;
65};
66
67class ChannelSwitch;
68
69class ChannelRouteIterator : public ChannelSwitchTypedefs
70{
71public:
72        ChannelRouteIterator(ChannelSwitch &cs) : m_cs(cs), m_useDefault(false) {}
73
74        void Reset(const std::string &channel);
75        bool End() const;
76        void Next();
77        BufferedTransformation & Destination();
78        const std::string & Channel();
79
80        ChannelSwitch& m_cs;
81        std::string m_channel;
82        bool m_useDefault;
83        MapIterator m_itMapCurrent, m_itMapEnd;
84        ListIterator m_itListCurrent, m_itListEnd;
85
86protected:
87        // Hide this to see if we break something...
88        ChannelRouteIterator();
89};
90
91//! Route input to different and/or multiple channels based on channel ID
92class CRYPTOPP_DLL ChannelSwitch : public Multichannel<Sink>, public ChannelSwitchTypedefs
93{
94public:
95        ChannelSwitch() : m_it(*this), m_blocked(false) {}
96        ChannelSwitch(BufferedTransformation &destination) : m_it(*this), m_blocked(false)
97        {
98                AddDefaultRoute(destination);
99        }
100        ChannelSwitch(BufferedTransformation &destination, const std::string &outChannel) : m_it(*this), m_blocked(false)
101        {
102                AddDefaultRoute(destination, outChannel);
103        }
104
105        void IsolatedInitialize(const NameValuePairs &parameters=g_nullNameValuePairs);
106
107        size_t ChannelPut2(const std::string &channel, const byte *begin, size_t length, int messageEnd, bool blocking);
108        size_t ChannelPutModifiable2(const std::string &channel, byte *begin, size_t length, int messageEnd, bool blocking);
109
110        bool ChannelFlush(const std::string &channel, bool completeFlush, int propagation=-1, bool blocking=true);
111        bool ChannelMessageSeriesEnd(const std::string &channel, int propagation=-1, bool blocking=true);
112
113        byte * ChannelCreatePutSpace(const std::string &channel, size_t &size);
114
115        void AddDefaultRoute(BufferedTransformation &destination);
116        void RemoveDefaultRoute(BufferedTransformation &destination);
117        void AddDefaultRoute(BufferedTransformation &destination, const std::string &outChannel);
118        void RemoveDefaultRoute(BufferedTransformation &destination, const std::string &outChannel);
119        void AddRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel);
120        void RemoveRoute(const std::string &inChannel, BufferedTransformation &destination, const std::string &outChannel);
121
122private:
123        RouteMap m_routeMap;
124        DefaultRouteList m_defaultRoutes;
125
126        ChannelRouteIterator m_it;
127        bool m_blocked;
128
129        friend class ChannelRouteIterator;
130};
131
132NAMESPACE_END
133
134#endif
Note: See TracBrowser for help on using the repository browser.