crypto/weakcryptospi/source/spi/cryptosignatureapi.cpp
changeset 8 35751d3474b7
child 43 2f10d260163b
equal deleted inserted replaced
2:675a964f4eb5 8:35751d3474b7
       
     1 /*
       
     2 * Copyright (c) 2006-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 * crypto signature API implementation
       
    16 * crypto signature API implementation
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 /**
       
    22  @file
       
    23 */
       
    24 
       
    25 #include "cryptosignatureapi.h"
       
    26 #include "signerplugin.h"
       
    27 #include "verifierplugin.h"
       
    28 #include "legacyselector.h"
       
    29 
       
    30 using namespace CryptoSpi;
       
    31 
       
    32 
       
    33 //
       
    34 // Implementation of signature base class 
       
    35 //
       
    36 CSignatureBase::CSignatureBase(MSignatureBase* aSignatureProcessor, TInt aHandle)
       
    37 : CCryptoBase(aSignatureProcessor, aHandle)
       
    38 	{	
       
    39 	}
       
    40 
       
    41 CSignatureBase::~CSignatureBase()
       
    42 	{
       
    43 	}
       
    44 
       
    45 EXPORT_C void CSignatureBase::SetPaddingModeL(TUid aPaddingMode)
       
    46 	{
       
    47 	MSignatureBase* ptr=static_cast<MSignatureBase*>(iPlugin);
       
    48 	ptr->SetPaddingModeL(aPaddingMode);
       
    49 	}
       
    50 
       
    51 EXPORT_C void CSignatureBase::SetKeyL(const CKey& aPrivateKey)
       
    52 	{
       
    53 	MSignatureBase* ptr=static_cast<MSignatureBase*>(iPlugin);
       
    54 	ptr->SetKeyL(aPrivateKey);	
       
    55 	}
       
    56 
       
    57 EXPORT_C TInt CSignatureBase::GetMaximumInputLengthL() const
       
    58 	{
       
    59 	MSignatureBase* ptr=static_cast<MSignatureBase*>(iPlugin);
       
    60 	return ptr->GetMaximumInputLengthL();		
       
    61 	}
       
    62 
       
    63 EXPORT_C TInt CSignatureBase::GetMaximumOutputLengthL() const
       
    64 	{
       
    65 	MSignatureBase* ptr=static_cast<MSignatureBase*>(iPlugin);
       
    66 	return ptr->GetMaximumOutputLengthL();			
       
    67 	}
       
    68 
       
    69 //
       
    70 // Implementation of Signer
       
    71 //
       
    72 CSigner* CSigner::NewL(MSigner* aSigner, TInt aHandle)
       
    73 	{
       
    74 	CSigner* self=new(ELeave) CSigner(aSigner, aHandle);
       
    75 	return self;									
       
    76 	}
       
    77 
       
    78 CSigner::CSigner(MSigner* aSigner, TInt aHandle) : CSignatureBase(aSigner, aHandle)
       
    79 	{
       
    80 	}
       
    81 
       
    82 EXPORT_C CSigner::~CSigner()
       
    83 	{
       
    84 	}
       
    85 
       
    86 EXPORT_C void CSigner::SignL(const TDesC8& aInput, CCryptoParams& aSignature)
       
    87 	{
       
    88 	MSigner* ptr=static_cast<MSigner*>(iPlugin);
       
    89 	ptr->SignL(aInput, aSignature);	
       
    90 	}
       
    91 
       
    92 
       
    93 //
       
    94 // Implementation of Verifier
       
    95 //
       
    96 CVerifier* CVerifier::NewL(MVerifier* aVerifier, TInt aHandle)
       
    97 	{
       
    98 	CVerifier* self=new(ELeave) CVerifier(aVerifier, aHandle);
       
    99 	return self;				
       
   100 	}
       
   101 
       
   102 CVerifier::CVerifier(MVerifier* aVerifier, TInt aHandle)
       
   103 : CSignatureBase(aVerifier, aHandle)
       
   104 	{
       
   105 	}
       
   106 	
       
   107 EXPORT_C CVerifier::~CVerifier()
       
   108 	{
       
   109 	}
       
   110 
       
   111 EXPORT_C void CVerifier::VerifyL(const TDesC8& aInput, const CCryptoParams& aSignature, TBool& aVerificationResult)
       
   112 	{
       
   113 	MVerifier* ptr=static_cast<MVerifier*>(iPlugin);
       
   114 	ptr->VerifyL(aInput, aSignature, aVerificationResult);
       
   115 	}
       
   116 
       
   117 EXPORT_C void CVerifier::InverseSignL(HBufC8*& aOutput, const CCryptoParams& aSignature)
       
   118 	{
       
   119 	MVerifier* ptr=static_cast<MVerifier*>(iPlugin);
       
   120 	ptr->InverseSignL(aOutput, aSignature);
       
   121 	}
       
   122 
       
   123 //
       
   124 // Implementation of Signer and Verifier Factory
       
   125 //
       
   126 EXPORT_C void CSignatureFactory::CreateSignerL(CSigner*& aSigner,
       
   127 											TUid aAlgorithmUid,
       
   128 											const CKey& aKey,
       
   129 											TUid aPaddingMode,
       
   130 											const CCryptoParams* aAlgorithmParams)
       
   131 	{
       
   132 	MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
       
   133 	if (selector)
       
   134 		{
       
   135 		selector->CreateSignerL(aSigner, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams);
       
   136 		}
       
   137 	else
       
   138 		{
       
   139 		CLegacySelector* legacySelector=CLegacySelector::NewLC();
       
   140 		legacySelector->CreateSignerL(aSigner, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams);
       
   141 		CleanupStack::PopAndDestroy(legacySelector); //selector	
       
   142 		}
       
   143 	}
       
   144 
       
   145 EXPORT_C void CSignatureFactory::CreateVerifierL(CVerifier*& aVerifier,
       
   146 												TUid aAlgorithmUid,
       
   147 												const CKey& aKey,
       
   148 												TUid aPaddingMode,
       
   149 												const CCryptoParams* aAlgorithmParams)
       
   150 	{
       
   151 	MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
       
   152 	if (selector)
       
   153 		{
       
   154 		selector->CreateVerifierL(aVerifier, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams);
       
   155 		}
       
   156 	else
       
   157 		{
       
   158 		CLegacySelector* legacySelector=CLegacySelector::NewLC();
       
   159 		legacySelector->CreateVerifierL(aVerifier, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams);
       
   160 		CleanupStack::PopAndDestroy(legacySelector); //legacySelector
       
   161 		}
       
   162 	}
       
   163 
       
   164 //
       
   165 // Implementation of Asynchronous Signer
       
   166 // (async methods not implemented, so no coverage)
       
   167 //
       
   168 
       
   169 #ifdef _BullseyeCoverage
       
   170 #pragma suppress_warnings on
       
   171 #pragma BullseyeCoverage off
       
   172 #pragma suppress_warnings off
       
   173 #endif
       
   174 
       
   175 CAsyncSigner* CAsyncSigner::NewL(MAsyncSigner* aSigner, TInt aHandle)
       
   176 	{
       
   177 	CAsyncSigner* self=new(ELeave) CAsyncSigner(aSigner, aHandle);
       
   178 	return self;		
       
   179 	}
       
   180 
       
   181 CAsyncSigner::CAsyncSigner(MAsyncSigner* aSigner, TInt aHandle)
       
   182 : CSignatureBase(aSigner, aHandle)
       
   183 	{
       
   184 	}
       
   185 
       
   186 EXPORT_C CAsyncSigner::~CAsyncSigner()
       
   187 	{
       
   188 	}
       
   189 
       
   190 EXPORT_C void CAsyncSigner::SignL(const TDesC8& aInput, CCryptoParams& aSignature, TRequestStatus& aRequestStatus)
       
   191 	{
       
   192 	MAsyncSigner* ptr=static_cast<MAsyncSigner*>(iPlugin);
       
   193 	ptr->SignL(aInput, aSignature, aRequestStatus);
       
   194 	}
       
   195 
       
   196 EXPORT_C void CAsyncSigner::Cancel()
       
   197 	{
       
   198 	MAsyncSigner* ptr=static_cast<MAsyncSigner*>(iPlugin);
       
   199 	ptr->Cancel();
       
   200 	}
       
   201 
       
   202 //
       
   203 // Implementation of Asynchronous Verifier
       
   204 //
       
   205 CAsyncVerifier* CAsyncVerifier::NewL(MAsyncVerifier* aVerifier, TInt aHandle)
       
   206 	{
       
   207 	CAsyncVerifier* self=new(ELeave) CAsyncVerifier(aVerifier, aHandle);
       
   208 	return self;
       
   209 	}
       
   210 	
       
   211 CAsyncVerifier::CAsyncVerifier(MAsyncVerifier* aVerifier, TInt aHandle)
       
   212 : CSignatureBase(aVerifier, aHandle)
       
   213 	{
       
   214 	}
       
   215 
       
   216 EXPORT_C CAsyncVerifier::~CAsyncVerifier()
       
   217 	{		
       
   218 	}
       
   219 
       
   220 EXPORT_C void CAsyncVerifier::VerifyL(const TDesC8& aInput, const CCryptoParams& aSignature, TBool& aVerificationResult, TRequestStatus& aRequestStatus)
       
   221 	{
       
   222 	MAsyncVerifier* ptr=static_cast<MAsyncVerifier*>(iPlugin);
       
   223 	ptr->VerifyL(aInput, aSignature, aVerificationResult, aRequestStatus);
       
   224 	}
       
   225 
       
   226 EXPORT_C void CAsyncVerifier::InverseSignL(HBufC8*& aOutput, const CCryptoParams& aSignature, TRequestStatus& aRequestStatus)
       
   227 	{
       
   228 	MAsyncVerifier* ptr=static_cast<MAsyncVerifier*>(iPlugin);
       
   229 	ptr->InverseSignL(aOutput, aSignature, aRequestStatus);
       
   230 	}
       
   231 
       
   232 EXPORT_C void CAsyncVerifier::Cancel()
       
   233 	{
       
   234 	MAsyncVerifier* ptr=static_cast<MAsyncVerifier*>(iPlugin);
       
   235 	ptr->Cancel();
       
   236 	}
       
   237 
       
   238 //
       
   239 // Implementation of Signer and Verifier Factory
       
   240 //
       
   241 EXPORT_C void CSignatureFactory::CreateAsyncSignerL(CAsyncSigner*& aSigner,
       
   242 												TUid aAlgorithmUid,
       
   243 												const CKey& aKey,
       
   244 												TUid aPaddingMode,
       
   245 												const CCryptoParams* aAlgorithmParams)
       
   246 	{
       
   247 	MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
       
   248 	if (selector)
       
   249 		{
       
   250 		selector->CreateAsyncSignerL(aSigner, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams);
       
   251 		}
       
   252 	else
       
   253 		{
       
   254 		CLegacySelector* legacySelector=CLegacySelector::NewLC();
       
   255 		legacySelector->CreateAsyncSignerL(aSigner, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams);
       
   256 		CleanupStack::PopAndDestroy(legacySelector); //selector	
       
   257 		}
       
   258 	}
       
   259 
       
   260 EXPORT_C void CSignatureFactory::CreateAsyncVerifierL(CAsyncVerifier*& aVerifier,
       
   261 													TUid aAlgorithmUid,
       
   262 													const CKey& aKey,
       
   263 													TUid aPaddingMode,
       
   264 													const CCryptoParams* aAlgorithmParams)
       
   265 	{
       
   266 	MPluginSelector* selector=reinterpret_cast<MPluginSelector *>(Dll::Tls());
       
   267 	if (selector)
       
   268 		{
       
   269 		selector->CreateAsyncVerifierL(aVerifier, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams);
       
   270 		}
       
   271 	else
       
   272 		{
       
   273 		CLegacySelector* legacySelector=CLegacySelector::NewLC();
       
   274 		legacySelector->CreateAsyncVerifierL(aVerifier, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams);
       
   275 		CleanupStack::PopAndDestroy(legacySelector); //legacySelector
       
   276 		}
       
   277 
       
   278 	}
       
   279 
       
   280