appinstaller/AppinstUi/Plugin/CommonUI/Src/CUICertificateDetailsDialog.cpp
changeset 0 ba25891c3a9e
child 44 329d304c1aa1
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2002-2004 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:   This file contains the implementation of 
       
    15 *                CCUICertificateDetailsDialog class member functions.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include <aknmessagequerydialog.h>
       
    22 #include <StringLoader.h>
       
    23 #include <SWInstCommonUI.rsg>
       
    24 #include <AknUtils.h>
       
    25 #include <hash.h>                  
       
    26 
       
    27 #include "CUICertificateDetailsDialog.h"
       
    28 #include "CUIDetailsDialog.h"
       
    29 
       
    30 using namespace SwiUI::CommonUI;
       
    31 
       
    32 // CONSTANTS
       
    33 _LIT( KNextLine, "\n" );
       
    34 _LIT( KNextNextLine, "\n\n" );
       
    35 _LIT( KHexFormat, "%02X" );
       
    36 const TInt KMaxLengthTextSerialNumberFormatting = 3;
       
    37 
       
    38 
       
    39 // ============================ MEMBER FUNCTIONS ===============================
       
    40 
       
    41 // -----------------------------------------------------------------------------
       
    42 // CCUICertificateDetailsDialog::CCUICertificateDetailsDialog
       
    43 // C++ default constructor can NOT contain any code, that
       
    44 // might leave.
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 CCUICertificateDetailsDialog::CCUICertificateDetailsDialog()
       
    48     {
       
    49     }
       
    50 
       
    51 // -----------------------------------------------------------------------------
       
    52 // CCUICertificateDetailsDialog::ConstructL
       
    53 // Symbian 2nd phase constructor can leave.
       
    54 // -----------------------------------------------------------------------------
       
    55 //
       
    56 void CCUICertificateDetailsDialog::ConstructL()
       
    57     {
       
    58    
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CCUICertificateDetailsDialog::NewL
       
    63 // Two-phased constructor.
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CCUICertificateDetailsDialog* CCUICertificateDetailsDialog::NewL()
       
    67 
       
    68     {
       
    69     CCUICertificateDetailsDialog* self = new ( ELeave ) CCUICertificateDetailsDialog();
       
    70     CleanupStack::PushL( self );
       
    71     self->ConstructL();
       
    72     CleanupStack::Pop( self );
       
    73     return self; 
       
    74     }
       
    75 
       
    76 // Destructor
       
    77 CCUICertificateDetailsDialog::~CCUICertificateDetailsDialog()
       
    78     {
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // CCUICertificateDetailsDialog::AddFieldLC
       
    83 // Adds a field (header and value) to the dialog.
       
    84 // (other items were commented in a header).
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 void CCUICertificateDetailsDialog::AddFieldLC( HBufC*& aMessage,
       
    88                                                TInt aHeaderResourceId,
       
    89                                                const TDesC& aValue )
       
    90     {
       
    91     HBufC* headerString = StringLoader::LoadLC( aHeaderResourceId );
       
    92     HBufC* newMessage;
       
    93     
       
    94     if ( aMessage->Length() > 0 )
       
    95         {
       
    96         newMessage = HBufC::NewL( headerString->Length() +
       
    97 	                          aValue.Length() +
       
    98                                   aMessage->Length() + 
       
    99                                   3 ); // \n\n, \n
       
   100         
       
   101         TPtr ptr( newMessage->Des() );
       
   102         ptr += *aMessage;        
       
   103         ptr += KNextNextLine;        
       
   104         ptr += *headerString;
       
   105         ptr += KNextLine;
       
   106         ptr += aValue;
       
   107         }
       
   108     else
       
   109         {
       
   110         newMessage = HBufC::NewL( headerString->Length() + aValue.Length() + 1 ); // \n
       
   111 
       
   112         TPtr ptr( newMessage->Des() );                
       
   113         ptr += *headerString;
       
   114         ptr += KNextLine;
       
   115         ptr += aValue;
       
   116         }
       
   117 
       
   118     CleanupStack::PopAndDestroy( headerString );
       
   119     CleanupStack::PopAndDestroy( aMessage );  
       
   120   
       
   121     aMessage = newMessage;    
       
   122     CleanupStack::PushL( aMessage );  
       
   123     }
       
   124 
       
   125 // -----------------------------------------------------------------------------
       
   126 // CCUICertificateDetailsDialog::ExecuteLD
       
   127 // Executes the dialog.
       
   128 // (other items were commented in a header).
       
   129 // -----------------------------------------------------------------------------
       
   130 //
       
   131 void CCUICertificateDetailsDialog::ExecuteLD( const CCUICertificateInfo& aCertInfo )
       
   132     {
       
   133     CleanupStack::PushL( this );
       
   134     
       
   135     // Valid from
       
   136     HBufC* validFrom = DateToStringLC( aCertInfo.ValidFromL() );
       
   137 
       
   138     // Valid until
       
   139     HBufC* validTo = DateToStringLC( aCertInfo.ValidToL() );
       
   140     
       
   141     // Serial
       
   142     TPtrC8 serialPtr( aCertInfo.SerialNumberL() );
       
   143     HBufC* serial = HBufC::NewLC( serialPtr.Length() * 2 );
       
   144     TBuf<KMaxLengthTextSerialNumberFormatting> buf;
       
   145     
       
   146     for ( TInt index = 0; index < serialPtr.Length(); index++ )
       
   147         {
       
   148         buf.Format( KHexFormat, serialPtr[index] ); 
       
   149         serial->Des().Append( buf );
       
   150         }
       
   151 
       
   152     // Fingerprint   
       
   153     HBufC* fingerprint = HBufC::NewLC( aCertInfo.FingerprintL().Length() * 5 );
       
   154     DevideToBlocks( aCertInfo.FingerprintL(), fingerprint->Des() );
       
   155     
       
   156     // Fingerprint (MD5)
       
   157     HBufC* fingerprint_md = HBufC::NewLC( aCertInfo.FingerprintL().Length() * 5 );
       
   158     if ( aCertInfo.EncodingL() != KNullDesC8 )
       
   159         {
       
   160     	CMD5* md5 = CMD5::NewL();
       
   161         CleanupStack::PushL( md5 );
       
   162         DevideToBlocks( md5->Hash( aCertInfo.EncodingL() ), fingerprint_md->Des() );
       
   163         CleanupStack::PopAndDestroy( md5 );
       
   164         }
       
   165     
       
   166     HBufC* message = HBufC::NewLC( 0 );
       
   167 
       
   168     // Costruct the fields
       
   169     AddFieldLC( message, R_SWCOMMON_SEC_ISSUER, aCertInfo.IssuerNameL() ); 
       
   170     AddFieldLC( message, R_SWCOMMON_SEC_SUBJECT, aCertInfo.SubjectNameL() );
       
   171     AddFieldLC( message, R_SWCOMMON_SEC_VALID_FROM, *validFrom );
       
   172     AddFieldLC( message, R_SWCOMMON_SEC_VALID_UNTIL, *validTo );
       
   173     AddFieldLC( message, R_SWCOMMON_SEC_SERIAL, *serial );
       
   174     AddFieldLC( message, R_SWCOMMON_SEC_FINGERPRINT, *fingerprint );
       
   175     if ( fingerprint_md->Length() > 0 )
       
   176         {
       
   177     	AddFieldLC( message, R_SWCOMMON_SEC_FINGERPRINT_MD, *fingerprint_md );
       
   178         }
       
   179     
       
   180 
       
   181     // Create and show the message query dialog
       
   182     CAknMessageQueryDialog* dlg = CAknMessageQueryDialog::NewL( *message );
       
   183     dlg->PrepareLC( R_SWCOMMON_SEC_DETAILS_DIALOG );
       
   184     dlg->RunLD();
       
   185 
       
   186     CleanupStack::PopAndDestroy( 7 );  // message, fingerprint_md, fingerprint, serial, validTo, validFrom
       
   187     }
       
   188 
       
   189 // -----------------------------------------------------------------------------
       
   190 // CCUICertificateDetailsDialog::DateToString
       
   191 // Converts date to local format.
       
   192 // (other items were commented in a header).
       
   193 // -----------------------------------------------------------------------------
       
   194 //
       
   195 HBufC* CCUICertificateDetailsDialog::DateToStringLC( const TDateTime& aDate )
       
   196     {
       
   197     // Create date descriptors.
       
   198     // We use Avkon date format string to format the date into correct format.
       
   199     HBufC* dateFormatString = StringLoader::LoadLC( R_QTN_DATE_USUAL_WITH_ZERO );
       
   200     
       
   201     TBuf<30> timeString;    
       
   202     TTime time( aDate );
       
   203         
       
   204     time.FormatL( timeString, *dateFormatString );
       
   205     CleanupStack::PopAndDestroy( dateFormatString );   
       
   206     HBufC* tmp = timeString.AllocLC();
       
   207 
       
   208     TPtr ptr = tmp->Des();
       
   209     AknTextUtils::DisplayTextLanguageSpecificNumberConversion( ptr ); 
       
   210 
       
   211     return tmp;    
       
   212     }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // CCUICertificateDetailsDialog::DevideToBlocks
       
   216 // Devides input descriptor to blocks.
       
   217 // (other items were commented in a header).
       
   218 // -----------------------------------------------------------------------------
       
   219 //
       
   220 void CCUICertificateDetailsDialog::DevideToBlocks( const TDesC8& aInput, TPtr aOutput )
       
   221     {
       
   222     const TInt KBlockLength = 2;    
       
   223     TInt blockIndex = 0;
       
   224     _LIT( KBlockSeparator, " " );
       
   225 
       
   226     for ( TInt index = 0 ; index < aInput.Length() ; index++ )
       
   227         {
       
   228         if ( blockIndex == KBlockLength )
       
   229             {
       
   230             aOutput.Append( KBlockSeparator );
       
   231             blockIndex = 0;
       
   232             }
       
   233         aOutput.AppendNumFixedWidthUC( (TUint)(aInput[index]), EHex, 2 );
       
   234         ++blockIndex;
       
   235         }
       
   236     }
       
   237 //  End of File