Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

/ray/src/lib/crypto/base64.h

Go to the documentation of this file.
00001 /*
00002  * lib/crypto/base64.h
00003  * 
00004  * Include header base-64 binary <-> ASCII conversion classes. 
00005  * 
00006  * Copyright (c) 2001--2004 by Wolfgang Wieser ] wwieser (a) gmx <*> de [ 
00007  * 
00008  * This file may be distributed and/or modified under the terms of the 
00009  * GNU General Public License version 2 as published by the Free Software 
00010  * Foundation. (See COPYING.GPL for details.)
00011  * 
00012  * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00013  * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00014  * 
00015  */
00016 
00017 #ifndef _LIB_CRYPTO_BASE64_H_
00018 #define _LIB_CRYPTO_BASE64_H_ 1
00019 
00026 #include <lib/sconfig.h>    /* MUST be first */
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  /* _LIB_CRYPTO_BASE64_H_ */

Generated on Sat Feb 19 22:33:45 2005 for Ray by doxygen 1.3.5