WvStreams
include/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
15struct rsa_st;
16
26class WvRSAKey
27{
28public:
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
67private:
68 bool priv;
69 mutable WvLog debug;
70};
71
72
84class WvRSAEncoder : public WvEncoder
85{
86public:
87 enum Mode {
88 Encrypt,
89 Decrypt,
92 };
93
101 WvRSAEncoder(Mode mode, const WvRSAKey &key);
102 virtual ~WvRSAEncoder();
103
104protected:
105 virtual bool _encode(WvBuf &in, WvBuf &out, bool flush);
106 virtual bool _reset(); // supported
107
108private:
109 Mode mode;
110 WvRSAKey key;
111 size_t rsasize;
112};
113
114
123class WvRSAStream : public WvEncoderStream
124{
125public:
126 WvRSAStream(WvStream *_cloned,
127 const WvRSAKey &_my_key, const WvRSAKey &_their_key,
130 virtual ~WvRSAStream() { }
131};
132
133
134#endif // __WVRSA_H
WvEncoderStream chains a series of encoders on the input and output ports of the underlying stream to...
bool flush(WvBuf &inbuf, WvBuf &outbuf, bool finish=false)
Flushes the encoder and optionally finishes it.
A WvFastString acts exactly like a WvString, but can take (const char *) strings without needing to a...
A WvLog stream accepts log messages from applications and forwards them to all registered WvLogRcv's.
An encoder implementing the RSA public key encryption method.
WvRSAEncoder(Mode mode, const WvRSAKey &key)
Creates a new RSA cipher encoder.
virtual bool _reset()
Template method implementation of reset().
virtual bool _encode(WvBuf &in, WvBuf &out, bool flush)
Template method implementation of encode().
An RSA public key or public/private key pair that can be used for encryption.
virtual WvString encode(const DumpMode mode) const
Return the information requested by mode.
Definition wvrsa.cc:86
DumpMode
Type for the encode() and decode() methods.
virtual WvString encode(const DumpMode mode) const
Return the information requested by mode.
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
WvRSAKey(int bits)
Create a new RSA key of bits strength.
virtual void decode(const DumpMode mode, WvStringParm encoded)
Load the information from the format requested by mode into the class - this overwrites the certifica...
A crypto stream implementing RSA public key encryption.
Unified support for streams, that is, sequences of bytes that may or may not be ready for read/write ...
WvString is an implementation of a simple and efficient printable-string class.