sl@0: /* sl@0: * Copyright (c) 2006-2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of the License "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * crypto signature API implementation sl@0: * crypto signature API implementation sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: */ sl@0: sl@0: #include sl@0: #include sl@0: #include sl@0: #include "legacyselector.h" sl@0: sl@0: using namespace CryptoSpi; sl@0: sl@0: sl@0: // sl@0: // Implementation of signature base class sl@0: // sl@0: CSignatureBase::CSignatureBase(MSignatureBase* aSignatureProcessor, TInt aHandle) sl@0: : CCryptoBase(aSignatureProcessor, aHandle) sl@0: { sl@0: } sl@0: sl@0: CSignatureBase::~CSignatureBase() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void CSignatureBase::SetPaddingModeL(TUid aPaddingMode) sl@0: { sl@0: MSignatureBase* ptr=static_cast(iPlugin); sl@0: ptr->SetPaddingModeL(aPaddingMode); sl@0: } sl@0: sl@0: EXPORT_C void CSignatureBase::SetKeyL(const CKey& aPrivateKey) sl@0: { sl@0: MSignatureBase* ptr=static_cast(iPlugin); sl@0: ptr->SetKeyL(aPrivateKey); sl@0: } sl@0: sl@0: EXPORT_C TInt CSignatureBase::GetMaximumInputLengthL() const sl@0: { sl@0: MSignatureBase* ptr=static_cast(iPlugin); sl@0: return ptr->GetMaximumInputLengthL(); sl@0: } sl@0: sl@0: EXPORT_C TInt CSignatureBase::GetMaximumOutputLengthL() const sl@0: { sl@0: MSignatureBase* ptr=static_cast(iPlugin); sl@0: return ptr->GetMaximumOutputLengthL(); sl@0: } sl@0: sl@0: // sl@0: // Implementation of Signer sl@0: // sl@0: CSigner* CSigner::NewL(MSigner* aSigner, TInt aHandle) sl@0: { sl@0: CSigner* self=new(ELeave) CSigner(aSigner, aHandle); sl@0: return self; sl@0: } sl@0: sl@0: CSigner::CSigner(MSigner* aSigner, TInt aHandle) : CSignatureBase(aSigner, aHandle) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C CSigner::~CSigner() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void CSigner::SignL(const TDesC8& aInput, CCryptoParams& aSignature) sl@0: { sl@0: MSigner* ptr=static_cast(iPlugin); sl@0: ptr->SignL(aInput, aSignature); sl@0: } sl@0: sl@0: sl@0: // sl@0: // Implementation of Verifier sl@0: // sl@0: CVerifier* CVerifier::NewL(MVerifier* aVerifier, TInt aHandle) sl@0: { sl@0: CVerifier* self=new(ELeave) CVerifier(aVerifier, aHandle); sl@0: return self; sl@0: } sl@0: sl@0: CVerifier::CVerifier(MVerifier* aVerifier, TInt aHandle) sl@0: : CSignatureBase(aVerifier, aHandle) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C CVerifier::~CVerifier() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void CVerifier::VerifyL(const TDesC8& aInput, const CCryptoParams& aSignature, TBool& aVerificationResult) sl@0: { sl@0: MVerifier* ptr=static_cast(iPlugin); sl@0: ptr->VerifyL(aInput, aSignature, aVerificationResult); sl@0: } sl@0: sl@0: EXPORT_C void CVerifier::InverseSignL(HBufC8*& aOutput, const CCryptoParams& aSignature) sl@0: { sl@0: MVerifier* ptr=static_cast(iPlugin); sl@0: ptr->InverseSignL(aOutput, aSignature); sl@0: } sl@0: sl@0: // sl@0: // Implementation of Signer and Verifier Factory sl@0: // sl@0: EXPORT_C void CSignatureFactory::CreateSignerL(CSigner*& aSigner, sl@0: TUid aAlgorithmUid, sl@0: const CKey& aKey, sl@0: TUid aPaddingMode, sl@0: const CCryptoParams* aAlgorithmParams) sl@0: { sl@0: MPluginSelector* selector=reinterpret_cast(Dll::Tls()); sl@0: if (selector) sl@0: { sl@0: selector->CreateSignerL(aSigner, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams); sl@0: } sl@0: else sl@0: { sl@0: CLegacySelector* legacySelector=CLegacySelector::NewLC(); sl@0: legacySelector->CreateSignerL(aSigner, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams); sl@0: CleanupStack::PopAndDestroy(legacySelector); //selector sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CSignatureFactory::CreateVerifierL(CVerifier*& aVerifier, sl@0: TUid aAlgorithmUid, sl@0: const CKey& aKey, sl@0: TUid aPaddingMode, sl@0: const CCryptoParams* aAlgorithmParams) sl@0: { sl@0: MPluginSelector* selector=reinterpret_cast(Dll::Tls()); sl@0: if (selector) sl@0: { sl@0: selector->CreateVerifierL(aVerifier, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams); sl@0: } sl@0: else sl@0: { sl@0: CLegacySelector* legacySelector=CLegacySelector::NewLC(); sl@0: legacySelector->CreateVerifierL(aVerifier, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams); sl@0: CleanupStack::PopAndDestroy(legacySelector); //legacySelector sl@0: } sl@0: } sl@0: sl@0: // sl@0: // Implementation of Asynchronous Signer sl@0: // (async methods not implemented, so no coverage) sl@0: // sl@0: sl@0: #ifdef _BullseyeCoverage sl@0: #pragma suppress_warnings on sl@0: #pragma BullseyeCoverage off sl@0: #pragma suppress_warnings off sl@0: #endif sl@0: sl@0: CAsyncSigner* CAsyncSigner::NewL(MAsyncSigner* aSigner, TInt aHandle) sl@0: { sl@0: CAsyncSigner* self=new(ELeave) CAsyncSigner(aSigner, aHandle); sl@0: return self; sl@0: } sl@0: sl@0: CAsyncSigner::CAsyncSigner(MAsyncSigner* aSigner, TInt aHandle) sl@0: : CSignatureBase(aSigner, aHandle) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C CAsyncSigner::~CAsyncSigner() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void CAsyncSigner::SignL(const TDesC8& aInput, CCryptoParams& aSignature, TRequestStatus& aRequestStatus) sl@0: { sl@0: MAsyncSigner* ptr=static_cast(iPlugin); sl@0: ptr->SignL(aInput, aSignature, aRequestStatus); sl@0: } sl@0: sl@0: EXPORT_C void CAsyncSigner::Cancel() sl@0: { sl@0: MAsyncSigner* ptr=static_cast(iPlugin); sl@0: ptr->Cancel(); sl@0: } sl@0: sl@0: // sl@0: // Implementation of Asynchronous Verifier sl@0: // sl@0: CAsyncVerifier* CAsyncVerifier::NewL(MAsyncVerifier* aVerifier, TInt aHandle) sl@0: { sl@0: CAsyncVerifier* self=new(ELeave) CAsyncVerifier(aVerifier, aHandle); sl@0: return self; sl@0: } sl@0: sl@0: CAsyncVerifier::CAsyncVerifier(MAsyncVerifier* aVerifier, TInt aHandle) sl@0: : CSignatureBase(aVerifier, aHandle) sl@0: { sl@0: } sl@0: sl@0: EXPORT_C CAsyncVerifier::~CAsyncVerifier() sl@0: { sl@0: } sl@0: sl@0: EXPORT_C void CAsyncVerifier::VerifyL(const TDesC8& aInput, const CCryptoParams& aSignature, TBool& aVerificationResult, TRequestStatus& aRequestStatus) sl@0: { sl@0: MAsyncVerifier* ptr=static_cast(iPlugin); sl@0: ptr->VerifyL(aInput, aSignature, aVerificationResult, aRequestStatus); sl@0: } sl@0: sl@0: EXPORT_C void CAsyncVerifier::InverseSignL(HBufC8*& aOutput, const CCryptoParams& aSignature, TRequestStatus& aRequestStatus) sl@0: { sl@0: MAsyncVerifier* ptr=static_cast(iPlugin); sl@0: ptr->InverseSignL(aOutput, aSignature, aRequestStatus); sl@0: } sl@0: sl@0: EXPORT_C void CAsyncVerifier::Cancel() sl@0: { sl@0: MAsyncVerifier* ptr=static_cast(iPlugin); sl@0: ptr->Cancel(); sl@0: } sl@0: sl@0: // sl@0: // Implementation of Signer and Verifier Factory sl@0: // sl@0: EXPORT_C void CSignatureFactory::CreateAsyncSignerL(CAsyncSigner*& aSigner, sl@0: TUid aAlgorithmUid, sl@0: const CKey& aKey, sl@0: TUid aPaddingMode, sl@0: const CCryptoParams* aAlgorithmParams) sl@0: { sl@0: MPluginSelector* selector=reinterpret_cast(Dll::Tls()); sl@0: if (selector) sl@0: { sl@0: selector->CreateAsyncSignerL(aSigner, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams); sl@0: } sl@0: else sl@0: { sl@0: CLegacySelector* legacySelector=CLegacySelector::NewLC(); sl@0: legacySelector->CreateAsyncSignerL(aSigner, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams); sl@0: CleanupStack::PopAndDestroy(legacySelector); //selector sl@0: } sl@0: } sl@0: sl@0: EXPORT_C void CSignatureFactory::CreateAsyncVerifierL(CAsyncVerifier*& aVerifier, sl@0: TUid aAlgorithmUid, sl@0: const CKey& aKey, sl@0: TUid aPaddingMode, sl@0: const CCryptoParams* aAlgorithmParams) sl@0: { sl@0: MPluginSelector* selector=reinterpret_cast(Dll::Tls()); sl@0: if (selector) sl@0: { sl@0: selector->CreateAsyncVerifierL(aVerifier, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams); sl@0: } sl@0: else sl@0: { sl@0: CLegacySelector* legacySelector=CLegacySelector::NewLC(); sl@0: legacySelector->CreateAsyncVerifierL(aVerifier, aAlgorithmUid, aKey, aPaddingMode, aAlgorithmParams); sl@0: CleanupStack::PopAndDestroy(legacySelector); //legacySelector sl@0: } sl@0: sl@0: } sl@0: sl@0: