|
1 /* |
|
2 * Copyright (c) 2008 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 "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 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <asn1dec.h> |
|
21 |
|
22 #include "cstsace.h" |
|
23 |
|
24 namespace java |
|
25 { |
|
26 namespace satsa |
|
27 { |
|
28 |
|
29 // CONSTANTS |
|
30 const TTagType KSTSPrincipalsTag = 0; |
|
31 const TTagType KSTSPermissionsTag = 1; |
|
32 const TTagType KSTSUserAuthenticationsTag = 2; |
|
33 const TTagType KSTSApduMaskPermissionTag = 0; |
|
34 |
|
35 const TInt KSTSDefaultGranularity = 5; |
|
36 |
|
37 // ============================ MEMBER FUNCTIONS =============================== |
|
38 |
|
39 // ----------------------------------------------------------------------------- |
|
40 // CSTSAce::CSTSAce |
|
41 // C++ default constructor can NOT contain any code, that |
|
42 // might leave. |
|
43 // ----------------------------------------------------------------------------- |
|
44 // |
|
45 CSTSAce::CSTSAce() |
|
46 { |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CSTSAce::ConstructL |
|
51 // Symbian 2nd phase constructor can leave. |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 void CSTSAce::ConstructL() |
|
55 { |
|
56 // creating with empty values |
|
57 iPrincipals |
|
58 = new(ELeave) CArrayPtrFlat<CSTSPrincipal> (KSTSDefaultGranularity); |
|
59 |
|
60 iApduMaskPermissions |
|
61 = new(ELeave) CArrayPtrFlat<CSTSAPDUMaskPermission> (KSTSDefaultGranularity); |
|
62 |
|
63 iUserAuthentications |
|
64 = new(ELeave) CArrayPtrFlat<CSTSUserAuth> (KSTSDefaultGranularity); |
|
65 } |
|
66 |
|
67 // ----------------------------------------------------------------------------- |
|
68 // CSTSAce::NewL |
|
69 // Two-phased constructor. |
|
70 // ----------------------------------------------------------------------------- |
|
71 // |
|
72 CSTSAce* CSTSAce::NewLC() |
|
73 { |
|
74 CSTSAce* self = new(ELeave) CSTSAce(); |
|
75 CleanupStack::PushL(self); |
|
76 self->ConstructL(); |
|
77 return self; |
|
78 } |
|
79 |
|
80 // Destructor |
|
81 CSTSAce::~CSTSAce() |
|
82 { |
|
83 if (iPrincipals) |
|
84 { |
|
85 iPrincipals->ResetAndDestroy(); |
|
86 delete iPrincipals; |
|
87 } |
|
88 if (iApduMaskPermissions) |
|
89 { |
|
90 iApduMaskPermissions->ResetAndDestroy(); |
|
91 delete iApduMaskPermissions; |
|
92 } |
|
93 if (iUserAuthentications) |
|
94 { |
|
95 iUserAuthentications->ResetAndDestroy(); |
|
96 delete iUserAuthentications; |
|
97 } |
|
98 } |
|
99 |
|
100 // ----------------------------------------------------------------------------- |
|
101 // CSTSAce::DecodeL |
|
102 // Decrypts raw data to this instance |
|
103 // (other items were commented in a header). |
|
104 // ----------------------------------------------------------------------------- |
|
105 void CSTSAce::DecodeL(const TDesC8& aRawData) |
|
106 { |
|
107 CArrayPtr<TASN1DecGeneric>* itemsData = DecodeSequenceLC(ETrue, aRawData); //must be sequence |
|
108 TInt pos = 0; |
|
109 //decode possible sequence of principal (in loop) |
|
110 if ((pos < itemsData->Count()) && (itemsData->At(pos)->Tag() |
|
111 == KSTSPrincipalsTag)) |
|
112 { |
|
113 //no need to check sequence tag |
|
114 CArrayPtr<TASN1DecGeneric>* principals = DecodeSequenceLC(EFalse, |
|
115 itemsData->At(pos++)->Encoding()); |
|
116 |
|
117 TInt numOfPrincipals = principals->Count(); |
|
118 |
|
119 if (numOfPrincipals) |
|
120 { |
|
121 CArrayPtr<CSTSPrincipal>* princArray = new(ELeave) CArrayPtrFlat< |
|
122 CSTSPrincipal> (numOfPrincipals); |
|
123 CleanupStack::PushL(princArray); |
|
124 //if leave occures, array's ResetAndDestroy method will be called |
|
125 CleanupResetAndDestroyPushL(*princArray); |
|
126 |
|
127 for (TInt i = 0; i < numOfPrincipals; i++) |
|
128 { |
|
129 CSTSPrincipal* principal = CSTSPrincipal::NewLC(); |
|
130 principal->DecodeL(principals->At(i)->Encoding()); |
|
131 princArray->AppendL(principal); |
|
132 CleanupStack::Pop(principal); |
|
133 } |
|
134 |
|
135 if (iPrincipals) |
|
136 { |
|
137 iPrincipals->ResetAndDestroy(); |
|
138 } |
|
139 delete iPrincipals; |
|
140 iPrincipals = princArray; |
|
141 |
|
142 CleanupStack::Pop(princArray);//ResetAndDestroy |
|
143 CleanupStack::Pop(princArray); |
|
144 } |
|
145 CleanupStack::PopAndDestroy(principals); |
|
146 } |
|
147 |
|
148 //decode possible sequence of permission (in loop) |
|
149 if ((pos < itemsData->Count()) && (itemsData->At(pos)->Tag() |
|
150 == KSTSPermissionsTag)) |
|
151 { |
|
152 //no need to check sequence tag |
|
153 CArrayPtr<TASN1DecGeneric>* permissions = DecodeSequenceLC(EFalse, |
|
154 itemsData->At(pos++)->Encoding()); |
|
155 |
|
156 TInt numOfPermissions = permissions->Count(); |
|
157 if (numOfPermissions) |
|
158 { |
|
159 CArrayPtr<CSTSAPDUMaskPermission> |
|
160 * permissionArray = new(ELeave) CArrayPtrFlat< |
|
161 CSTSAPDUMaskPermission> (numOfPermissions); |
|
162 CleanupStack::PushL(permissionArray); |
|
163 //if leave occures, array's ResetAndDestroy method will be called |
|
164 CleanupResetAndDestroyPushL(*permissionArray); |
|
165 |
|
166 for (TInt i = 0; i < numOfPermissions; i++) |
|
167 { |
|
168 //we need only APDUMAskPermissions |
|
169 if (permissions->At(i)->Tag() == KSTSApduMaskPermissionTag) |
|
170 { |
|
171 CSTSAPDUMaskPermission* permission = |
|
172 CSTSAPDUMaskPermission::NewLC(); |
|
173 permission->DecodeL(permissions->At(i)->Encoding()); |
|
174 permissionArray->AppendL(permission); |
|
175 CleanupStack::Pop(permission); |
|
176 } |
|
177 } |
|
178 |
|
179 if (iApduMaskPermissions) |
|
180 { |
|
181 iApduMaskPermissions->ResetAndDestroy(); |
|
182 } |
|
183 delete iApduMaskPermissions; |
|
184 iApduMaskPermissions = permissionArray; |
|
185 |
|
186 CleanupStack::Pop(permissionArray); //ResetAndDestroy |
|
187 CleanupStack::Pop(permissionArray); |
|
188 } |
|
189 CleanupStack::PopAndDestroy(permissions); |
|
190 } |
|
191 |
|
192 //decode possible sequence of UserAuthentication (in loop) |
|
193 if ((pos < itemsData->Count()) && (itemsData->At(pos)->Tag() |
|
194 == KSTSUserAuthenticationsTag)) |
|
195 { |
|
196 //no need to check sequence tag |
|
197 CArrayPtr<TASN1DecGeneric>* userAuthentications = DecodeSequenceLC( |
|
198 EFalse, itemsData->At(pos++)->Encoding()); |
|
199 |
|
200 TInt numOfUserAuthentications = userAuthentications->Count(); |
|
201 if (numOfUserAuthentications) |
|
202 { |
|
203 |
|
204 CArrayPtr<CSTSUserAuth> |
|
205 * userAuthArray = |
|
206 new(ELeave) CArrayPtrFlat<CSTSUserAuth> (numOfUserAuthentications); |
|
207 CleanupStack::PushL(userAuthArray); |
|
208 //if leave occures, array's ResetAndDestroy method will be called |
|
209 CleanupResetAndDestroyPushL(*userAuthArray); |
|
210 |
|
211 for (TInt i = 0; i < numOfUserAuthentications; i++) |
|
212 { |
|
213 CSTSUserAuth* userAuthentication = CSTSUserAuth::NewLC(); |
|
214 userAuthentication->DecodeL( |
|
215 userAuthentications->At(i)->Encoding()); |
|
216 //we need only EAPDUPinEntry |
|
217 if (userAuthentication->Type() == CSTSUserAuth::EAPDUPinEntry) |
|
218 { |
|
219 userAuthArray->AppendL(userAuthentication); |
|
220 } |
|
221 CleanupStack::Pop(userAuthentication); |
|
222 } |
|
223 |
|
224 if (iUserAuthentications) |
|
225 { |
|
226 iUserAuthentications->ResetAndDestroy(); |
|
227 } |
|
228 delete iUserAuthentications; |
|
229 iUserAuthentications = userAuthArray; |
|
230 CleanupStack::Pop(userAuthArray);//ResetAndDestroy |
|
231 CleanupStack::Pop(userAuthArray); |
|
232 } |
|
233 CleanupStack::PopAndDestroy(userAuthentications); |
|
234 } |
|
235 CleanupStack::PopAndDestroy(itemsData); |
|
236 } |
|
237 |
|
238 // ----------------------------------------------------------------------------- |
|
239 // CSTSAce::Principals |
|
240 // Getter for principals |
|
241 // (other items were commented in a header). |
|
242 // ----------------------------------------------------------------------------- |
|
243 const CArrayPtr<CSTSPrincipal>& CSTSAce::Principals() const |
|
244 { |
|
245 return *iPrincipals; |
|
246 } |
|
247 |
|
248 // ----------------------------------------------------------------------------- |
|
249 // CSTSAce::APDUMaskPermissions |
|
250 // Getter for APDUMaskPermissions |
|
251 // (other items were commented in a header). |
|
252 // ----------------------------------------------------------------------------- |
|
253 const CArrayPtr<CSTSAPDUMaskPermission>& CSTSAce::APDUMaskPermissions() const |
|
254 { |
|
255 return *iApduMaskPermissions; |
|
256 } |
|
257 |
|
258 // ----------------------------------------------------------------------------- |
|
259 // CSTSAce::UserAuthentications |
|
260 // Getter for UserAuthentications |
|
261 // (other items were commented in a header). |
|
262 // ----------------------------------------------------------------------------- |
|
263 const CArrayPtr<CSTSUserAuth>& CSTSAce::UserAuthentications() const |
|
264 { |
|
265 return *iUserAuthentications; |
|
266 } |
|
267 |
|
268 } // namespace satsa |
|
269 } // namespace java |
|
270 // End of File |