WvStreams
wvbase64.h
00001 /* -*- Mode: C++ -*-
00002  * Worldvisions Weaver Software:
00003  *   Copyright (C) 1997-2002 Net Integration Technologies, Inc.
00004  *
00005  * Base64 encoder and decoder implementations.
00006  */
00007 #ifndef __WVBASE64_H
00008 #define __WVBASE64_H
00009 
00010 #include "wvencoder.h"
00011 
00020 class WvBase64Encoder : public WvEncoder
00021 {
00022     enum State {
00023         ATBIT0, ATBIT2, ATBIT4
00024     };
00025     State state;
00026     unsigned int bits; // remaining bits shifted left 8 bits
00027     
00028 public:
00030     WvBase64Encoder();
00031     virtual ~WvBase64Encoder() { }
00032 
00033 protected:
00034     // on flush, outputs any needed pad characters
00035     virtual bool _encode(WvBuf &in, WvBuf &out, bool flush);
00036     virtual bool _finish(WvBuf &out);
00037     virtual bool _reset(); // supported
00038 };
00039 
00040 
00049 class WvBase64Decoder : public WvEncoder
00050 {
00051     enum State {
00052         ATBIT0, ATBIT2, ATBIT4, ATBIT6, PAD
00053     };
00054     State state;
00055     unsigned int bits; // remaining bits shifted left 6 bits
00056     
00057 public:
00059     WvBase64Decoder();
00060     virtual ~WvBase64Decoder() { }
00061 
00062 protected:
00063     virtual bool _encode(WvBuf &in, WvBuf &out, bool flush);
00064     virtual bool _reset(); // supported
00065 };
00066 
00067 #endif // __WVBASE64_H