wim/WimPlugin/src/WimCertStoreMappings.cpp
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2002 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 implementation represents an array of mapping entries 
       
    15 *               (certificate infos) with trusted settings
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 
       
    22 #include "WimCertStoreMappings.h"
       
    23 #include "WimTrace.h"
       
    24 //#include "WimDebug.h"
       
    25 
       
    26 // ============================ MEMBER FUNCTIONS ===============================
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // CWimCertStoreMappings::NewL()
       
    30 // Two-phased constructor
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 CWimCertStoreMappings* CWimCertStoreMappings::NewL()
       
    34     {
       
    35     _WIMTRACE ( _L( "CWimCertStoreMappings::NewL()" ) );
       
    36     CWimCertStoreMappings* self = new( ELeave ) CWimCertStoreMappings();
       
    37     CleanupStack::PushL( self );
       
    38     self->ConstructL();
       
    39     CleanupStack::Pop( self );
       
    40     return self;
       
    41     }
       
    42 
       
    43 // -----------------------------------------------------------------------------
       
    44 // CWimCertStoreMappings::CWimCertStoreMappings()
       
    45 // Default constructor
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 CWimCertStoreMappings::CWimCertStoreMappings()
       
    49     {
       
    50     }
       
    51 
       
    52 // -----------------------------------------------------------------------------
       
    53 // CWimCertStoreMappings::ConstructL()
       
    54 // Second phase constructor
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 void CWimCertStoreMappings::ConstructL()
       
    58     {
       
    59     }
       
    60 
       
    61 // -----------------------------------------------------------------------------
       
    62 // CWimCertStoreMappings::~CWimCertStoreMappings()
       
    63 // Destructor. 
       
    64 // -----------------------------------------------------------------------------
       
    65 //
       
    66 CWimCertStoreMappings::~CWimCertStoreMappings()
       
    67     {
       
    68     _WIMTRACE ( _L( "CWimCertStoreMappings::~CWimCertStoreMappings()" ) );
       
    69     iMappings.ResetAndDestroy();
       
    70     }
       
    71 
       
    72 // -----------------------------------------------------------------------------
       
    73 // CWimCertStoreMappings::Count()
       
    74 // Returns the count of mapping entries from the internal array.
       
    75 // -----------------------------------------------------------------------------
       
    76 //
       
    77 TInt CWimCertStoreMappings::Count() const
       
    78     {
       
    79     return iMappings.Count();
       
    80     }
       
    81 
       
    82 // -----------------------------------------------------------------------------
       
    83 // CWimCertStoreMappings::AddL()
       
    84 // Adds an mapping entry to the internal array.
       
    85 // -----------------------------------------------------------------------------
       
    86 //
       
    87 void CWimCertStoreMappings::AddL( const CWimCertStoreMapping* aEntry )
       
    88     {
       
    89     _WIMTRACE ( _L( "CWimCertStoreMappings::AddL()" ) );
       
    90     User::LeaveIfError( iMappings.Append( aEntry ) );
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // CWimCertStoreMappings::Index()
       
    95 // Returns the index of mapping entry from the internal array using given
       
    96 // certificate info.
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 TInt CWimCertStoreMappings::Index( const CCTCertInfo& aCertInfo )
       
   100     {
       
   101     _WIMTRACE ( _L( "CWimCertStoreMappings::Index()" ) );
       
   102     TInt count = iMappings.Count();
       
   103     TInt ix = KErrNotFound;
       
   104     for ( TInt i = 0; i < count; i++ )
       
   105         {
       
   106         CWimCertStoreMapping* mapping = ( iMappings )[i];
       
   107         if ( aCertInfo == *( mapping->Entry() ) )
       
   108             {
       
   109             ix = i;
       
   110             i = count; // End this loop
       
   111             }
       
   112         }
       
   113     return ix;
       
   114     }
       
   115 
       
   116 // -----------------------------------------------------------------------------
       
   117 // CWimCertStoreMapping* CWimCertStoreMappings::Mapping()
       
   118 // Returns the mapping entry from the internal array using given index
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 CWimCertStoreMapping* CWimCertStoreMappings::Mapping( TInt aIndex )
       
   122     {
       
   123     _WIMTRACE ( _L( "CWimCertStoreMappings::Mapping()" ) );
       
   124     return ( iMappings )[aIndex];
       
   125     }
       
   126 
       
   127 // -----------------------------------------------------------------------------
       
   128 // CCTCertInfo& CWimCertStoreMappings::Entry()
       
   129 // Returns the certificate info from mapping entry using given index
       
   130 // -----------------------------------------------------------------------------
       
   131 //
       
   132 const CCTCertInfo& CWimCertStoreMappings::Entry( TInt aIndex )
       
   133     {
       
   134     _WIMTRACE ( _L( "CWimCertStoreMappings::Entry()" ) );
       
   135     CWimCertStoreMapping* mapping = ( iMappings )[aIndex];
       
   136     return *mapping->Entry();
       
   137     }
       
   138 
       
   139 // -----------------------------------------------------------------------------
       
   140 // CCTCertInfo& CWimCertStoreMappings::EntryByHandleL()
       
   141 // Returns the certificate info from the mapping entry using given handle
       
   142 // -----------------------------------------------------------------------------
       
   143 //
       
   144 const CCTCertInfo& CWimCertStoreMappings::EntryByHandleL( TInt aHandle ) const
       
   145     {
       
   146     _WIMTRACE ( _L( "CWimCertStoreMappings::EntryByHandleL()" ) );
       
   147     CCTCertInfo* info = NULL;
       
   148     TInt count = iMappings.Count();
       
   149     for ( TInt i = 0; i < count; i++ )
       
   150         {
       
   151         CWimCertStoreMapping* mapping = ( iMappings )[i];
       
   152         if ( aHandle == mapping->Entry()->Handle().iObjectId )
       
   153             {
       
   154             info = mapping->Entry();
       
   155             i = count; // End this loop
       
   156             }
       
   157         }
       
   158     if ( !info )
       
   159         {
       
   160         User::Leave( KErrNotFound );
       
   161         }
       
   162     return *info;
       
   163     }
       
   164 
       
   165 // End of file