os/security/cryptoplugins/cryptospiplugins/test/dummyecchwplugin/src/dummyeccsignerimpl.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/security/cryptoplugins/cryptospiplugins/test/dummyecchwplugin/src/dummyeccsignerimpl.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,147 @@
1.4 +/*
1.5 +* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +* All rights reserved.
1.7 +* This component and the accompanying materials are made available
1.8 +* under the terms of the License "Eclipse Public License v1.0"
1.9 +* which accompanies this distribution, and is available
1.10 +* at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.11 +*
1.12 +* Initial Contributors:
1.13 +* Nokia Corporation - initial contribution.
1.14 +*
1.15 +* Contributors:
1.16 +*
1.17 +* Description:
1.18 +*
1.19 +*/
1.20 +
1.21 +
1.22 +#include "dummyeccsignerimpl.h"
1.23 +#include "keys.h"
1.24 +#include "pluginconfig.h"
1.25 +#include "cryptospihai.h"
1.26 +
1.27 +using namespace DummyEccHwCrypto;
1.28 +using namespace CryptoSpiHai;
1.29 +
1.30 +const TInt KMaxSignerOutputLength = 50;
1.31 +const TInt KMaxSignerInputLength = 50;
1.32 +
1.33 +// CDummyECCSignerImpl
1.34 +CDummyECCSignerImpl* CDummyECCSignerImpl::NewL(const CKey& aKey,
1.35 + TUid aPaddingMode)
1.36 + {
1.37 + CDummyECCSignerImpl* self =
1.38 + CDummyECCSignerImpl::NewLC(aKey, aPaddingMode);
1.39 + CleanupStack::Pop(self);
1.40 + return self;
1.41 + }
1.42 +
1.43 +CDummyECCSignerImpl* CDummyECCSignerImpl::NewLC(const CKey& aKey,
1.44 + TUid aPaddingMode)
1.45 + {
1.46 + CDummyECCSignerImpl* self =
1.47 + new (ELeave) CDummyECCSignerImpl(aPaddingMode);
1.48 + CleanupStack::PushL(self);
1.49 + self->ConstructL(aKey);
1.50 + return self;
1.51 + }
1.52 +
1.53 +CDummyECCSignerImpl::CDummyECCSignerImpl(TUid aPaddingMode) :
1.54 + iPaddingMode(aPaddingMode)
1.55 + {
1.56 + }
1.57 +
1.58 +CDummyECCSignerImpl::~CDummyECCSignerImpl()
1.59 + {
1.60 + delete iKey;
1.61 + }
1.62 +
1.63 +void CDummyECCSignerImpl::ConstructL(const CKey& aKey)
1.64 + {
1.65 + SetKeyL(aKey);
1.66 + }
1.67 +
1.68 +// MPlugin Interface
1.69 +void CDummyECCSignerImpl::Close()
1.70 + {
1.71 + delete this;
1.72 + }
1.73 +void CDummyECCSignerImpl::Reset()
1.74 + {
1.75 + }
1.76 +void CDummyECCSignerImpl::GetCharacteristicsL(
1.77 + const TCharacteristics*& aPluginCharacteristics)
1.78 + {
1.79 + TInt numCiphers = sizeof(KSignerCharacteristics)
1.80 + / sizeof(TAsymmetricSignatureCharacteristics*);
1.81 + TInt32 implUid = ImplementationUid().iUid;
1.82 + for (TInt i = 0; i < numCiphers; ++i)
1.83 + {
1.84 + if (KSignerCharacteristics[i]->cmn.iImplementationUID == implUid)
1.85 + {
1.86 + aPluginCharacteristics = KSignerCharacteristics[i];
1.87 + break;
1.88 + }
1.89 + }
1.90 + }
1.91 +
1.92 +const CExtendedCharacteristics* CDummyECCSignerImpl::GetExtendedCharacteristicsL()
1.93 + {
1.94 + // All Symbian software plug-ins have unlimited concurrency, cannot be reserved
1.95 + // for exclusive use and are not CERTIFIED to be standards compliant.
1.96 + return CExtendedCharacteristics::NewL(KMaxTInt, EFalse);
1.97 + }
1.98 +
1.99 +TAny* CDummyECCSignerImpl::GetExtension(TUid /* aExtensionId */)
1.100 + {
1.101 + return 0;
1.102 + }
1.103 +// End of MPlugin Interface
1.104 +
1.105 +// MSignatureBase Interface
1.106 +void CDummyECCSignerImpl::SetPaddingModeL(TUid /* aPaddingMode */)
1.107 + {
1.108 + User::Leave(KErrNotSupported);
1.109 + }
1.110 +
1.111 +void CDummyECCSignerImpl::SetKeyL(const CKey& aKey)
1.112 + {
1.113 + // delete any previous key and recreate the key
1.114 + delete iKey;
1.115 + iKey = NULL;
1.116 + iKey = CKey::NewL(aKey);
1.117 + }
1.118 +
1.119 +TInt CDummyECCSignerImpl::GetMaximumInputLengthL() const
1.120 + {
1.121 + return KMaxSignerInputLength;
1.122 + }
1.123 +
1.124 +TInt CDummyECCSignerImpl::GetMaximumOutputLengthL() const
1.125 + {
1.126 + return KMaxSignerOutputLength;
1.127 + }
1.128 +
1.129 +TUid CDummyECCSignerImpl::ImplementationUid() const
1.130 + {
1.131 + return KCryptoPluginEccSignerUid;
1.132 + }
1.133 +
1.134 +void CDummyECCSignerImpl::SignL(const TDesC8& aInput,
1.135 + CCryptoParams& aSignature)
1.136 + {
1.137 + if (iKey->IsPresent(KPassedHandleToKeyUid))
1.138 + {
1.139 + const TInt keyHandle = iKey->GetTIntL(KPassedHandleToKeyUid);
1.140 +
1.141 + // Invoke the Spi HAI to perform the operation
1.142 + CCryptoSpiHai::SignL(keyHandle, aInput, aSignature);
1.143 + }
1.144 + else
1.145 + {
1.146 + User::Leave(KErrNotSupported);
1.147 + }
1.148 + }
1.149 +
1.150 +// End of file