00001
00002
00003
00004
00005
00006
00007 #ifndef __WVRSA_H
00008 #define __WVRSA_H
00009
00010 #include "wverror.h"
00011 #include "wvencoder.h"
00012 #include "wvencoderstream.h"
00013 #include "wvlog.h"
00014
00015 struct rsa_st;
00016
00026 class WvRSAKey
00027 {
00028 public:
00036 enum DumpMode { RsaPEM, RsaPubPEM, RsaHex, RsaPubHex };
00037
00038 struct rsa_st *rsa;
00039
00040 WvRSAKey();
00041 WvRSAKey(const WvRSAKey &k);
00042 WvRSAKey(WvStringParm keystr, bool priv);
00043 WvRSAKey(struct rsa_st *_rsa, bool priv);
00044
00048 WvRSAKey(int bits);
00049
00050 virtual ~WvRSAKey();
00051
00052 virtual bool isok() const;
00053
00057 virtual WvString encode(const DumpMode mode) const;
00058 virtual void encode(const DumpMode mode, WvBuf &buf) const;
00059
00064 virtual void decode(const DumpMode mode, WvStringParm encoded);
00065 virtual void decode(const DumpMode mode, WvBuf &encoded);
00066
00067 private:
00068 bool priv;
00069 mutable WvLog debug;
00070 };
00071
00072
00084 class WvRSAEncoder : public WvEncoder
00085 {
00086 public:
00087 enum Mode {
00088 Encrypt,
00089 Decrypt,
00090 SignEncrypt,
00091 SignDecrypt
00092 };
00093
00101 WvRSAEncoder(Mode mode, const WvRSAKey &key);
00102 virtual ~WvRSAEncoder();
00103
00104 protected:
00105 virtual bool _encode(WvBuf &in, WvBuf &out, bool flush);
00106 virtual bool _reset();
00107
00108 private:
00109 Mode mode;
00110 WvRSAKey key;
00111 size_t rsasize;
00112 };
00113
00114
00123 class WvRSAStream : public WvEncoderStream
00124 {
00125 public:
00126 WvRSAStream(WvStream *_cloned,
00127 const WvRSAKey &_my_key, const WvRSAKey &_their_key,
00128 WvRSAEncoder::Mode readmode = WvRSAEncoder::Decrypt,
00129 WvRSAEncoder::Mode writemode = WvRSAEncoder::Encrypt);
00130 virtual ~WvRSAStream() { }
00131 };
00132
00133
00134 #endif // __WVRSA_H