os/security/cryptoservices/certificateandkeymgmt/tpkixcert_tef/src/apiteststeps.cpp
First public contribution.
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.
19 #include "apiteststeps.h"
20 #include "cleanuputils.h"
23 CPkixCertAddSupportedOidsStep::CPkixCertAddSupportedOidsStep()
25 SetTestStepName(KAddSupportedOidsTestStep);
28 //1. make a copy(A) of the supported oids at the start
29 //2. add in the oids from the config file(B), make a copy of these and add to A
30 //3. get the supported oids now(C)
31 //4. iterate over C, for each oid find copies in A and remove them. if it is not found we error
32 //5. if A is non empty we error
33 void CPkixCertAddSupportedOidsStep::PerformTestL()
35 CPkixCertStepBase::PerformTestL();
37 //1. make a copy(A) of the supported oids at the start
39 const RPointerArray<TDesC>& suppOids = iCertChain->SupportedCriticalExtensions();
40 //CleanupClosePushL(suppOids); //don't need to do this as a ref and done in stepbase destructor
41 RPointerArray<HBufC> startSuppOids;
42 CleanupResetAndDestroy<RPointerArray<HBufC> >::PushL(startSuppOids);
46 for (i=0; i < suppOids.Count(); ++i)
48 des = (suppOids[i])->AllocLC();
49 startSuppOids.AppendL(des);
50 CleanupStack::Pop(des);
55 //2. add in the oids from the config file(B)
56 iCertChain->AddSupportedCriticalExtensionsL(iProcessedOids);
58 //make a copy of these and add to A
59 for (i=0; i < iProcessedOids.Count(); ++i)
61 des = (iProcessedOids[i])->AllocLC();
62 startSuppOids.AppendL(des);
63 CleanupStack::Pop(des);
66 //3. get the supported oids now(C)
67 const RPointerArray<TDesC>& suppOids2 = iCertChain->SupportedCriticalExtensions();
70 //4. iterate over C, for each oid find copies in A and remove them. if it is not found we error
72 for (i=0; i < suppOids2.Count(); ++i)
75 for (TInt j=0; j < startSuppOids.Count(); ++j)
77 if ((*startSuppOids[j]) == (*suppOids2[i]))
80 delete (startSuppOids[j]);
81 startSuppOids.Remove(j);
84 } //startSuppOids loop
87 ERR_PRINTF2(_L("Extra ERROR: OID in result: %S"), suppOids2[i]);
88 User::Leave(KErrGeneral);
93 //5. if A is non empty we error
94 if (startSuppOids.Count() != 0)
96 for (TInt j=0; j < startSuppOids.Count(); ++j)
98 ERR_PRINTF2(_L("ERROR: OID missing from result: %S"), startSuppOids[j]);
100 User::Leave(KErrGeneral);
103 CleanupStack::PopAndDestroy(2, iCertChain);
107 ///////////////////////////////////////////////////////////////////
111 CPkixCertRemoveSupportedOidsStep::CPkixCertRemoveSupportedOidsStep()
113 SetTestStepName(KRemoveSupportedOidsTestStep);
117 //1. make a copy(A) of the supported oids at the start
118 //2. remove the oids read from the config file(B)
119 //3. make a copy(C) of the supported oids now
121 //5. iterate over A, for each oid find and remove first occurence only in C. if not found we error
122 //6. iterate over B removing each from C
123 //7. if C is non empty we error
124 void CPkixCertRemoveSupportedOidsStep::PerformTestL()
126 CPkixCertStepBase::PerformTestL();
128 //1. make a copy(A) of the supported oids at the start
132 const RPointerArray<TDesC>& suppOids = iCertChain->SupportedCriticalExtensions();
133 //CleanupClosePushL(suppOids); //don't need to do this as a ref and done in stepbase destructor
134 RPointerArray<HBufC> startSuppOids;
135 CleanupResetAndDestroy<RPointerArray<HBufC> >::PushL(startSuppOids);
139 for (i=0; i < suppOids.Count(); ++i)
141 des = (suppOids[i])->AllocLC();
142 startSuppOids.AppendL(des);
143 CleanupStack::Pop(des);
147 //2. remove the oids read from the config file(B)
148 iCertChain->RemoveSupportedCriticalExtensions(iProcessedOids);
150 //3. make a copy(C) of the supported oids now
151 const RPointerArray<TDesC>& suppOids2 = iCertChain->SupportedCriticalExtensions();
153 RPointerArray<HBufC> endSuppOids;
154 CleanupResetAndDestroy<RPointerArray<HBufC> >::PushL(endSuppOids);
156 for (i=0; i < suppOids2.Count(); ++i)
158 des = (suppOids2[i])->AllocLC();
159 endSuppOids.AppendL(des);
160 CleanupStack::Pop(des);
166 for (i=0; i < iProcessedOids.Count(); ++i)
168 des = (iProcessedOids[i])->AllocLC();
169 endSuppOids.AppendL(des);
170 CleanupStack::Pop(des);
175 //5. iterate over A, for each oid find and remove first occurence only in C. if not found we error
177 for (i=0; i < startSuppOids.Count(); ++i)
180 for (TInt j=0; j < endSuppOids.Count(); ++j)
182 if ((*endSuppOids[j]) == (*startSuppOids[i]))
185 delete (endSuppOids[j]);
186 endSuppOids.Remove(j);
192 ERR_PRINTF2(_L("ERROR: Extra OID removed from result: %S"), startSuppOids[i]);
193 User::Leave(KErrGeneral);
197 //6. iterate over B removing each from C
198 for (i=0; i < iProcessedOids.Count(); ++i)
200 for (TInt j=0; j < endSuppOids.Count(); ++j)
202 if ((*endSuppOids[j]) == (*iProcessedOids[i]))
204 delete (endSuppOids[j]);
205 endSuppOids.Remove(j);
211 //7. if C is non empty we error
212 if (endSuppOids.Count() != 0)
214 for (TInt j=0; j < endSuppOids.Count(); ++j)
216 ERR_PRINTF2(_L("ERROR: Extra/duplicate OID found in result: %S"), endSuppOids[j]);
218 User::Leave(KErrGeneral);
221 CleanupStack::PopAndDestroy(3, iCertChain);
224 /////////////////////////////////////////////////////////////////////
226 CPkixCertSetSupportedOidsStep::CPkixCertSetSupportedOidsStep()
228 SetTestStepName(KSetSupportedOidsTestStep);
232 //1. set the supported oids to the ones from the config(A)
233 //2. make a copy(B) of supported oids
234 //3. iterate over B, remove every match found in copy(C) taken from A. if not found in C we error
235 //4. if C not empty we error
236 void CPkixCertSetSupportedOidsStep::PerformTestL()
238 CPkixCertStepBase::PerformTestL();
240 //1. set the supported oids to the ones from the config(A)
241 iCertChain->SetSupportedCriticalExtensionsL(iProcessedOids);
243 //2. make a copy(B) of supported oids
244 const RPointerArray<TDesC>& suppOids = iCertChain->SupportedCriticalExtensions();
246 RPointerArray<HBufC> endSuppOids;
247 CleanupResetAndDestroy<RPointerArray<HBufC> >::PushL(endSuppOids);
251 for (i=0; i < suppOids.Count(); ++i)
253 des = (suppOids[i])->AllocLC();
254 endSuppOids.AppendL(des);
255 CleanupStack::Pop(des);
258 //3. iterate over B, remove every match found in copy(C) taken from A. if not found in C we error
260 RPointerArray<TDesC> oidsCopy;
261 CleanupClosePushL(oidsCopy);
263 for (i=0; i < iOids.Count(); ++i)
265 oidsCopy.AppendL(&(iOids[i]));
269 for (i=0; i < endSuppOids.Count(); ++i)
272 for (TInt j=(oidsCopy.Count() - 1); j >= 0; --j)
274 if ((*oidsCopy[j]) == (*endSuppOids[i]))
282 ERR_PRINTF2(_L("ERROR: Extra OID found in result: %S"), endSuppOids[i]);
283 User::Leave(KErrGeneral);
287 //4. if C not empty we error
288 if (oidsCopy.Count() != 0)
290 for (TInt j=0; j < oidsCopy.Count(); ++j)
292 ERR_PRINTF2(_L("ERROR: OID missing from result: %S"), oidsCopy[j]);
294 User::Leave(KErrGeneral);
297 CleanupStack::PopAndDestroy(3, iCertChain);
301 ////////////////////////////////////////////////
303 CPkixCertResetSupportedOidsStep::CPkixCertResetSupportedOidsStep()
305 SetTestStepName(KResetSupportedOidsTestStep);
308 //1. make a copy(A) of supported oids
309 //2. set supported oids to list from config
310 //3. reset supported oids
311 //4. get supported oids(B)
312 //5. iterate over B, find and remove first match in A. if not found we error
313 //6. if A is not empty we error
314 void CPkixCertResetSupportedOidsStep::PerformTestL()
316 CPkixCertStepBase::PerformTestL();
318 //1. make a copy(A) of supported oids
319 const RPointerArray<TDesC>& suppOids = iCertChain->SupportedCriticalExtensions();
320 //CleanupClosePushL(suppOids); //don't need to do this as a ref and done in stepbase destructor
321 RPointerArray<HBufC> startSuppOids;
322 CleanupResetAndDestroy<RPointerArray<HBufC> >::PushL(startSuppOids);
326 for (i=0; i < suppOids.Count(); ++i)
328 des = (suppOids[i])->AllocLC();
329 startSuppOids.AppendL(des);
330 CleanupStack::Pop(des);
333 //2. set supported oids to list from config
334 iCertChain->SetSupportedCriticalExtensionsL(iProcessedOids);
335 //3. reset supported oids
336 iCertChain->ResetSupportedCriticalExtsToDefaultL();
337 //4. get supported oids(B)
338 const RPointerArray<TDesC>& suppOids2 = iCertChain->SupportedCriticalExtensions();
340 //5. iterate over B, find and remove first match in A. if not found we error
342 for (i=0; i < suppOids2.Count(); ++i)
345 for (TInt j=0; j < startSuppOids.Count(); ++j)
347 if ((*suppOids2[i]) == (*startSuppOids[j]))
350 delete (startSuppOids[j]);
351 startSuppOids.Remove(j);
357 ERR_PRINTF2(_L("ERROR: Extra OID found in result: %S"), suppOids2[i]);
358 User::Leave(KErrGeneral);
362 //6. if A is not empty we error
363 if (startSuppOids.Count() != 0)
365 for (TInt j=0; j < startSuppOids.Count(); ++j)
367 ERR_PRINTF2(_L("ERROR: OID missing from result: %S"), startSuppOids[j]);
369 User::Leave(KErrGeneral);
372 CleanupStack::PopAndDestroy(2, iCertChain);