|
1 /* |
|
2 * Copyright (c) 2002 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 "CCMSOriginatorInfo.h" |
|
21 #include "TCMSTimeUtil.h" |
|
22 #include "CCMSCertificateChoices.h" |
|
23 #include "CCMSX509CertificateList.h" |
|
24 #include <asn1dec.h> |
|
25 #include <asn1enc.h> |
|
26 |
|
27 // CONSTANTS |
|
28 const TInt KMinNumberOfSubModules = 0; |
|
29 const TInt KMaxNumberOfSubModules = 2; |
|
30 const TTagType KCertsTag = 0; |
|
31 const TTagType KCrlsTag = 1; |
|
32 |
|
33 // ============================ MEMBER FUNCTIONS =============================== |
|
34 |
|
35 // ----------------------------------------------------------------------------- |
|
36 // CCMSOriginatorInfo::CCMSOriginatorInfo |
|
37 // C++ constructor can NOT contain any code, that |
|
38 // might leave. |
|
39 // ----------------------------------------------------------------------------- |
|
40 // |
|
41 EXPORT_C CCMSOriginatorInfo::CCMSOriginatorInfo( ) |
|
42 { |
|
43 } |
|
44 |
|
45 // ----------------------------------------------------------------------------- |
|
46 // CCMSOriginatorInfo::NewL |
|
47 // Two-phased constructor. |
|
48 // ----------------------------------------------------------------------------- |
|
49 // |
|
50 EXPORT_C CCMSOriginatorInfo* |
|
51 CCMSOriginatorInfo::NewL() |
|
52 { |
|
53 // creating with empty values |
|
54 CCMSOriginatorInfo* self = |
|
55 new( ELeave ) CCMSOriginatorInfo(); |
|
56 return self; |
|
57 } |
|
58 |
|
59 // Destructor |
|
60 CCMSOriginatorInfo::~CCMSOriginatorInfo() |
|
61 { |
|
62 if( iCerts ) |
|
63 { |
|
64 iCerts->ResetAndDestroy(); |
|
65 delete iCerts; |
|
66 } |
|
67 if( iCrls ) |
|
68 { |
|
69 iCrls->ResetAndDestroy(); |
|
70 delete iCrls; |
|
71 } |
|
72 } |
|
73 |
|
74 // ----------------------------------------------------------------------------- |
|
75 // CCMSOriginatorInfo::DecodeL |
|
76 // Decrypts raw data to this instance |
|
77 // ----------------------------------------------------------------------------- |
|
78 void CCMSOriginatorInfo::DecodeL( const TDesC8& aRawData ) |
|
79 { |
|
80 CArrayPtr< TASN1DecGeneric >* itemList = DecodeSequenceLC( |
|
81 aRawData, KMinNumberOfSubModules, KMaxNumberOfSubModules ); |
|
82 |
|
83 DecodeArrayL( itemList ); |
|
84 |
|
85 CleanupStack::PopAndDestroy( itemList ); |
|
86 } |
|
87 |
|
88 // ----------------------------------------------------------------------------- |
|
89 // CCMSOriginatorInfo::EncoderLC |
|
90 // Returns ASN1 encoder for this instance |
|
91 // ----------------------------------------------------------------------------- |
|
92 |
|
93 CASN1EncBase* CCMSOriginatorInfo::EncoderLC() const |
|
94 { |
|
95 CASN1EncSequence* root = CASN1EncSequence::NewLC(); |
|
96 |
|
97 if( iCerts ) |
|
98 { |
|
99 // encode certs [0] IMPLICIT CertificateSet OPTIONAL |
|
100 CASN1EncSequence* certs = CASN1EncSequence::NewLC(); |
|
101 TInt certCount = iCerts->Count(); |
|
102 for( TInt i = 0; i < certCount; i++ ) |
|
103 { |
|
104 CASN1EncBase* certEncoder = iCerts->At( i )->EncoderLC(); |
|
105 certs->AddAndPopChildL( certEncoder ); |
|
106 } |
|
107 certs->SetTag( KCertsTag ); |
|
108 root->AddAndPopChildL( certs ); |
|
109 } |
|
110 |
|
111 if( iCrls ) |
|
112 { |
|
113 // encode crls [1] IMPLICIT CertificateRevocationLists OPTIONAL |
|
114 CASN1EncSequence* crls = CASN1EncSequence::NewLC(); |
|
115 TInt crlCount = iCrls->Count(); |
|
116 for( TInt i = 0; i < crlCount; i++ ) |
|
117 { |
|
118 CASN1EncBase* crlEncoder = iCrls->At( i )->EncoderLC(); |
|
119 crls->AddAndPopChildL( crlEncoder ); |
|
120 } |
|
121 crls->SetTag( KCrlsTag ); |
|
122 root->AddAndPopChildL( crls ); |
|
123 } |
|
124 |
|
125 return root; |
|
126 } |
|
127 |
|
128 // ----------------------------------------------------------------------------- |
|
129 // CCMSOriginatorInfo::Certs() |
|
130 // Getter for certs |
|
131 // ----------------------------------------------------------------------------- |
|
132 EXPORT_C const CArrayPtr< CCMSCertificateChoices >* |
|
133 CCMSOriginatorInfo::Certs() const |
|
134 { |
|
135 return iCerts; |
|
136 } |
|
137 |
|
138 // ----------------------------------------------------------------------------- |
|
139 // CCMSOriginatorInfo::Crls() |
|
140 // Getter for crls |
|
141 // ----------------------------------------------------------------------------- |
|
142 EXPORT_C const CArrayPtr< CCMSX509CertificateList >* |
|
143 CCMSOriginatorInfo::Crls() const |
|
144 { |
|
145 return iCrls; |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CCMSOriginatorInfo::SetCertsL() |
|
150 // Setter for certs |
|
151 // ----------------------------------------------------------------------------- |
|
152 EXPORT_C void CCMSOriginatorInfo::SetCerts( |
|
153 CArrayPtr< CCMSCertificateChoices >* aCerts ) |
|
154 { |
|
155 delete iCerts; |
|
156 iCerts = aCerts; |
|
157 } |
|
158 |
|
159 // ----------------------------------------------------------------------------- |
|
160 // CCMSOriginatorInfo::SetCrlsL() |
|
161 // Setter for Crls |
|
162 // ----------------------------------------------------------------------------- |
|
163 EXPORT_C void CCMSOriginatorInfo::SetCrls( |
|
164 CArrayPtr< CCMSX509CertificateList >* aCrls ) |
|
165 { |
|
166 delete iCrls; |
|
167 iCrls = aCrls; |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CCMSOriginatorInfo::DecodeImplicitTagL |
|
172 // Decrypts raw data with implicit tag |
|
173 // ----------------------------------------------------------------------------- |
|
174 void CCMSOriginatorInfo::DecodeImplicitTagL( |
|
175 const TDesC8& aRawData, |
|
176 const TTagType aImplicitTag ) |
|
177 { |
|
178 // Check the tag |
|
179 TASN1DecGeneric decGen( aRawData ); |
|
180 decGen.InitL(); |
|
181 // Accept only given tag |
|
182 if( decGen.Tag() != aImplicitTag ) |
|
183 { |
|
184 User::Leave( KErrArgument ); |
|
185 } |
|
186 TASN1DecSequence decSeq; |
|
187 CArrayPtr< TASN1DecGeneric >* items = decSeq.DecodeDERLC( decGen ); |
|
188 TInt itemCount = items->Count(); |
|
189 if( ( itemCount > KMaxNumberOfSubModules ) || |
|
190 ( itemCount < KMinNumberOfSubModules ) ) |
|
191 { |
|
192 User::Leave( KErrArgument ); |
|
193 } |
|
194 DecodeArrayL( items ); |
|
195 CleanupStack::PopAndDestroy( items ); |
|
196 } |
|
197 |
|
198 // ----------------------------------------------------------------------------- |
|
199 // CCMSOriginatorInfo::DecodeArrayL |
|
200 // Decodes data from an array of decoders |
|
201 // ----------------------------------------------------------------------------- |
|
202 void CCMSOriginatorInfo::DecodeArrayL( |
|
203 CArrayPtr< TASN1DecGeneric >* aItems ) |
|
204 { |
|
205 TInt itemCount = aItems->Count(); |
|
206 |
|
207 TInt sequenceCounter = 0; |
|
208 |
|
209 TASN1DecSequence decSeq; |
|
210 |
|
211 CArrayPtr< CCMSCertificateChoices >* certs = NULL; |
|
212 TInt certCount = 0; |
|
213 if( sequenceCounter < itemCount ) |
|
214 { |
|
215 TASN1DecGeneric* certsGenericDecoder = aItems->At( sequenceCounter ); |
|
216 if( certsGenericDecoder->Tag() == KCertsTag ) |
|
217 { |
|
218 CArrayPtr< TASN1DecGeneric >* certList = |
|
219 decSeq.DecodeDERLC( *certsGenericDecoder ); |
|
220 |
|
221 certCount = certList->Count(); |
|
222 |
|
223 certs = new( ELeave ) CArrayPtrFlat< CCMSCertificateChoices >( |
|
224 certCount ); |
|
225 |
|
226 CleanupStack::PushL( certs ); |
|
227 |
|
228 for( TInt i = 0; i < certCount; i++ ) |
|
229 { |
|
230 CCMSCertificateChoices* choices = CCMSCertificateChoices::NewL(); |
|
231 CleanupStack::PushL( choices ); |
|
232 choices->DecodeL( certList->At( i )->Encoding() ); |
|
233 certs->AppendL( choices ); |
|
234 } |
|
235 |
|
236 sequenceCounter++; |
|
237 } |
|
238 } |
|
239 |
|
240 CArrayPtr< CCMSX509CertificateList >* crls = NULL; |
|
241 TInt crlCount = 0; |
|
242 if( sequenceCounter < itemCount ) |
|
243 { |
|
244 TASN1DecGeneric* crlsGenericDecoder = aItems->At( sequenceCounter ); |
|
245 if( crlsGenericDecoder->Tag() != KCrlsTag ) |
|
246 { |
|
247 User::Leave( KErrArgument ); |
|
248 } |
|
249 CArrayPtr< TASN1DecGeneric >* crlList = |
|
250 decSeq.DecodeDERLC( *crlsGenericDecoder ); |
|
251 |
|
252 crlCount = crlList->Count(); |
|
253 |
|
254 crls = new( ELeave ) CArrayPtrFlat< CCMSX509CertificateList >( |
|
255 crlCount ); |
|
256 |
|
257 CleanupStack::PushL( crls ); |
|
258 |
|
259 for( TInt i = 0; i < crlCount; i++ ) |
|
260 { |
|
261 CCMSX509CertificateList* cList = CCMSX509CertificateList::NewLC(); |
|
262 cList->DecodeL( crlList->At( i )->Encoding() ); |
|
263 crls->AppendL( cList ); |
|
264 } |
|
265 } |
|
266 |
|
267 if( iCerts ) |
|
268 { |
|
269 iCerts->ResetAndDestroy(); |
|
270 delete iCerts; |
|
271 } |
|
272 iCerts = certs; |
|
273 if( iCrls ) |
|
274 { |
|
275 iCrls->ResetAndDestroy(); |
|
276 delete iCrls; |
|
277 } |
|
278 iCrls = crls; |
|
279 |
|
280 if( crls ) |
|
281 { |
|
282 CleanupStack::Pop( crlCount ); |
|
283 CleanupStack::Pop( crls ); |
|
284 CleanupStack::PopAndDestroy( ); // crlList |
|
285 } |
|
286 if( certs ) |
|
287 { |
|
288 CleanupStack::Pop( certCount ); |
|
289 CleanupStack::Pop( certs ); |
|
290 CleanupStack::PopAndDestroy( ); // certList |
|
291 } |
|
292 |
|
293 } |
|
294 |
|
295 |
|
296 // End of File |