genericservices/httputils/inc/TConvBase64.h
changeset 0 e4d67989cc36
child 27 3a7375419266
equal deleted inserted replaced
-1:000000000000 0:e4d67989cc36
       
     1 // Copyright (c) 2001-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // File contains internal classes for Ascii To Base64 converison
       
    15 // and vice-versa.
       
    16 // 
       
    17 //
       
    18 
       
    19 /**
       
    20  @file TConvBase64.h
       
    21  @internalAll
       
    22  @released
       
    23 */
       
    24 
       
    25 #ifndef __TCONVBASE64_H__
       
    26 #define __TCONVBASE64_H__
       
    27 
       
    28 #include <e32base.h>
       
    29 
       
    30 
       
    31 const TInt KMaxB64EncodedCharsPerLine = 60;
       
    32 // Could be increased to 75 characters for every encoded line if KDecodeLineLength = 675.  
       
    33 // 60 was chosen to maintain existing behaviour.
       
    34 const TInt8 KImcvLookUpStartOffset = 43;
       
    35 const TUint8 KImcvConvEquals = '=';
       
    36 const TInt8 AsciiToBase64[80]=
       
    37 	{
       
    38     62, -1, -1, -1, 63, 52, 53, 54, 55, 56,
       
    39     57, 58, 59, 60, 61, -1, -1, -1, 64, -1,
       
    40     -1, -1,  0,  1,  2,  3,  4,  5,  6,  7,
       
    41     8,  9, 10, 11, 12, 13, 14, 15, 16, 17,
       
    42     18, 19, 20, 21, 22, 23, 24, 25, -1, -1,
       
    43     -1, -1, -1, -1, 26, 27, 28, 29, 30, 31,
       
    44     32, 33, 34, 35, 36, 37, 38, 39, 40, 41,
       
    45     42, 43, 44, 45, 46, 47, 48, 49, 50, 51
       
    46     };
       
    47 const TInt8 Base64ToAscii[65]=
       
    48 	{
       
    49     65, 66, 67, 68, 69, 70, 71, 72, 73, 74,
       
    50     75, 76, 77, 78, 79, 80, 81, 82, 83, 84,
       
    51     85, 86, 87, 88, 89, 90, 97, 98, 99,100,
       
    52     101,102,103,104,105,106,107,108,109,110,
       
    53     111,112,113,114,115,116,117,118,119,120,
       
    54     121,122, 48, 49, 50, 51, 52, 53, 54, 55,
       
    55     56, 57, 43, 47, 61 
       
    56     };
       
    57     
       
    58 /**
       
    59 Base64 encoding and decoding class, complaint with RFC-3548.
       
    60 @internalAll
       
    61 @released
       
    62 */    
       
    63 class TBase64
       
    64 	{
       
    65 private:
       
    66 	/** 
       
    67 		enum base64 coding defines 
       
    68 	*/
       
    69 	enum
       
    70 	{ 
       
    71 	/** Padding characters	*/
       
    72 	EPadChar = 64 
       
    73 	};
       
    74 	
       
    75 	/** 
       
    76 	enum for EMaskValues
       
    77 	*/
       
    78 	enum EMaskValues
       
    79 	{ 
       
    80 	/**	Mask Six bits */
       
    81 	ESixBitMask = 0x3F, 
       
    82 	/** Mask Eight bits */
       
    83 	EEightBitMask = 0xFF 
       
    84 	};
       
    85 	
       
    86 	/** 
       
    87 	enum for EMaskShiftValues
       
    88 	*/
       
    89 	enum EMaskShiftValues
       
    90 	{ 
       
    91 	/** enum for 6 	*/
       
    92 	ESix = 6,
       
    93 	/** enum for 4 	*/ 
       
    94 	EFour = 4, 
       
    95 	/** enum for 2	*/
       
    96 	ETwo = 2, 
       
    97 	/** enum for 0	*/
       
    98 	EZero = 0 
       
    99 	};
       
   100 
       
   101 public:
       
   102 	IMPORT_C TBase64();
       
   103 	IMPORT_C TInt Encode( const TDesC8& aSrcString, TDes8& rDestString);
       
   104 	IMPORT_C TBool Decode( const TDesC8& aSrcString, TDes8& rDestString);
       
   105 
       
   106 private:
       
   107 
       
   108 	TInt iShiftStored;
       
   109 	TInt iMaskShiftStored;	
       
   110 	};
       
   111 	
       
   112 #endif	// __TCONVBASE64_H__