WvStreams
wvrsa.h
1 /* -*- Mode: C++ -*-
2  * Worldvisions Tunnel Vision Software:
3  * Copyright (C) 1997-2002 Net Integration Technologies, Inc.
4  *
5  * RSA cryptography abstractions.
6  */
7 #ifndef __WVRSA_H
8 #define __WVRSA_H
9 
10 #include "wverror.h"
11 #include "wvencoder.h"
12 #include "wvencoderstream.h"
13 #include "wvlog.h"
14 
15 struct rsa_st;
16 
26 class WvRSAKey
27 {
28 public:
36  enum DumpMode { RsaPEM, RsaPubPEM, RsaHex, RsaPubHex };
37 
38  struct rsa_st *rsa;
39 
40  WvRSAKey();
41  WvRSAKey(const WvRSAKey &k);
42  WvRSAKey(WvStringParm keystr, bool priv);
43  WvRSAKey(struct rsa_st *_rsa, bool priv); // note: takes ownership
44 
48  WvRSAKey(int bits);
49 
50  virtual ~WvRSAKey();
51 
52  virtual bool isok() const;
53 
57  virtual WvString encode(const DumpMode mode) const;
58  virtual void encode(const DumpMode mode, WvBuf &buf) const;
59 
64  virtual void decode(const DumpMode mode, WvStringParm encoded);
65  virtual void decode(const DumpMode mode, WvBuf &encoded);
66 
67 private:
68  bool priv;
69  mutable WvLog debug;
70 };
71 
72 
84 class WvRSAEncoder : public WvEncoder
85 {
86 public:
87  enum Mode {
92  };
93 
101  WvRSAEncoder(Mode mode, const WvRSAKey &key);
102  virtual ~WvRSAEncoder();
103 
104 protected:
105  virtual bool _encode(WvBuf &in, WvBuf &out, bool flush);
106  virtual bool _reset(); // supported
107 
108 private:
109  Mode mode;
110  WvRSAKey key;
111  size_t rsasize;
112 };
113 
114 
124 {
125 public:
126  WvRSAStream(WvStream *_cloned,
127  const WvRSAKey &_my_key, const WvRSAKey &_their_key,
130  virtual ~WvRSAStream() { }
131 };
132 
133 
134 #endif // __WVRSA_H
WvRSAEncoder::WvRSAEncoder
WvRSAEncoder(Mode mode, const WvRSAKey &key)
Creates a new RSA cipher encoder.
Definition: wvrsa.cc:221
WvEncoderStream
WvEncoderStream chains a series of encoders on the input and output ports of the underlying stream to...
Definition: wvencoderstream.h:37
WvEncoder
The base encoder class.
Definition: wvencoder.h:67
WvRSAEncoder::Encrypt
@ Encrypt
Definition: wvrsa.h:88
WvRSAKey::encode
virtual WvString encode(const DumpMode mode) const
Return the information requested by mode.
Definition: wvrsa.cc:86
WvRSAEncoder::Mode
Mode
Definition: wvrsa.h:87
WvRSAEncoder::SignDecrypt
@ SignDecrypt
Definition: wvrsa.h:91
WvRSAEncoder::SignEncrypt
@ SignEncrypt
Definition: wvrsa.h:90
WvRSAEncoder
An encoder implementing the RSA public key encryption method.
Definition: wvrsa.h:84
WvRSAKey
An RSA public key or public/private key pair that can be used for encryption.
Definition: wvrsa.h:26
WvRSAKey::DumpMode
DumpMode
Type for the encode() and decode() methods.
Definition: wvrsa.h:36
WvRSAEncoder::_reset
virtual bool _reset()
Template method implementation of reset().
Definition: wvrsa.cc:236
WvString
WvString is an implementation of a simple and efficient printable-string class.
Definition: wvstring.h:329
WvRSAEncoder::_encode
virtual bool _encode(WvBuf &in, WvBuf &out, bool flush)
Template method implementation of encode().
Definition: wvrsa.cc:242
WvLog
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
Definition: wvlog.h:56
WvRSAKey::decode
virtual void decode(const DumpMode mode, WvStringParm encoded)
Load the information from the format requested by mode into the class - this overwrites the certifica...
Definition: wvrsa.cc:147
WvBufBase< unsigned char >
Specialization of WvBufBase for unsigned char type buffers intended for use with raw memory buffers.
Definition: wvbuf.h:22
WvRSAEncoder::Decrypt
@ Decrypt
Definition: wvrsa.h:89
WvStream
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
Definition: wvstream.h:24
WvRSAStream
A crypto stream implementing RSA public key encryption.
Definition: wvrsa.h:123
WvEncoder::flush
bool flush(WvBuf &inbuf, WvBuf &outbuf, bool finish=false)
Flushes the encoder and optionally finishes it.
Definition: wvencoder.h:163