cryptomgmtlibs/securityutils/inc/base64.h
changeset 0 2c201484c85f
child 6 50f2ff6984be
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description: 
       
    15 *
       
    16 */
       
    17 //
       
    18 // base64.h
       
    19 //
       
    20 
       
    21 /**
       
    22 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
       
    23 * All rights reserved.
       
    24 * This component and the accompanying materials are made available
       
    25 * under the terms of the License "Symbian Foundation License v1.0"
       
    26 * which accompanies this distribution, and is available
       
    27 * at the URL "http://www.symbianfoundation.org/legal/sfl-v10.html".
       
    28 *
       
    29 * Initial Contributors:
       
    30 * Nokia Corporation - initial contribution.
       
    31 *
       
    32 * Contributors:
       
    33 *
       
    34 * Description:
       
    35 * Base64 encoding and decoding functions.
       
    36 * 
       
    37 *
       
    38 */
       
    39 
       
    40 
       
    41 
       
    42 
       
    43 
       
    44 /**
       
    45  @file
       
    46  @internalComponent
       
    47 */
       
    48 
       
    49 #ifndef __BASE64_H__
       
    50 #define __BASE64_H__
       
    51 
       
    52 #include <e32base.h>
       
    53 
       
    54 /**
       
    55  * This class performs Base64 encoding and decoding. The implementation
       
    56  * has been obtained from messaging.
       
    57  */
       
    58 class TBase64
       
    59 	{
       
    60 public:
       
    61 	/**
       
    62 	 * Constructs the codec object.
       
    63 	 */
       
    64 	IMPORT_C TBase64();
       
    65 
       
    66 	/**
       
    67 	 * Initializes the codec.
       
    68 	 */
       
    69 	IMPORT_C void Initialize();
       
    70 
       
    71 	/**
       
    72 	 * Encodes binary data using base64 encoding.
       
    73 	 * @param aSrcString Data to encode.
       
    74 	 * @return Newly allocated buffer containing base64 encoding of
       
    75 	 *     the data (on the cleanup stack).
       
    76 	 * @note The function leaves in case of an error.
       
    77 	 */
       
    78 	IMPORT_C HBufC8* EncodeLC(const TDesC8& aSrcString);
       
    79 
       
    80 	/**
       
    81 	 * Decodes base64-encoded binary data.
       
    82 	 * @param aSrcString Data to decode.
       
    83 	 * @param aNeedMoreData Receives ETrue if the encoded string is
       
    84 	 *     not long enough to decode in full, EFalse otherwise.
       
    85 	 * @return Newly allocated buffer containing decoded binary data
       
    86 	 *     (on the cleanup stack).
       
    87 	 * @note The function leaves in case of an error.
       
    88 	 */
       
    89 	IMPORT_C HBufC8* DecodeLC(const TDesC8& aSrcString, TBool& aNeedMoreData);
       
    90 
       
    91 private:
       
    92 	enum {EPadChar = 64};
       
    93 	enum EMaskValues {ESixBitMask = 0x3F, EEightBitMask = 0xFF};
       
    94 	enum EMaskShiftValues {ESix = 6, EFour = 4, ETwo = 2, EZero = 0};
       
    95 	static const TUint8 iAlphabet[];
       
    96 	TInt iShiftStored;
       
    97 	TInt iMaskShiftStored;
       
    98 	};
       
    99 
       
   100 #endif // __BASE64_H__