javaextensions/pim/framework/inc.s60/pimbase64converter.h
branchRCL_3
changeset 19 04becd199f91
equal deleted inserted replaced
16:f5050f1da672 19:04becd199f91
       
     1 /*
       
     2 * Copyright (c) 2008 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 "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:  Description
       
    15  *
       
    16 */
       
    17 
       
    18 
       
    19 #ifndef PIMBASE64CONVERTER_H
       
    20 #define PIMBASE64CONVERTER_H
       
    21 
       
    22 //  INCLUDES
       
    23 #include "pimcommon.h"
       
    24 
       
    25 // CLASS DECLARATION
       
    26 
       
    27 /**
       
    28  *  Base64 coder and decoder.
       
    29  *
       
    30  *  Base64 encoding is defined in IETF RFC 2045.
       
    31  *
       
    32  *  Base64 encoding is identical to the "B" binary encoding, defined in
       
    33  *  IETF RFC 2047 (which merely refers to RFC 2045).
       
    34  */
       
    35 NONSHARABLE_CLASS(PIMBase64Converter)
       
    36 {
       
    37 public: // New functions
       
    38 
       
    39     /**
       
    40      * Encodes given byte array to base64 representation.
       
    41      *
       
    42      * @param aSource Source bytes.
       
    43      *
       
    44      * @return Target bytes.
       
    45      *         \b Ownership of the return value is transferred to caller.
       
    46      */
       
    47     static CPIMByteArray* EncodeBase64L(const CPIMByteArray& aSource);
       
    48 
       
    49     /**
       
    50      * Decodes given byte array from base64 representation.
       
    51      *
       
    52      * @param aSource Source bytes.
       
    53      *
       
    54      * @return Target bytes.
       
    55      *         \b Ownership of the return value is transferred to caller.
       
    56      */
       
    57     static CPIMByteArray* DecodeBase64L(const CPIMByteArray& aSource);
       
    58 
       
    59 private: // New functions
       
    60 
       
    61     /**
       
    62      * Base64 encodes \a aQuantum and appends resulting bytes to
       
    63      * \a aToArray.
       
    64      *
       
    65      * @param aNumSourceBytes Number of (8 bit) source bytes, 0 to 3.
       
    66      *        If the number is 3, full quantum is encoded. If the number is
       
    67      *        1 or 2, partial quantum is encoded and missing bytes are
       
    68      *        fillied with pad byte. If the number is 0, nothing is done.
       
    69      *
       
    70      * @par Leaving:
       
    71      * @li \c KErrArgument - \aNumSourceBytes is invalid. On debug builds
       
    72      *     a panic is raised instead.
       
    73      */
       
    74     static void EncodeQuantumL(
       
    75         const TUint32& aQuantum,
       
    76         CPIMByteArray& aTargetArray,
       
    77         const TInt& aNumSourceBytes);
       
    78 
       
    79     /**
       
    80      * Base64 decodes \a aQuantum and appends resulting bytes to
       
    81      * \a aToArray. The quantum must contain 24 bits (four 6 bit source
       
    82      * bytes).
       
    83      *
       
    84      * @par Leaving:
       
    85      * @li \c KErrArgument - \aNumSourceBytes is invalid. On debug builds
       
    86      *     a panic is raised instead.
       
    87      */
       
    88     static void DecodeQuantumL(const TUint32& aQuantum,
       
    89                                CPIMByteArray& aTargetArray, const TInt& aNumSourceBytes);
       
    90 
       
    91     /**
       
    92      * Maps \a aByte to a character in the base64 alphabet.
       
    93      *
       
    94      * @return \a aByte mapped to a character in the base64 alphabet.
       
    95      */
       
    96     static TUint8 ByteToBase64Letter(const TUint8& aByte);
       
    97 
       
    98     /**
       
    99      * Maps \a aLetter (in the base64 alphabet) to a byte. Does not match
       
   100      * the pad byte.
       
   101      *
       
   102      * @return \a aLetter (in the base64 alphabet) mapped to a byte or
       
   103      *         KNonBase64Letter if the letter does not belong to the base64
       
   104      *         alphabet.
       
   105      */
       
   106     static TUint8 Base64LetterToByte(const TUint8& aLetter);
       
   107 
       
   108 private:
       
   109 
       
   110     /**
       
   111      * C++ default constructor.
       
   112      * The class is non-instantiable.
       
   113      */
       
   114     PIMBase64Converter();
       
   115 
       
   116     /**
       
   117      * Destructor.
       
   118      */
       
   119     ~PIMBase64Converter();
       
   120 
       
   121 };
       
   122 
       
   123 #endif // PIMBASE64CONVERTER_H
       
   124 // End of File