pkiutilities/DeviceToken/Inc/DevCertKeyDataManager.h
changeset 0 164170e6151a
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2006 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:   The header file of DevCertKeyDataManager
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #ifndef __DEVCERTKEYDATAMANAGER_H__
       
    21 #define __DEVCERTKEYDATAMANAGER_H__
       
    22 
       
    23 #include <s32file.h>
       
    24 #include <ct/tcttokenobjecthandle.h>
       
    25 #include <ct.h>
       
    26 
       
    27 class CDevTokenKeyInfo;
       
    28 
       
    29 /**
       
    30  *  class CDevCertKeyData
       
    31  *
       
    32  * Server side in-memory representation of a key for file key store management
       
    33  * purposes. Objects of this type are stored in an in-memory array for quick
       
    34  * keystore lookup
       
    35  *
       
    36  *  @lib
       
    37  *  @since S60 v3.2
       
    38  */
       
    39 class CDevCertKeyData : public CBase
       
    40     {
       
    41     public:
       
    42         
       
    43         // Create a new key data object
       
    44         static CDevCertKeyData* NewLC(TInt aObjectId, const TDesC& aLabel, TStreamId aInfoData,
       
    45         
       
    46         TStreamId aPublicData, TStreamId aPrivateData);
       
    47         
       
    48         // Read a key data object from a stream
       
    49         static CDevCertKeyData* NewL(RStoreReadStream& aReadStream);
       
    50         
       
    51     public:
       
    52         
       
    53         ~CDevCertKeyData(); 
       
    54         
       
    55     public:
       
    56         
       
    57         // Write out the key data to a stream
       
    58         void ExternalizeL(RWriteStream&) const;
       
    59         
       
    60     public:
       
    61         
       
    62         inline const TDesC& Label() const;
       
    63         
       
    64         inline TInt32 Handle() const;
       
    65         
       
    66         inline TStreamId InfoDataStreamId() const;
       
    67         
       
    68         inline TStreamId PublicDataStreamId() const;
       
    69         
       
    70         inline TStreamId PrivateDataStreamId() const;
       
    71         
       
    72     private:
       
    73         
       
    74         CDevCertKeyData(TInt aObjectId, TStreamId aInfoData,
       
    75         
       
    76         TStreamId aPublicData, TStreamId aPrivateData);
       
    77         
       
    78         CDevCertKeyData();
       
    79         
       
    80         void ConstructL(const TDesC& aLabel);
       
    81         
       
    82         void InternalizeL(RReadStream&);
       
    83         
       
    84     private:
       
    85         
       
    86         TInt iObjectId;       // Data to identify the key
       
    87         
       
    88         TStreamId iInfoData;    // ID of stream holding publicly available data for key 
       
    89         
       
    90         TStreamId iPublicKeyData; // ID of stream holding public key data
       
    91         
       
    92         TStreamId iPrivateKeyData;  // ID of stream holding private key data
       
    93         
       
    94         HBufC* iLabel;        // Key label data
       
    95     };
       
    96 
       
    97 inline const TDesC& CDevCertKeyData::Label() const
       
    98     {
       
    99     return *iLabel;
       
   100     }
       
   101 
       
   102 inline TInt32 CDevCertKeyData::Handle() const
       
   103     {
       
   104     return iObjectId;
       
   105     }
       
   106 
       
   107 inline TStreamId CDevCertKeyData::InfoDataStreamId() const
       
   108     {
       
   109     return iInfoData;
       
   110     }
       
   111 
       
   112 inline TStreamId CDevCertKeyData::PublicDataStreamId() const
       
   113     {
       
   114     return iPublicKeyData;
       
   115     }
       
   116 
       
   117 inline TStreamId CDevCertKeyData::PrivateDataStreamId() const
       
   118     {
       
   119     return iPrivateKeyData;
       
   120     }
       
   121 
       
   122 
       
   123 /**
       
   124  *  class CDevCertKeyDataManager
       
   125  *
       
   126  * Access the server file store of all keys and key data. The only class to
       
   127  * access the store, which maintains store integrity When a new key is created,
       
   128  * it is represented by a CDevCertKeyData object and added to the array.  
       
   129  *
       
   130  *  @lib
       
   131  *  @since S60 v3.2
       
   132  */
       
   133 class CDevCertKeyDataManager : public CBase
       
   134     {
       
   135     public:
       
   136         
       
   137         static CDevCertKeyDataManager* NewL();
       
   138         
       
   139         ~CDevCertKeyDataManager();
       
   140         
       
   141     public: 
       
   142         
       
   143         void AddL(const CDevCertKeyData*);
       
   144         
       
   145         void RemoveL(TInt aObjectId);
       
   146         
       
   147         TBool IsKeyAlreadyInStore(const TDesC& aKeyLabel) const;
       
   148         
       
   149     public:
       
   150         
       
   151         // Create a new key data object for a key create/import and leave it one the cleanup stack
       
   152         const CDevCertKeyData* CreateKeyDataLC( const TDesC& aLabel );
       
   153         
       
   154         // Reads the info data for a given key, returning a new CKeyInfo that's on the cleanup stack
       
   155         CDevTokenKeyInfo* ReadKeyInfoLC(const CDevCertKeyData& aKeyData) const;
       
   156         
       
   157         // Writes key info data for a key
       
   158         void WriteKeyInfoL(const CDevCertKeyData& aKeyData, const CDevTokenKeyInfo& aKeyInfo);
       
   159         
       
   160         // Writes key info data and reverts changes to the store if if leaves
       
   161         void SafeWriteKeyInfoL(const CDevCertKeyData& aKeyData, const CDevTokenKeyInfo& aKeyInfo);
       
   162         
       
   163         // Methods for opening data streams for a key
       
   164         void OpenPublicDataStreamLC(const CDevCertKeyData& aKeyData, RStoreWriteStream& aStream);
       
   165         
       
   166         void OpenPublicDataStreamLC(const CDevCertKeyData& aKeyData, RStoreReadStream& aStream) const;
       
   167         
       
   168         void OpenPrivateDataStreamLC(const CDevCertKeyData& aKeyData, RStoreWriteStream& aStream);
       
   169         
       
   170         void OpenPrivateDataStreamLC(const CDevCertKeyData& aKeyData, RStoreReadStream& aStream);
       
   171 
       
   172     public:
       
   173         
       
   174         TInt Count() const;
       
   175         
       
   176         const CDevCertKeyData* operator[](TInt aIndex) const;
       
   177         
       
   178         const CDevCertKeyData* Lookup(TInt aObjectId) const;
       
   179 
       
   180     private:
       
   181         
       
   182         CDevCertKeyDataManager();
       
   183         
       
   184         void ConstructL();
       
   185         
       
   186     private:                      //  Manages access to store
       
   187         
       
   188         void OpenStoreL();
       
   189         
       
   190         void OpenStoreInFileL(const TDesC& aFile);
       
   191         
       
   192         void CreateStoreInFileL(const TDesC& aFile);
       
   193         
       
   194     private:
       
   195         
       
   196         void OpenInfoDataStreamLC(const CDevCertKeyData& aKeyData, RStoreWriteStream&);
       
   197         
       
   198         static void RevertStore(TAny* aStore);      //  Cleanupitem
       
   199         
       
   200         void WriteKeysToStoreL();
       
   201         
       
   202         TStreamId CreateWriteStreamL();
       
   203         
       
   204         void CompactStore();
       
   205         
       
   206     private:
       
   207         
       
   208         RFile iFile;
       
   209         
       
   210         RFs iFs;
       
   211         
       
   212         CPermanentFileStore* iFileStore;
       
   213         
       
   214         TStreamId iRootStreamId;      // Root of the store
       
   215         
       
   216         TStreamId iInfoStreamId;      // Stream that contains list of key data
       
   217 
       
   218     private:
       
   219         
       
   220         TInt iKeyIdentifier;
       
   221         
       
   222         RPointerArray<const CDevCertKeyData> iKeys; // In memory representation of keys in the store
       
   223     };
       
   224 
       
   225 #endif
       
   226 
       
   227 //EOF
       
   228