|
1 /* |
|
2 * Copyright (c) 2004 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 "CCMSOriginatorIdentifierOrKey.h" |
|
21 #include "CCMSIssuerAndSerialNumber.h" |
|
22 #include "CCMSOriginatorPublicKey.h" |
|
23 #include <asn1dec.h> |
|
24 #include <asn1enc.h> |
|
25 |
|
26 // ============================ MEMBER FUNCTIONS =============================== |
|
27 |
|
28 // ----------------------------------------------------------------------------- |
|
29 // CCMSOriginatorIdentifierOrKey::CCMSOriginatorIdentifierOrKey |
|
30 // C++ default constructor can NOT contain any code, that |
|
31 // might leave. |
|
32 // ----------------------------------------------------------------------------- |
|
33 // |
|
34 EXPORT_C CCMSOriginatorIdentifierOrKey::CCMSOriginatorIdentifierOrKey() |
|
35 { |
|
36 } |
|
37 |
|
38 // ----------------------------------------------------------------------------- |
|
39 // CCMSOriginatorIdentifierOrKey::ConstructL |
|
40 // Symbian 2nd phase constructor can leave. |
|
41 // ----------------------------------------------------------------------------- |
|
42 // |
|
43 EXPORT_C void CCMSOriginatorIdentifierOrKey::ConstructL( |
|
44 const CCMSIssuerAndSerialNumber& aIssuerAndSerialNumber ) |
|
45 { |
|
46 SetIssuerAndSerialNumberL( aIssuerAndSerialNumber ); |
|
47 } |
|
48 |
|
49 // ----------------------------------------------------------------------------- |
|
50 // CCMSOriginatorIdentifierOrKey::ConstructL |
|
51 // Symbian 2nd phase constructor can leave. |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 EXPORT_C void CCMSOriginatorIdentifierOrKey::ConstructL( |
|
55 const TDesC8& aSubjectKeyIdentifier ) |
|
56 { |
|
57 SetSubjectKeyIdentifierL( aSubjectKeyIdentifier ); |
|
58 } |
|
59 |
|
60 // ----------------------------------------------------------------------------- |
|
61 // CCMSOriginatorIdentifierOrKey::ConstructL |
|
62 // Symbian 2nd phase constructor can leave. |
|
63 // ----------------------------------------------------------------------------- |
|
64 // |
|
65 EXPORT_C void CCMSOriginatorIdentifierOrKey::ConstructL( |
|
66 const CCMSOriginatorPublicKey& aOriginatorKey ) |
|
67 { |
|
68 SetOriginatorKeyL( aOriginatorKey ); |
|
69 } |
|
70 |
|
71 // ----------------------------------------------------------------------------- |
|
72 // CCMSOriginatorIdentifierOrKey::NewL |
|
73 // Two-phased constructor. |
|
74 // ----------------------------------------------------------------------------- |
|
75 // |
|
76 EXPORT_C CCMSOriginatorIdentifierOrKey* CCMSOriginatorIdentifierOrKey::NewL() |
|
77 { |
|
78 // creating with empty/default values |
|
79 CCMSIssuerAndSerialNumber* issuer = CCMSIssuerAndSerialNumber::NewL( ); |
|
80 CleanupStack::PushL( issuer ); |
|
81 CCMSOriginatorIdentifierOrKey* self = NewL( *issuer ); |
|
82 CleanupStack::PopAndDestroy( issuer ); |
|
83 return self; |
|
84 } |
|
85 |
|
86 // ----------------------------------------------------------------------------- |
|
87 // CCMSOriginatorIdentifierOrKey::NewL |
|
88 // Two-phased constructor. |
|
89 // ----------------------------------------------------------------------------- |
|
90 // |
|
91 EXPORT_C CCMSOriginatorIdentifierOrKey* CCMSOriginatorIdentifierOrKey::NewL( |
|
92 const CCMSIssuerAndSerialNumber& aIssuerAndSerialNumber) |
|
93 { |
|
94 CCMSOriginatorIdentifierOrKey* self = |
|
95 new( ELeave ) CCMSOriginatorIdentifierOrKey(); |
|
96 |
|
97 CleanupStack::PushL( self ); |
|
98 self->ConstructL( aIssuerAndSerialNumber ); |
|
99 CleanupStack::Pop(); |
|
100 |
|
101 return self; |
|
102 } |
|
103 |
|
104 // ----------------------------------------------------------------------------- |
|
105 // CCMSOriginatorIdentifierOrKey::NewL |
|
106 // Two-phased constructor. |
|
107 // ----------------------------------------------------------------------------- |
|
108 // |
|
109 EXPORT_C CCMSOriginatorIdentifierOrKey* CCMSOriginatorIdentifierOrKey::NewL( |
|
110 const TDesC8& aSubjectKeyIdentifier ) |
|
111 { |
|
112 CCMSOriginatorIdentifierOrKey* self = |
|
113 new( ELeave ) CCMSOriginatorIdentifierOrKey(); |
|
114 |
|
115 CleanupStack::PushL( self ); |
|
116 self->ConstructL( aSubjectKeyIdentifier ); |
|
117 CleanupStack::Pop(); |
|
118 |
|
119 return self; |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CCMSOriginatorIdentifierOrKey::NewL |
|
124 // Two-phased constructor. |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 EXPORT_C CCMSOriginatorIdentifierOrKey* CCMSOriginatorIdentifierOrKey::NewL( |
|
128 const CCMSOriginatorPublicKey& aOriginatorKey ) |
|
129 { |
|
130 CCMSOriginatorIdentifierOrKey* self = |
|
131 new( ELeave ) CCMSOriginatorIdentifierOrKey(); |
|
132 |
|
133 CleanupStack::PushL( self ); |
|
134 self->ConstructL( aOriginatorKey ); |
|
135 CleanupStack::Pop(); |
|
136 |
|
137 return self; |
|
138 } |
|
139 |
|
140 // Destructor |
|
141 CCMSOriginatorIdentifierOrKey::~CCMSOriginatorIdentifierOrKey() |
|
142 { |
|
143 delete iIssuerAndSerialNumber; |
|
144 delete iSubjectKeyIdentifier; |
|
145 delete iOriginatorKey; |
|
146 } |
|
147 |
|
148 // ----------------------------------------------------------------------------- |
|
149 // CCMSOriginatorIdentifierOrKey::DecodeL |
|
150 // Decrypts raw data to this instance |
|
151 // ----------------------------------------------------------------------------- |
|
152 void CCMSOriginatorIdentifierOrKey::DecodeL( const TDesC8& aRawData ) |
|
153 { |
|
154 TASN1DecGeneric decGen( aRawData ); |
|
155 decGen.InitL(); |
|
156 switch( decGen.Tag() ) |
|
157 { |
|
158 case EASN1Sequence: |
|
159 { |
|
160 // check class and decode iasn |
|
161 if( decGen.Class() != EUniversal ) |
|
162 { |
|
163 User::Leave( KErrArgument ); |
|
164 } |
|
165 CCMSIssuerAndSerialNumber* issuerAndSerialNumber = |
|
166 CCMSIssuerAndSerialNumber::NewL(); |
|
167 CleanupStack::PushL( issuerAndSerialNumber ); |
|
168 issuerAndSerialNumber->DecodeL( aRawData ); |
|
169 DeleteOldValueAndChangeTypeL( EIssuerAndSerialNumber ); |
|
170 iIssuerAndSerialNumber = issuerAndSerialNumber; |
|
171 CleanupStack::Pop( issuerAndSerialNumber ); |
|
172 break; |
|
173 } |
|
174 case ESubjectKeyIdentifier: |
|
175 { |
|
176 // check class and decode ski |
|
177 if( decGen.Class() != EContextSpecific ) |
|
178 { |
|
179 User::Leave( KErrArgument ); |
|
180 } |
|
181 TASN1DecOctetString octetDecoder; |
|
182 TInt pos = 0; |
|
183 HBufC8* subjectKeyIdentifier = |
|
184 octetDecoder.DecodeDERL( aRawData, pos ); |
|
185 CleanupStack::PushL( subjectKeyIdentifier ); |
|
186 DeleteOldValueAndChangeTypeL( ESubjectKeyIdentifier ); |
|
187 iSubjectKeyIdentifier = subjectKeyIdentifier; |
|
188 CleanupStack::Pop( subjectKeyIdentifier ); |
|
189 break; |
|
190 } |
|
191 case EOriginatorKey: |
|
192 { |
|
193 // check class and decode originatorKey |
|
194 if( decGen.Class() != EContextSpecific ) |
|
195 { |
|
196 User::Leave( KErrArgument ); |
|
197 } |
|
198 CCMSOriginatorPublicKey* originatorKey = |
|
199 CCMSOriginatorPublicKey::NewL(); |
|
200 CleanupStack::PushL( originatorKey ); |
|
201 originatorKey->DecodeL( aRawData ); |
|
202 DeleteOldValueAndChangeTypeL( EOriginatorKey ); |
|
203 iOriginatorKey = originatorKey; |
|
204 CleanupStack::Pop( originatorKey ); |
|
205 break; |
|
206 } |
|
207 default: |
|
208 { |
|
209 User::Leave( KErrArgument ); |
|
210 } |
|
211 } |
|
212 } |
|
213 |
|
214 // ----------------------------------------------------------------------------- |
|
215 // CCMSOriginatorIdentifierOrKey::EncodeL |
|
216 // Encrypts this instance to descriptor |
|
217 // ----------------------------------------------------------------------------- |
|
218 |
|
219 void CCMSOriginatorIdentifierOrKey::EncodeL( HBufC8*& aResult ) const |
|
220 { |
|
221 CASN1EncBase* root = EncoderLC(); |
|
222 |
|
223 // encode the object in a DER encoding |
|
224 HBufC8* der = HBufC8::NewMaxLC( root->LengthDER() ); |
|
225 TPtr8 pder( der->Des() ); |
|
226 TUint pos = 0; |
|
227 root->WriteDERL( pder, pos ); |
|
228 CleanupStack::Pop( der ); |
|
229 aResult = der; |
|
230 |
|
231 CleanupStack::PopAndDestroy( root ); |
|
232 } |
|
233 |
|
234 // ----------------------------------------------------------------------------- |
|
235 // CCMSOriginatorIdentifierOrKey::EncoderLC |
|
236 // Returns ASN1 encoder for this instance |
|
237 // ----------------------------------------------------------------------------- |
|
238 |
|
239 CASN1EncBase* CCMSOriginatorIdentifierOrKey::EncoderLC() const |
|
240 { |
|
241 switch( iType ) |
|
242 { |
|
243 case EIssuerAndSerialNumber: |
|
244 { |
|
245 return iIssuerAndSerialNumber->EncoderLC(); |
|
246 } |
|
247 case ESubjectKeyIdentifier: |
|
248 { |
|
249 return EncoderSubjectKeyIdentifierLC(); |
|
250 } |
|
251 case EOriginatorKey: |
|
252 { |
|
253 return EncoderOriginatorKeyLC(); |
|
254 } |
|
255 default: |
|
256 { |
|
257 User::Leave( KErrCorrupt ); |
|
258 return NULL; |
|
259 } |
|
260 } |
|
261 } |
|
262 |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CCMSOriginatorIdentifierOrKey::Type |
|
265 // Type getter. |
|
266 // ----------------------------------------------------------------------------- |
|
267 EXPORT_C CCMSOriginatorIdentifierOrKey::TType |
|
268 CCMSOriginatorIdentifierOrKey::Type() const |
|
269 { |
|
270 return iType; |
|
271 } |
|
272 |
|
273 // ----------------------------------------------------------------------------- |
|
274 // CCMSOriginatorIdentifierOrKey::IssuerAndSerialNumberL |
|
275 // IssuerAndSerialNumber getter. |
|
276 // ----------------------------------------------------------------------------- |
|
277 EXPORT_C const CCMSIssuerAndSerialNumber& |
|
278 CCMSOriginatorIdentifierOrKey::IssuerAndSerialNumberL() const |
|
279 { |
|
280 if( !iIssuerAndSerialNumber ) |
|
281 { |
|
282 User::Leave( KErrNotFound ); |
|
283 } |
|
284 return *iIssuerAndSerialNumber; |
|
285 } |
|
286 |
|
287 // ----------------------------------------------------------------------------- |
|
288 // CCMSOriginatorIdentifierOrKey::SubjectKeyIdentifierL |
|
289 // SubjectKeyIdentifier getter. |
|
290 // ----------------------------------------------------------------------------- |
|
291 EXPORT_C const TDesC8& |
|
292 CCMSOriginatorIdentifierOrKey::SubjectKeyIdentifierL() const |
|
293 { |
|
294 if( !iSubjectKeyIdentifier ) |
|
295 { |
|
296 User::Leave( KErrNotFound ); |
|
297 } |
|
298 return *iSubjectKeyIdentifier; |
|
299 } |
|
300 |
|
301 // ----------------------------------------------------------------------------- |
|
302 // CCMSOriginatorIdentifierOrKey::SubjectKeyIdentifierL |
|
303 // SubjectKeyIdentifier getter. |
|
304 // ----------------------------------------------------------------------------- |
|
305 EXPORT_C const CCMSOriginatorPublicKey& |
|
306 CCMSOriginatorIdentifierOrKey::OriginatorKeyL() const |
|
307 { |
|
308 if( !iOriginatorKey ) |
|
309 { |
|
310 User::Leave( KErrNotFound ); |
|
311 } |
|
312 return *iOriginatorKey; |
|
313 } |
|
314 |
|
315 |
|
316 |
|
317 // ----------------------------------------------------------------------------- |
|
318 // CCMSOriginatorIdentifierOrKey::SetIssuerAndSerialNumberL |
|
319 // IssuerAndSerialNumber setter |
|
320 // ----------------------------------------------------------------------------- |
|
321 EXPORT_C void CCMSOriginatorIdentifierOrKey::SetIssuerAndSerialNumberL( |
|
322 const CCMSIssuerAndSerialNumber& aIssuerAndSerialNumber ) |
|
323 { |
|
324 CCMSIssuerAndSerialNumber* issuerAndSerialNumber = |
|
325 CCMSIssuerAndSerialNumber::NewL( |
|
326 aIssuerAndSerialNumber.IssuerName(), |
|
327 aIssuerAndSerialNumber.SerialNumber() ); |
|
328 CleanupStack::PushL( issuerAndSerialNumber ); |
|
329 DeleteOldValueAndChangeTypeL( EIssuerAndSerialNumber ); |
|
330 iIssuerAndSerialNumber = issuerAndSerialNumber; |
|
331 CleanupStack::Pop( issuerAndSerialNumber ); |
|
332 } |
|
333 |
|
334 // ----------------------------------------------------------------------------- |
|
335 // CCMSOriginatorIdentifierOrKey::SetSubjectKeyIdentifierL |
|
336 // SubjectKeyIdentifier setter |
|
337 // ----------------------------------------------------------------------------- |
|
338 EXPORT_C void CCMSOriginatorIdentifierOrKey::SetSubjectKeyIdentifierL( |
|
339 const TDesC8& aSubjectKeyIdentifier ) |
|
340 { |
|
341 HBufC8* subjectKeyIdentifier = aSubjectKeyIdentifier.AllocLC(); |
|
342 DeleteOldValueAndChangeTypeL( ESubjectKeyIdentifier ); |
|
343 iSubjectKeyIdentifier = subjectKeyIdentifier; |
|
344 CleanupStack::Pop( subjectKeyIdentifier ); |
|
345 } |
|
346 |
|
347 // ----------------------------------------------------------------------------- |
|
348 // CCMSOriginatorIdentifierOrKey::SetOriginatorKeyL |
|
349 // OriginatorKey setter |
|
350 // ----------------------------------------------------------------------------- |
|
351 EXPORT_C void CCMSOriginatorIdentifierOrKey::SetOriginatorKeyL( |
|
352 const CCMSOriginatorPublicKey& aOriginatorKey ) |
|
353 { |
|
354 CCMSOriginatorPublicKey* originatorKey = |
|
355 CCMSOriginatorPublicKey::NewLC( aOriginatorKey ); |
|
356 DeleteOldValueAndChangeTypeL( EOriginatorKey ); |
|
357 iOriginatorKey = originatorKey; |
|
358 CleanupStack::Pop( originatorKey ); |
|
359 } |
|
360 |
|
361 // ----------------------------------------------------------------------------- |
|
362 // CCMSOriginatorIdentifierOrKey::DeleteOldValueAndChangeType |
|
363 // Deletes old value and changes type |
|
364 // ----------------------------------------------------------------------------- |
|
365 void CCMSOriginatorIdentifierOrKey::DeleteOldValueAndChangeTypeL( |
|
366 CCMSOriginatorIdentifierOrKey::TType aNewType ) |
|
367 { |
|
368 switch( iType ) |
|
369 { |
|
370 case EIssuerAndSerialNumber: |
|
371 { |
|
372 delete iIssuerAndSerialNumber; |
|
373 iIssuerAndSerialNumber = NULL; |
|
374 break; |
|
375 } |
|
376 case ESubjectKeyIdentifier: |
|
377 { |
|
378 delete iSubjectKeyIdentifier; |
|
379 iSubjectKeyIdentifier = NULL; |
|
380 break; |
|
381 } |
|
382 case EOriginatorKey: |
|
383 { |
|
384 delete iOriginatorKey; |
|
385 iOriginatorKey = NULL; |
|
386 break; |
|
387 } |
|
388 default: |
|
389 { |
|
390 User::Leave( KErrCorrupt ); |
|
391 } |
|
392 } |
|
393 iType = aNewType; |
|
394 } |
|
395 |
|
396 // ----------------------------------------------------------------------------- |
|
397 // CCMSOriginatorIdentifierOrKey::EncoderSubjectKeyIdentifierLC |
|
398 // returns encoder for the subjectKeyIdentifier |
|
399 // ----------------------------------------------------------------------------- |
|
400 CASN1EncBase* |
|
401 CCMSOriginatorIdentifierOrKey::EncoderSubjectKeyIdentifierLC() const |
|
402 { |
|
403 CASN1EncOctetString* subjectKeyIdentifier = |
|
404 CASN1EncOctetString::NewLC( *iSubjectKeyIdentifier ); |
|
405 subjectKeyIdentifier->SetTag( ESubjectKeyIdentifier ); |
|
406 |
|
407 return subjectKeyIdentifier; |
|
408 } |
|
409 |
|
410 // ----------------------------------------------------------------------------- |
|
411 // CCMSOriginatorIdentifierOrKey::EncoderOriginatorKeyL |
|
412 // Returns encoder for the OriginatorKey value |
|
413 // ----------------------------------------------------------------------------- |
|
414 CASN1EncBase* CCMSOriginatorIdentifierOrKey::EncoderOriginatorKeyLC() const |
|
415 { |
|
416 CASN1EncBase* originatorKey = iOriginatorKey->EncoderLC(); |
|
417 originatorKey->SetTag( EOriginatorKey ); |
|
418 |
|
419 return originatorKey; |
|
420 } |
|
421 |
|
422 // End of File |