00001 // -*- C++ -*- 00002 00003 //============================================================================= 00004 /** 00005 * @file Codecs.h 00006 * 00007 * Codecs.h,v 4.9 2005/11/26 03:13:13 ossama Exp 00008 * 00009 * @author Krishnakumar B <kitty@cs.wustl.edu> 00010 * 00011 * Codecs is a generic wrapper for various encoding and decoding 00012 * mechanisms. Currently it includes Base64 content transfer-encoding as 00013 * specified by RFC 2045, Multipurpose Internet Mail Extensions (MIME) Part 00014 * One: Format of Internet Message Bodies. 00015 * 00016 */ 00017 //============================================================================= 00018 00019 #ifndef ACE_CODECS_H 00020 #define ACE_CODECS_H 00021 00022 #include /**/ "ace/pre.h" 00023 00024 #include "ace/ACE_export.h" 00025 00026 #if !defined (ACE_LACKS_PRAGMA_ONCE) 00027 # pragma once 00028 #endif /* ACE_LACKS_PRAGMA_ONCE */ 00029 00030 #include "ace/Basic_Types.h" 00031 #include "ace/Global_Macros.h" 00032 00033 00034 ACE_BEGIN_VERSIONED_NAMESPACE_DECL 00035 00036 /** 00037 * @class ACE_Base64 00038 * 00039 * @brief Encode/Decode a stream of bytes according to Base64 encoding. 00040 * 00041 * This class provides methods to encode or decode a stream of bytes 00042 * to/from Base64 encoding. It doesn't convert the input stream to a 00043 * canonical form before encoding. 00044 * 00045 */ 00046 class ACE_Export ACE_Base64 00047 { 00048 public: 00049 00050 //@{ 00051 00052 /** 00053 * Encodes a stream of bytes to Base64 data 00054 * 00055 * @param input Binary data in byte stream. 00056 * @param input_len Length of the byte stream. 00057 * @param output_len Length of the encoded Base64 byte stream. 00058 * @return Encoded Base64 data in byte stream or NULL if input data cannot 00059 * be encoded. 00060 */ 00061 00062 static ACE_Byte* encode (const ACE_Byte* input, 00063 const size_t input_len, 00064 size_t* output_len); 00065 /** 00066 * Decodes a stream of Base64 to bytes data 00067 * 00068 * @param input Encoded Base64 data in byte stream. 00069 * @param output_len Length of the binary byte stream. 00070 * @return Binary data in byte stream or NULL if input data cannot 00071 * be encoded. 00072 */ 00073 static ACE_Byte* decode (const ACE_Byte* input, 00074 size_t* output_len); 00075 00076 /** 00077 * Return the length of the encoded input data 00078 * 00079 * @param input Encoded Base64 data in byte stream. 00080 * @return Length of the encoded Base64 data. 00081 * 00082 */ 00083 static size_t length (const ACE_Byte* input); 00084 00085 //@} 00086 00087 protected: 00088 00089 // Prevent default construction. 00090 ACE_Base64 (void) {} 00091 00092 private: 00093 00094 // Preventing copying and assignment. 00095 ACE_Base64 (ACE_Base64 const &); 00096 ACE_Base64 & operator= (ACE_Base64 const &); 00097 00098 /// Initialize the tables for encoding/decoding. 00099 static void init (void); 00100 00101 private: 00102 00103 /// Alphabet used for decoding i.e decoder_[alphabet_[i = 0..63]] = i 00104 static ACE_Byte decoder_[]; 00105 00106 /// Alphabet used to check valid range of encoded input i.e 00107 /// member_[alphabet_[0..63]] = 1 00108 static ACE_Byte member_[]; 00109 00110 /// Boolean to denote whether initialization is complete 00111 static bool init_; 00112 00113 }; 00114 00115 ACE_END_VERSIONED_NAMESPACE_DECL 00116 00117 #include /**/ "ace/post.h" 00118 00119 #endif /* ACE_CODECS_H */