Update contrib.
2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
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".
9 * Initial Contributors:
10 * Nokia Corporation - initial contribution.
15 * crypto Mac API implementation
24 #include <cryptospi/cryptomacapi.h>
25 #include <cryptospi/macplugin.h>
26 #include "legacyselector.h"
28 using namespace CryptoSpi;
31 EXPORT_C void CMacFactory::CreateMacL(CMac*& aMac,
32 const TUid aAlgorithmUid,
34 const CCryptoParams* aAlgorithmParams)
36 MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
39 selector->CreateMacL(aMac, aAlgorithmUid, aKey, aAlgorithmParams);
43 CLegacySelector* legacySelector=CLegacySelector::NewLC();
44 legacySelector->CreateMacL(aMac, aAlgorithmUid, aKey, aAlgorithmParams);
45 CleanupStack::PopAndDestroy(legacySelector); //selector
49 CMac* CMac::NewL(MMac* aMac, TInt aHandle)
51 CMac* self = new (ELeave) CMac(aMac, aHandle);
55 CMac::CMac(MMac* aMac, TInt aHandle)
56 : CCryptoBase(aMac, aHandle)
60 EXPORT_C CMac::~CMac()
65 * Following working methods delegate calls to the plug-in implementation
66 * of the requested MAC algorithm.
68 EXPORT_C TPtrC8 CMac::MacL(const TDesC8& aMessage)
70 return ((MMac*)iPlugin)->MacL(aMessage);
74 EXPORT_C void CMac::UpdateL(const TDesC8& aMessage)
76 ((MMac*)iPlugin)->UpdateL(aMessage);
79 EXPORT_C TPtrC8 CMac::FinalL(const TDesC8& aMessage)
81 return ((MMac*)iPlugin)->FinalL(aMessage);
84 EXPORT_C void CMac::ReInitialiseAndSetKeyL(const CKey& aKey)
86 ((MMac*)iPlugin)->ReInitialiseAndSetKeyL(aKey);
89 EXPORT_C CMac* CMac::ReplicateL()
91 MMac* plugin=((MMac*)iPlugin)->ReplicateL();
92 CleanupClosePushL(*plugin);
94 lib.SetHandle(iLibHandle);
96 User::LeaveIfError(duplib.Duplicate(RThread(), EOwnerProcess));
97 CleanupClosePushL(duplib);
98 CMac* self=new(ELeave) CMac(plugin, duplib.Handle());
99 CleanupStack::Pop(2, plugin); //duplib, plugin
103 EXPORT_C CMac* CMac::CopyL()
105 MMac* plugin=((MMac*)iPlugin)->CopyL();
106 CleanupClosePushL(*plugin);
108 lib.SetHandle(iLibHandle);
110 User::LeaveIfError(duplib.Duplicate(RThread(), EOwnerProcess));
111 CleanupClosePushL(duplib);
112 CMac* self=new(ELeave) CMac(plugin, duplib.Handle());
113 CleanupStack::Pop(2, plugin); //duplib, plugin
118 // Asynchronous MAC interface implementation
119 // (async not implemented, so no coverage)
120 // Once we have a dedicated hardware plugin-dll
121 // the following pre-processor conditions must be removed.
123 #ifdef _BullseyeCoverage
124 #pragma suppress_warnings on
125 #pragma BullseyeCoverage off
126 #pragma suppress_warnings off
130 EXPORT_C void CMacFactory::CreateAsyncMacL(CAsyncMac*& aMac,
131 const TUid aAlgorithmUid,
133 const CCryptoParams* aAlgorithmParams)
135 MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
138 selector->CreateAsyncMacL(aMac, aAlgorithmUid, aKey, aAlgorithmParams);
142 CLegacySelector* legacySelector=CLegacySelector::NewLC();
143 legacySelector->CreateAsyncMacL(aMac, aAlgorithmUid, aKey, aAlgorithmParams);
144 CleanupStack::PopAndDestroy(legacySelector); //selector
148 CAsyncMac* CAsyncMac::NewL(MAsyncMac* aMac, TInt aHandle)
150 CAsyncMac* self = new (ELeave) CAsyncMac(aMac, aHandle);
154 CAsyncMac::CAsyncMac(MAsyncMac* aMac, TInt aHandle)
155 : CCryptoBase(aMac, aHandle)
159 EXPORT_C CAsyncMac::~CAsyncMac()
164 * Following asynchronous working methods delegate calls to the plug-in implementation
165 * of the requested MAC algorithm.
167 EXPORT_C TPtrC8 CAsyncMac::MacL(const TDesC8& aMessage, TRequestStatus& aStatus)
169 return ((MAsyncMac*)iPlugin)->MacL(aMessage, aStatus);
172 EXPORT_C void CAsyncMac::UpdateL(const TDesC8& aMessage, TRequestStatus& aStatus)
174 ((MAsyncMac*)iPlugin)->UpdateL(aMessage, aStatus);
177 EXPORT_C TPtrC8 CAsyncMac::FinalL(const TDesC8& aMessage, TRequestStatus& aStatus)
179 return ((MAsyncMac*)iPlugin)->FinalL(aMessage, aStatus);
182 EXPORT_C void CAsyncMac::ReInitialiseAndSetKeyL(const CKey& aKey)
184 ((MAsyncMac*)iPlugin)->ReInitialiseAndSetKeyL(aKey);
187 EXPORT_C CAsyncMac* CAsyncMac::ReplicateL()
189 MAsyncMac* plugin=((MAsyncMac*)iPlugin)->ReplicateL();
190 CleanupClosePushL(*plugin);
192 lib.SetHandle(iLibHandle);
194 User::LeaveIfError(duplib.Duplicate(RThread(), EOwnerProcess));
195 CleanupClosePushL(duplib);
196 CAsyncMac* self=new(ELeave) CAsyncMac(plugin, duplib.Handle());
197 CleanupStack::Pop(2, plugin); //duplib, plugin
201 EXPORT_C CAsyncMac* CAsyncMac::CopyL()
203 MAsyncMac* plugin=((MAsyncMac*)iPlugin)->CopyL();
204 CleanupClosePushL(*plugin);
206 lib.SetHandle(iLibHandle);
208 User::LeaveIfError(duplib.Duplicate(RThread(), EOwnerProcess));
209 CleanupClosePushL(duplib);
210 CAsyncMac* self=new(ELeave) CAsyncMac(plugin, duplib.Handle());
211 CleanupStack::Pop(2, plugin); //duplib, plugin
216 EXPORT_C void CAsyncMac::Cancel()
218 ((MAsyncMac*)iPlugin)->Cancel();