cryptoservices/certificateandkeymgmt/swicertstore/CSWICertStore.cpp
changeset 0 2c201484c85f
child 8 35751d3474b7
equal deleted inserted replaced
-1:000000000000 0:2c201484c85f
       
     1 /*
       
     2 * Copyright (c) 2004-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 
       
    19 #include <swicertstore.h>
       
    20 #include "CSWICertStoreImpl.h"
       
    21 #include "CSWICertStoreToken.h"
       
    22 #include "CSWICertStoreTokenType.h"
       
    23 
       
    24 _LIT(KSWICertStorePanic, "CSWICertStore");
       
    25 
       
    26 EXPORT_C CCTTokenType* CSWICertStore::CreateTokenTypeL()
       
    27 	{
       
    28 	// This method is just here so we don't have to declare
       
    29 	// CSWICertStoreTokenType in the exported header
       
    30 	return CSWICertStoreTokenType::NewL();
       
    31 	}
       
    32 
       
    33 EXPORT_C CSWICertStore* CSWICertStore::NewL(RFs& aFs)
       
    34 	{
       
    35 	// This method relies on the fact that we know the implementation of the swi
       
    36 	// cert store token type is synchronous
       
    37 
       
    38 	// Create token type
       
    39 	MCTTokenType* tokenType = CSWICertStoreTokenType::NewL(aFs);
       
    40 	CleanupReleasePushL(*tokenType);
       
    41 
       
    42 	// Open token
       
    43 	TRequestStatus stat;
       
    44 	MCTToken* token = NULL;
       
    45 	TUid tokenTypeUid = { KSWICertStoreTokenTypeUid };
       
    46 	TCTTokenHandle tokenHandle(tokenTypeUid, CSWICertStoreTokenType::ESWICertStore);
       
    47 	tokenType->OpenToken(tokenHandle, token, stat);
       
    48 	User::WaitForRequest(stat);
       
    49 	User::LeaveIfError(stat.Int());
       
    50 	CleanupReleasePushL(*token);
       
    51 
       
    52 	// Get interface
       
    53 	MCTTokenInterface* tokenIf = NULL;
       
    54 	token->GetInterface(TUid::Uid(KInterfaceCertStore), tokenIf, stat);
       
    55 	User::WaitForRequest(stat);
       
    56 	User::LeaveIfError(stat.Int());
       
    57 	
       
    58 	__ASSERT_ALWAYS(tokenIf, User::Panic(KSWICertStorePanic, 1));
       
    59 
       
    60 	// Release token and token type
       
    61 	CleanupStack::PopAndDestroy(2, tokenType);
       
    62 
       
    63 	return static_cast<CSWICertStore*>(tokenIf);
       
    64 	}
       
    65 
       
    66 CSWICertStore* CSWICertStore::NewL(CSWICertStoreToken& aToken, RFs& aFs)
       
    67 	{
       
    68 	CSWICertStore* self = new (ELeave) CSWICertStore(aToken);
       
    69 	CleanupStack::PushL(self);
       
    70 	self->ConstructL(aFs);
       
    71 	CleanupStack::Pop(self);
       
    72 	return self;
       
    73 	}
       
    74 
       
    75 CSWICertStore::CSWICertStore(CSWICertStoreToken& aToken) :
       
    76 	iToken(aToken)
       
    77 	{
       
    78 	}
       
    79 
       
    80 void CSWICertStore::ConstructL(RFs& aFs)
       
    81 	{
       
    82 	iImpl = CSWICertStoreImpl::NewL(iToken, aFs);
       
    83 	}
       
    84 
       
    85 void CSWICertStore::DoRelease()
       
    86 	{
       
    87 	if (iToken.ReleaseInterface())
       
    88 		{
       
    89 		delete this;
       
    90 		}
       
    91 	}
       
    92 
       
    93 CSWICertStore::~CSWICertStore()
       
    94 	{
       
    95 	delete iImpl;
       
    96 	}
       
    97 
       
    98 MCTToken& CSWICertStore::Token()
       
    99 	{
       
   100 	return iToken;
       
   101 	}
       
   102 
       
   103 void CSWICertStore::List(RMPointerArray<CCTCertInfo>& aCerts,
       
   104 						 const CCertAttributeFilter& aFilter,
       
   105 						 TRequestStatus& aStatus)
       
   106 	{
       
   107 	TRAPD(err, iImpl->ListL(aCerts, aFilter));
       
   108 	TRequestStatus* status = &aStatus;
       
   109 	User::RequestComplete(status, err);
       
   110 	}
       
   111 
       
   112 void CSWICertStore::CancelList()
       
   113 	{
       
   114 	}
       
   115 
       
   116 void CSWICertStore::GetCert(CCTCertInfo*& aCertInfo,
       
   117 							const TCTTokenObjectHandle& aHandle, 
       
   118 							TRequestStatus& aStatus)
       
   119 	{
       
   120 	TRAPD(err, aCertInfo = iImpl->GetCertL(aHandle));
       
   121 	TRequestStatus* status = &aStatus;
       
   122 	User::RequestComplete(status, err);
       
   123 	}
       
   124 		
       
   125 void CSWICertStore::CancelGetCert()
       
   126 	{
       
   127 	}
       
   128 
       
   129 void CSWICertStore::Applications(const CCTCertInfo& aCertInfo,
       
   130 								 RArray<TUid>& aApplications,
       
   131 								 TRequestStatus& aStatus)
       
   132 	{
       
   133 	TRAPD(err, iImpl->ApplicationsL(aCertInfo.Handle(), aApplications));
       
   134 	TRequestStatus* status = &aStatus;
       
   135 	User::RequestComplete(status, err);
       
   136 	}
       
   137 
       
   138 void CSWICertStore::CancelApplications()
       
   139 	{
       
   140 	}
       
   141 
       
   142 void CSWICertStore::IsApplicable(const CCTCertInfo& aCertInfo,
       
   143 								 TUid aApplication, 
       
   144 								 TBool& aIsApplicable,
       
   145 								 TRequestStatus& aStatus)
       
   146 	{
       
   147 	TRAPD(err, aIsApplicable = iImpl->IsApplicableL(aCertInfo.Handle(), aApplication));
       
   148 	TRequestStatus* status = &aStatus;
       
   149 	User::RequestComplete(status, err);
       
   150 	}
       
   151 
       
   152 void CSWICertStore::CancelIsApplicable()
       
   153 	{
       
   154 	}
       
   155 
       
   156 void CSWICertStore::Trusted(const CCTCertInfo& aCertInfo,
       
   157 							TBool& aTrusted, 
       
   158 							TRequestStatus& aStatus)
       
   159 	{
       
   160 	TRAPD(err, aTrusted = iImpl->TrustedL(aCertInfo.Handle()));
       
   161 	TRequestStatus* status = &aStatus;
       
   162 	User::RequestComplete(status, err);
       
   163 	}
       
   164 
       
   165 void CSWICertStore::CancelTrusted()
       
   166 	{
       
   167 	}
       
   168 
       
   169 void CSWICertStore::Retrieve(const CCTCertInfo& aCertInfo,
       
   170 							 TDes8& aEncodedCert, 
       
   171 							 TRequestStatus& aStatus)
       
   172 	{
       
   173 	TRAPD(err, iImpl->RetrieveL(aCertInfo.Handle(), aEncodedCert));
       
   174 	TRequestStatus* status = &aStatus;
       
   175 	User::RequestComplete(status, err);
       
   176 	}
       
   177 
       
   178 void CSWICertStore::CancelRetrieve()
       
   179 	{
       
   180 	}
       
   181 
       
   182 EXPORT_C const TCertMetaInfo& CSWICertStore::CertMetaInfoL(const CCTCertInfo& aCertInfo)
       
   183 	{
       
   184 	return iImpl->CertMetaInfoL(aCertInfo.Handle());
       
   185 	}