00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef _LIB_CRYPTO_BASE64_H_
00018 #define _LIB_CRYPTO_BASE64_H_ 1
00019
00026 #include <lib/sconfig.h>
00027
00035 class Base64Encoder
00036 {
00037 private:
00038 uint32 state;
00039 int lwidth;
00040
00041 public:
00044 inline Base64Encoder(int _lwidth=0) : state(0),lwidth(_lwidth) {}
00046 inline Base64Encoder(const Base64Encoder &b) :
00047 state(b.state),lwidth(b.lwidth) {}
00049 inline ~Base64Encoder() {}
00050
00052 inline Base64Encoder &operator=(const Base64Encoder &b)
00053 { state=b.state; lwidth=b.lwidth; return(*this); }
00054
00061 inline void SetLWidth(int _lwidth)
00062 { lwidth=_lwidth; }
00063
00075 inline void reset()
00076 { state=0; }
00077
00086 inline size_t EncodedSize(size_t inlen)
00087 {
00088 size_t words=(inlen+2)/3;
00089 return(words*4 + 8 + (lwidth ? words/lwidth : 0));
00090 }
00091
00115 ssize_t encode(const char *in,size_t inlen,char *out,size_t outlen);
00116
00122 static ssize_t EncodeBuf(const char *in,size_t inlen,char *out,
00123 size_t outlen,int lwidth);
00124 };
00125
00126
00134 class Base64Decoder
00135 {
00136 private:
00137 uint32 state;
00138
00139 public:
00141 inline Base64Decoder() : state(0) {}
00143 inline Base64Decoder(const Base64Decoder &b) : state(b.state) {}
00145 inline ~Base64Decoder() {}
00146
00148 inline Base64Decoder &operator=(const Base64Decoder &b)
00149 { state=b.state; return(*this); }
00150
00157 inline void reset()
00158 { state=0; }
00159
00168 inline size_t DecodedSize(size_t inlen)
00169 {
00170 size_t words=(inlen+3)/4;
00171 return(words*3 + 2);
00172 }
00173
00202 ssize_t decode(const char *in,size_t inlen,char *out,size_t outlen);
00203
00209 static ssize_t DecodeBuf(const char *in,size_t inlen,char *out,
00210 size_t outlen);
00211 };
00212
00213 #endif