os/security/cryptoservices/certificateandkeymgmt/swicertstore/CSWICertStore.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
/*
sl@0
     2
* Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     3
* All rights reserved.
sl@0
     4
* This component and the accompanying materials are made available
sl@0
     5
* under the terms of the License "Eclipse Public License v1.0"
sl@0
     6
* which accompanies this distribution, and is available
sl@0
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     8
*
sl@0
     9
* Initial Contributors:
sl@0
    10
* Nokia Corporation - initial contribution.
sl@0
    11
*
sl@0
    12
* Contributors:
sl@0
    13
*
sl@0
    14
* Description: 
sl@0
    15
*
sl@0
    16
*/
sl@0
    17
sl@0
    18
sl@0
    19
#include <swicertstore.h>
sl@0
    20
#include "CSWICertStoreImpl.h"
sl@0
    21
#include "CSWICertStoreToken.h"
sl@0
    22
#include "CSWICertStoreTokenType.h"
sl@0
    23
sl@0
    24
_LIT(KSWICertStorePanic, "CSWICertStore");
sl@0
    25
sl@0
    26
EXPORT_C CCTTokenType* CSWICertStore::CreateTokenTypeL()
sl@0
    27
	{
sl@0
    28
	// This method is just here so we don't have to declare
sl@0
    29
	// CSWICertStoreTokenType in the exported header
sl@0
    30
	return CSWICertStoreTokenType::NewL();
sl@0
    31
	}
sl@0
    32
sl@0
    33
EXPORT_C CSWICertStore* CSWICertStore::NewL(RFs& aFs)
sl@0
    34
	{
sl@0
    35
	// This method relies on the fact that we know the implementation of the swi
sl@0
    36
	// cert store token type is synchronous
sl@0
    37
sl@0
    38
	// Create token type
sl@0
    39
	MCTTokenType* tokenType = CSWICertStoreTokenType::NewL(aFs);
sl@0
    40
	CleanupReleasePushL(*tokenType);
sl@0
    41
sl@0
    42
	// Open token
sl@0
    43
	TRequestStatus stat;
sl@0
    44
	MCTToken* token = NULL;
sl@0
    45
	TUid tokenTypeUid = { KSWICertStoreTokenTypeUid };
sl@0
    46
	TCTTokenHandle tokenHandle(tokenTypeUid, CSWICertStoreTokenType::ESWICertStore);
sl@0
    47
	tokenType->OpenToken(tokenHandle, token, stat);
sl@0
    48
	User::WaitForRequest(stat);
sl@0
    49
	User::LeaveIfError(stat.Int());
sl@0
    50
	CleanupReleasePushL(*token);
sl@0
    51
sl@0
    52
	// Get interface
sl@0
    53
	MCTTokenInterface* tokenIf = NULL;
sl@0
    54
	token->GetInterface(TUid::Uid(KInterfaceCertStore), tokenIf, stat);
sl@0
    55
	User::WaitForRequest(stat);
sl@0
    56
	User::LeaveIfError(stat.Int());
sl@0
    57
	
sl@0
    58
	__ASSERT_ALWAYS(tokenIf, User::Panic(KSWICertStorePanic, 1));
sl@0
    59
sl@0
    60
	// Release token and token type
sl@0
    61
	CleanupStack::PopAndDestroy(2, tokenType);
sl@0
    62
sl@0
    63
	return static_cast<CSWICertStore*>(tokenIf);
sl@0
    64
	}
sl@0
    65
sl@0
    66
CSWICertStore* CSWICertStore::NewL(CSWICertStoreToken& aToken, RFs& aFs)
sl@0
    67
	{
sl@0
    68
	CSWICertStore* self = new (ELeave) CSWICertStore(aToken);
sl@0
    69
	CleanupStack::PushL(self);
sl@0
    70
	self->ConstructL(aFs);
sl@0
    71
	CleanupStack::Pop(self);
sl@0
    72
	return self;
sl@0
    73
	}
sl@0
    74
sl@0
    75
CSWICertStore::CSWICertStore(CSWICertStoreToken& aToken) :
sl@0
    76
	iToken(aToken)
sl@0
    77
	{
sl@0
    78
	}
sl@0
    79
sl@0
    80
void CSWICertStore::ConstructL(RFs& aFs)
sl@0
    81
	{
sl@0
    82
	iImpl = CSWICertStoreImpl::NewL(iToken, aFs);
sl@0
    83
	}
sl@0
    84
sl@0
    85
void CSWICertStore::DoRelease()
sl@0
    86
	{
sl@0
    87
	if (iToken.ReleaseInterface())
sl@0
    88
		{
sl@0
    89
		delete this;
sl@0
    90
		}
sl@0
    91
	}
sl@0
    92
sl@0
    93
CSWICertStore::~CSWICertStore()
sl@0
    94
	{
sl@0
    95
	delete iImpl;
sl@0
    96
	}
sl@0
    97
sl@0
    98
MCTToken& CSWICertStore::Token()
sl@0
    99
	{
sl@0
   100
	return iToken;
sl@0
   101
	}
sl@0
   102
sl@0
   103
void CSWICertStore::List(RMPointerArray<CCTCertInfo>& aCerts,
sl@0
   104
						 const CCertAttributeFilter& aFilter,
sl@0
   105
						 TRequestStatus& aStatus)
sl@0
   106
	{
sl@0
   107
	TRAPD(err, iImpl->ListL(aCerts, aFilter));
sl@0
   108
	TRequestStatus* status = &aStatus;
sl@0
   109
	User::RequestComplete(status, err);
sl@0
   110
	}
sl@0
   111
sl@0
   112
void CSWICertStore::CancelList()
sl@0
   113
	{
sl@0
   114
	}
sl@0
   115
sl@0
   116
void CSWICertStore::GetCert(CCTCertInfo*& aCertInfo,
sl@0
   117
							const TCTTokenObjectHandle& aHandle, 
sl@0
   118
							TRequestStatus& aStatus)
sl@0
   119
	{
sl@0
   120
	TRAPD(err, aCertInfo = iImpl->GetCertL(aHandle));
sl@0
   121
	TRequestStatus* status = &aStatus;
sl@0
   122
	User::RequestComplete(status, err);
sl@0
   123
	}
sl@0
   124
		
sl@0
   125
void CSWICertStore::CancelGetCert()
sl@0
   126
	{
sl@0
   127
	}
sl@0
   128
sl@0
   129
void CSWICertStore::Applications(const CCTCertInfo& aCertInfo,
sl@0
   130
								 RArray<TUid>& aApplications,
sl@0
   131
								 TRequestStatus& aStatus)
sl@0
   132
	{
sl@0
   133
	TRAPD(err, iImpl->ApplicationsL(aCertInfo.Handle(), aApplications));
sl@0
   134
	TRequestStatus* status = &aStatus;
sl@0
   135
	User::RequestComplete(status, err);
sl@0
   136
	}
sl@0
   137
sl@0
   138
void CSWICertStore::CancelApplications()
sl@0
   139
	{
sl@0
   140
	}
sl@0
   141
sl@0
   142
void CSWICertStore::IsApplicable(const CCTCertInfo& aCertInfo,
sl@0
   143
								 TUid aApplication, 
sl@0
   144
								 TBool& aIsApplicable,
sl@0
   145
								 TRequestStatus& aStatus)
sl@0
   146
	{
sl@0
   147
	TRAPD(err, aIsApplicable = iImpl->IsApplicableL(aCertInfo.Handle(), aApplication));
sl@0
   148
	TRequestStatus* status = &aStatus;
sl@0
   149
	User::RequestComplete(status, err);
sl@0
   150
	}
sl@0
   151
sl@0
   152
void CSWICertStore::CancelIsApplicable()
sl@0
   153
	{
sl@0
   154
	}
sl@0
   155
sl@0
   156
void CSWICertStore::Trusted(const CCTCertInfo& aCertInfo,
sl@0
   157
							TBool& aTrusted, 
sl@0
   158
							TRequestStatus& aStatus)
sl@0
   159
	{
sl@0
   160
	TRAPD(err, aTrusted = iImpl->TrustedL(aCertInfo.Handle()));
sl@0
   161
	TRequestStatus* status = &aStatus;
sl@0
   162
	User::RequestComplete(status, err);
sl@0
   163
	}
sl@0
   164
sl@0
   165
void CSWICertStore::CancelTrusted()
sl@0
   166
	{
sl@0
   167
	}
sl@0
   168
sl@0
   169
void CSWICertStore::Retrieve(const CCTCertInfo& aCertInfo,
sl@0
   170
							 TDes8& aEncodedCert, 
sl@0
   171
							 TRequestStatus& aStatus)
sl@0
   172
	{
sl@0
   173
	TRAPD(err, iImpl->RetrieveL(aCertInfo.Handle(), aEncodedCert));
sl@0
   174
	TRequestStatus* status = &aStatus;
sl@0
   175
	User::RequestComplete(status, err);
sl@0
   176
	}
sl@0
   177
sl@0
   178
void CSWICertStore::CancelRetrieve()
sl@0
   179
	{
sl@0
   180
	}
sl@0
   181
sl@0
   182
EXPORT_C const TCertMetaInfo& CSWICertStore::CertMetaInfoL(const CCTCertInfo& aCertInfo)
sl@0
   183
	{
sl@0
   184
	return iImpl->CertMetaInfoL(aCertInfo.Handle());
sl@0
   185
	}
sl@0
   186
sl@0
   187