kmime_codec_base64.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef __KMIME_CODEC_BASE64__
00033 #define __KMIME_CODEC_BASE64__
00034
00035 #include "kmime_codecs.h"
00036
00037 namespace KMime {
00038
00039 class Base64Codec : public Codec {
00040 protected:
00041 friend class Codec;
00042 Base64Codec() : Codec() {}
00043
00044 public:
00045 virtual ~Base64Codec() {}
00046
00047 const char * name() const {
00048 return "base64";
00049 }
00050
00051 int maxEncodedSizeFor( int insize, bool withCRLF=false ) const {
00052
00053 int totalNumPackets = ( insize + 2 ) / 3;
00054
00055 int numLineBreaks = totalNumPackets / (76/4);
00056
00057 ++numLineBreaks;
00058
00059 return 4 * totalNumPackets + ( withCRLF ? 2 : 1 ) * numLineBreaks;
00060 }
00061
00062 int maxDecodedSizeFor( int insize, bool withCRLF=false ) const {
00063
00064
00065
00066
00067
00068 int result = ( ( insize + 3 ) / 4 ) * 3;
00069
00070 if ( withCRLF )
00071 result *= 2;
00072
00073 return result;
00074 }
00075
00076 Encoder * makeEncoder( bool withCRLF=false ) const;
00077 Decoder * makeDecoder( bool withCRLF=false ) const;
00078 };
00079
00080
00081
00082 class Rfc2047BEncodingCodec : public Base64Codec {
00083 protected:
00084 friend class Codec;
00085 Rfc2047BEncodingCodec()
00086 : Base64Codec() {}
00087
00088 public:
00089 virtual ~Rfc2047BEncodingCodec() {}
00090
00091 const char * name() const { return "b"; }
00092
00093 int maxEncodedSizeFor( int insize, bool withCRLF=false ) const {
00094 (void)withCRLF;
00095
00096 return ( ( insize + 2 ) / 3 ) * 4;
00097 }
00098
00099 int maxDecodedSizeFor( int insize, bool withCRLF=false ) const {
00100 (void)withCRLF;
00101
00102
00103 return ( ( insize + 3 ) / 4 ) * 3;
00104 }
00105
00106 Encoder * makeEncoder( bool withCRLF=false ) const;
00107 };
00108
00109
00110 }
00111
00112 #endif // __KMIME_CODEC_BASE64__
This file is part of the documentation for libkdenetwork Library Version 3.3.2.