Update contrib.
2 * Copyright (c) 1998-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.
19 #include "tdsavector.h"
20 #include "tvectorutils.h"
23 #include "tbrokenrandom.h"
25 ////////////////////////////////////////////////////////////////////////////////
27 ////////////////////////////////////////////////////////////////////////////////
29 CTestAction* CDSASignVector::NewL(RFs& aFs,
30 CConsoleBase& aConsole,
32 const TTestActionSpec& aTestActionSpec)
34 CTestAction* self = CDSASignVector::NewLC(aFs, aConsole, aOut, aTestActionSpec);
39 CTestAction* CDSASignVector::NewLC(RFs& aFs,
40 CConsoleBase& aConsole,
42 const TTestActionSpec& aTestActionSpec)
44 CDSASignVector* self = new(ELeave) CDSASignVector(aFs, aConsole, aOut);
45 CleanupStack::PushL(self);
46 self->ConstructL(aTestActionSpec);
50 CDSASignVector::~CDSASignVector()
58 CDSASignVector::CDSASignVector(RFs& /*aFs*/,
59 CConsoleBase& aConsole,
61 : CVectorTest(aConsole, aOut)
65 void CDSASignVector::ConstructL(const TTestActionSpec& aTestActionSpec)
67 CVectorTest::ConstructL(aTestActionSpec);
69 iPrivKey = VectorUtils::ReadDSAPrivateKeyL(aTestActionSpec.iActionBody);
71 iMessage.Set(Input::ParseElement(aTestActionSpec.iActionBody, _L8("<m>")));
72 iK = Input::ParseElementHexL(aTestActionSpec.iActionBody, _L8("<k>"));
74 iSignature = VectorUtils::ReadDSASignatureL(aTestActionSpec.iActionBody);
75 iSigInput = CHashingSignatureInput::NewL(CMessageDigest::ESHA1);
76 iSigInput->Update(iMessage);
79 void CDSASignVector::DoPerformActionL()
83 CRandomSetSource* random = new(ELeave)CRandomSetSource(*iK);
84 SetThreadRandomLC(random);
86 CDSASigner* signer = CDSASigner::NewLC(*iPrivKey);
87 const CDSASignature* testSig = signer->SignL(iSigInput->Final());
88 iResult = (*testSig == *iSignature);
91 CleanupStack::PopAndDestroy(signer);
92 CleanupStack::PopAndDestroy(); //SetThreadRandomLC
97 void CDSASignVector::DoPerformanceTestActionL()
102 void CDSASignVector::DoCheckResult(TInt /*aError*/)
104 // If using Keith's fixed up testframework for testing failures, iResult will
105 // have already been corrected for a deliberate fail result.
106 // If not using Keith's testframework iResult is still a fail result at this
107 // point, so now's the time to adjust for deliberate failure.
110 iResult = (iResult && iExpectedResult) || (!iResult && !iExpectedResult);
112 if( iResult == EFalse )
114 iConsole.Printf(_L("X"));
118 iConsole.Printf(_L("."));
122 ////////////////////////////////////////////////////////////////////////////////
124 ////////////////////////////////////////////////////////////////////////////////
126 CTestAction* CDSAVerifyVector::NewL(RFs& aFs,
127 CConsoleBase& aConsole,
129 const TTestActionSpec& aTestActionSpec)
131 CTestAction* self = CDSAVerifyVector::NewLC(aFs, aConsole, aOut, aTestActionSpec);
136 CTestAction* CDSAVerifyVector::NewLC(RFs& aFs,
137 CConsoleBase& aConsole,
139 const TTestActionSpec& aTestActionSpec)
141 CDSAVerifyVector* self = new(ELeave) CDSAVerifyVector(aFs, aConsole, aOut);
142 CleanupStack::PushL(self);
143 self->ConstructL(aTestActionSpec);
147 CDSAVerifyVector::~CDSAVerifyVector()
155 CDSAVerifyVector::CDSAVerifyVector(RFs& /*aFs*/,
156 CConsoleBase& aConsole,
158 : CVectorTest(aConsole, aOut)
162 void CDSAVerifyVector::ConstructL(const TTestActionSpec& aTestActionSpec)
164 CVectorTest::ConstructL(aTestActionSpec);
166 iPubKey = VectorUtils::ReadDSAPublicKeyL(aTestActionSpec.iActionBody);
168 TPtrC8 message(Input::ParseElement(aTestActionSpec.iActionBody, _L8("<m>")));
169 if (message.Length()==0)
170 iMessage = Input::ParseElementHexL(aTestActionSpec.iActionBody, _L8("<hexm>"));
172 iMessage = message.AllocL();
174 iSignature = VectorUtils::ReadDSASignatureL(aTestActionSpec.iActionBody);
175 iSigInput = CHashingSignatureInput::NewL(CMessageDigest::ESHA1);
176 iSigInput->Update(*iMessage);
179 void CDSAVerifyVector::DoPerformActionL()
183 CDSAVerifier* verifier = CDSAVerifier::NewLC(*iPubKey);
184 iResult = verifier->VerifyL(iSigInput->Final(), *iSignature);
186 CleanupStack::PopAndDestroy(verifier);
190 void CDSAVerifyVector::DoPerformanceTestActionL()
195 void CDSAVerifyVector::DoCheckResult(TInt /*aError*/)
197 // If using Keith's fixed up testframework for testing failures, iResult will
198 // have already been corrected for a deliberate fail result.
199 // If not using Keith's testframework iResult is still a fail result at this
200 // point, so now's the time to adjust for deliberate failure.
203 iResult = (iResult && iExpectedResult) || (!iResult && !iExpectedResult);
205 if( iResult == EFalse )
207 iConsole.Printf(_L("X"));
211 iConsole.Printf(_L("."));